Changes to use acs out of theme
This commit is contained in:
parent
c966f46bc6
commit
8fd25af7a1
|
@ -4,6 +4,8 @@
|
||||||
author: Luciano Ayres
|
author: Luciano Ayres
|
||||||
group: blocktronics
|
group: blocktronics
|
||||||
enabled: true
|
enabled: true
|
||||||
|
// this theme requires at least 80 columns
|
||||||
|
acs: TW80
|
||||||
|
|
||||||
//
|
//
|
||||||
// Also check out Luciano's ANSIGARDEN:
|
// Also check out Luciano's ANSIGARDEN:
|
||||||
|
|
|
@ -33,7 +33,7 @@ module.exports = class LoginServerModule extends ServerModule {
|
||||||
const preLoginTheme = _.get(Config(), 'theme.preLogin');
|
const preLoginTheme = _.get(Config(), 'theme.preLogin');
|
||||||
const selectedTheme = theme.findMatching(client, preLoginTheme);
|
const selectedTheme = theme.findMatching(client, preLoginTheme);
|
||||||
|
|
||||||
if ('*' === selectedTheme) {
|
if (_.isNil(selectedTheme) || '*' === selectedTheme) {
|
||||||
client.user.properties[UserProps.ThemeId] = theme.getRandomTheme() || '';
|
client.user.properties[UserProps.ThemeId] = theme.getRandomTheme() || '';
|
||||||
} else {
|
} else {
|
||||||
client.user.properties[UserProps.ThemeId] = selectedTheme;
|
client.user.properties[UserProps.ThemeId] = selectedTheme;
|
||||||
|
|
|
@ -120,7 +120,7 @@ exports.getModule = class NewUserAppModule extends MenuModule {
|
||||||
const defaultTheme = _.get(config, 'theme.default');
|
const defaultTheme = _.get(config, 'theme.default');
|
||||||
const selectedTheme = theme.findMatching(self.client, defaultTheme);
|
const selectedTheme = theme.findMatching(self.client, defaultTheme);
|
||||||
|
|
||||||
if ('*' === selectedTheme) {
|
if (_.isNil(selectedTheme) || '*' === selectedTheme) {
|
||||||
newUser.properties[UserProps.ThemeId] = theme.getRandomTheme();
|
newUser.properties[UserProps.ThemeId] = theme.getRandomTheme();
|
||||||
} else {
|
} else {
|
||||||
newUser.properties[UserProps.ThemeId] = selectedTheme;
|
newUser.properties[UserProps.ThemeId] = selectedTheme;
|
||||||
|
|
|
@ -27,6 +27,7 @@ exports.getThemeArt = getThemeArt;
|
||||||
exports.getAvailableThemes = getAvailableThemes;
|
exports.getAvailableThemes = getAvailableThemes;
|
||||||
exports.getRandomTheme = getRandomTheme;
|
exports.getRandomTheme = getRandomTheme;
|
||||||
exports.setClientTheme = setClientTheme;
|
exports.setClientTheme = setClientTheme;
|
||||||
|
exports.themeAcsMatches = themeAcsMatches;
|
||||||
exports.findMatching = findMatching;
|
exports.findMatching = findMatching;
|
||||||
exports.selectDefaultTheme = selectDefaultTheme;
|
exports.selectDefaultTheme = selectDefaultTheme;
|
||||||
exports.displayPreparedArt = displayPreparedArt;
|
exports.displayPreparedArt = displayPreparedArt;
|
||||||
|
@ -50,9 +51,9 @@ exports.ThemeManager = class ThemeManager {
|
||||||
themeManagerInstance
|
themeManagerInstance
|
||||||
.getAvailableThemes()
|
.getAvailableThemes()
|
||||||
.forEach((themeConfig, themeId) => {
|
.forEach((themeConfig, themeId) => {
|
||||||
const { name, author, group } = themeConfig.get().info;
|
const { name, author, group, acs } = themeConfig.get().info;
|
||||||
Log.info(
|
Log.info(
|
||||||
{ themeId, themeName: name, author, group },
|
{ themeId, themeName: name, author: author, group: group, acs: acs },
|
||||||
'Theme loaded'
|
'Theme loaded'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -420,7 +421,7 @@ function getRandomTheme() {
|
||||||
}
|
}
|
||||||
function selectDefaultTheme(client) {
|
function selectDefaultTheme(client) {
|
||||||
const selectedTheme = theme.findMatching(client, Config().theme.default);
|
const selectedTheme = theme.findMatching(client, Config().theme.default);
|
||||||
if ('*' === selectedTheme) {
|
if (_.isNil(selectedTheme) || '*' === selectedTheme) {
|
||||||
return theme.getRandomTheme() || '';
|
return theme.getRandomTheme() || '';
|
||||||
} else {
|
} else {
|
||||||
return selectedTheme;
|
return selectedTheme;
|
||||||
|
@ -428,6 +429,23 @@ function selectDefaultTheme(client) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function themeAcsMatches(client, themeName) {
|
||||||
|
const themeConfig = getAvailableThemes().get(themeName);
|
||||||
|
if (!_.isNil(themeConfig)) {
|
||||||
|
if (_.has(themeConfig, 'info.acs')) {
|
||||||
|
return client.acs.matches(themeConfig.info.acs);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return true; // No ACS means anything can use it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function findMatching(client, themeSection) {
|
function findMatching(client, themeSection) {
|
||||||
if (!(_.isArray(themeSection))) {
|
if (!(_.isArray(themeSection))) {
|
||||||
Log.debug({ theme: themeSection }, 'Setting the theme from a simple string');
|
Log.debug({ theme: themeSection }, 'Setting the theme from a simple string');
|
||||||
|
@ -435,16 +453,11 @@ function findMatching(client, themeSection) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.debug('Finding a matching theme from ACS settings');
|
Log.debug('Finding a matching theme from ACS settings');
|
||||||
const matchingTheme = client.acs.getConditionalValue(themeSection, 'name');
|
let matchingTheme = themeSection.find((themeName) => {
|
||||||
if (_.isNil(matchingTheme)) {
|
return themeAcsMatches(client, themeName);
|
||||||
Log.warn('No matching theme in configuration found.');
|
});
|
||||||
// Default to random if nothing found
|
|
||||||
return '*';
|
return matchingTheme;
|
||||||
}
|
|
||||||
else {
|
|
||||||
Log.debug({ theme: matchingTheme }, 'Found matching theme');
|
|
||||||
return matchingTheme;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setClientTheme(client, themeId) {
|
function setClientTheme(client, themeId) {
|
||||||
|
@ -456,10 +469,18 @@ function setClientTheme(client, themeId) {
|
||||||
const defaultTheme = selectDefaultTheme(client);
|
const defaultTheme = selectDefaultTheme(client);
|
||||||
if (availThemes.has(themeId)) {
|
if (availThemes.has(themeId)) {
|
||||||
msg = 'Set client theme';
|
msg = 'Set client theme';
|
||||||
setThemeId = themeId;
|
setThemeId = themeAcsMatches(client, themeId);
|
||||||
|
if (_.isNil(setThemeId)) {
|
||||||
|
Log.warn('No theme matching acs found, setting to first theme.');
|
||||||
|
setThemeId = availThemes.keys().next().value;
|
||||||
|
}
|
||||||
} else if (availThemes.has(defaultTheme)) {
|
} else if (availThemes.has(defaultTheme)) {
|
||||||
msg = 'Failed setting theme by supplied ID; Using default';
|
msg = 'Failed setting theme by supplied ID; Using default';
|
||||||
setThemeId = config.theme.default;
|
setThemeId = findMatching(client, config.theme.default);
|
||||||
|
if (_.isNil(setThemeId)) {
|
||||||
|
Log.warn('No theme matching acs found, setting to first theme.');
|
||||||
|
setThemeId = availThemes.keys().next().value;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
msg =
|
msg =
|
||||||
'Failed setting theme by system default ID; Using the first one we can find';
|
'Failed setting theme by system default ID; Using the first one we can find';
|
||||||
|
@ -545,9 +566,21 @@ function getThemeArt(options, cb) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function fromDefaultTheme(artInfo, callback) {
|
function fromDefaultTheme(artInfo, callback) {
|
||||||
if (artInfo || config.theme.default === options.themeId) {
|
if (artInfo) {
|
||||||
return callback(null, artInfo);
|
return callback(null, artInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_.isArray(config.theme.default)) {
|
||||||
|
if (config.theme.default === options.themeId) {
|
||||||
|
return callback(null, artInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (config.theme.default.includes(options.themeId)) {
|
||||||
|
return callback(null, artInfo);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
const defaultTheme = selectDefaultTheme(options.client);
|
const defaultTheme = selectDefaultTheme(options.client);
|
||||||
options.basePath = paths.join(config.paths.themes, defaultTheme);
|
options.basePath = paths.join(config.paths.themes, defaultTheme);
|
||||||
art.getArt(options.name, options, (err, artInfo) => {
|
art.getArt(options.name, options, (err, artInfo) => {
|
||||||
|
|
Loading…
Reference in New Issue