Changes to use acs out of theme
This commit is contained in:
parent
c966f46bc6
commit
8fd25af7a1
|
@ -4,6 +4,8 @@
|
|||
author: Luciano Ayres
|
||||
group: blocktronics
|
||||
enabled: true
|
||||
// this theme requires at least 80 columns
|
||||
acs: TW80
|
||||
|
||||
//
|
||||
// Also check out Luciano's ANSIGARDEN:
|
||||
|
|
|
@ -33,7 +33,7 @@ module.exports = class LoginServerModule extends ServerModule {
|
|||
const preLoginTheme = _.get(Config(), 'theme.preLogin');
|
||||
const selectedTheme = theme.findMatching(client, preLoginTheme);
|
||||
|
||||
if ('*' === selectedTheme) {
|
||||
if (_.isNil(selectedTheme) || '*' === selectedTheme) {
|
||||
client.user.properties[UserProps.ThemeId] = theme.getRandomTheme() || '';
|
||||
} else {
|
||||
client.user.properties[UserProps.ThemeId] = selectedTheme;
|
||||
|
|
|
@ -120,7 +120,7 @@ exports.getModule = class NewUserAppModule extends MenuModule {
|
|||
const defaultTheme = _.get(config, 'theme.default');
|
||||
const selectedTheme = theme.findMatching(self.client, defaultTheme);
|
||||
|
||||
if ('*' === selectedTheme) {
|
||||
if (_.isNil(selectedTheme) || '*' === selectedTheme) {
|
||||
newUser.properties[UserProps.ThemeId] = theme.getRandomTheme();
|
||||
} else {
|
||||
newUser.properties[UserProps.ThemeId] = selectedTheme;
|
||||
|
|
|
@ -27,6 +27,7 @@ exports.getThemeArt = getThemeArt;
|
|||
exports.getAvailableThemes = getAvailableThemes;
|
||||
exports.getRandomTheme = getRandomTheme;
|
||||
exports.setClientTheme = setClientTheme;
|
||||
exports.themeAcsMatches = themeAcsMatches;
|
||||
exports.findMatching = findMatching;
|
||||
exports.selectDefaultTheme = selectDefaultTheme;
|
||||
exports.displayPreparedArt = displayPreparedArt;
|
||||
|
@ -50,9 +51,9 @@ exports.ThemeManager = class ThemeManager {
|
|||
themeManagerInstance
|
||||
.getAvailableThemes()
|
||||
.forEach((themeConfig, themeId) => {
|
||||
const { name, author, group } = themeConfig.get().info;
|
||||
const { name, author, group, acs } = themeConfig.get().info;
|
||||
Log.info(
|
||||
{ themeId, themeName: name, author, group },
|
||||
{ themeId, themeName: name, author: author, group: group, acs: acs },
|
||||
'Theme loaded'
|
||||
);
|
||||
});
|
||||
|
@ -420,7 +421,7 @@ function getRandomTheme() {
|
|||
}
|
||||
function selectDefaultTheme(client) {
|
||||
const selectedTheme = theme.findMatching(client, Config().theme.default);
|
||||
if ('*' === selectedTheme) {
|
||||
if (_.isNil(selectedTheme) || '*' === selectedTheme) {
|
||||
return theme.getRandomTheme() || '';
|
||||
} else {
|
||||
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) {
|
||||
if (!(_.isArray(themeSection))) {
|
||||
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');
|
||||
const matchingTheme = client.acs.getConditionalValue(themeSection, 'name');
|
||||
if (_.isNil(matchingTheme)) {
|
||||
Log.warn('No matching theme in configuration found.');
|
||||
// Default to random if nothing found
|
||||
return '*';
|
||||
}
|
||||
else {
|
||||
Log.debug({ theme: matchingTheme }, 'Found matching theme');
|
||||
return matchingTheme;
|
||||
}
|
||||
let matchingTheme = themeSection.find((themeName) => {
|
||||
return themeAcsMatches(client, themeName);
|
||||
});
|
||||
|
||||
return matchingTheme;
|
||||
}
|
||||
|
||||
function setClientTheme(client, themeId) {
|
||||
|
@ -456,10 +469,18 @@ function setClientTheme(client, themeId) {
|
|||
const defaultTheme = selectDefaultTheme(client);
|
||||
if (availThemes.has(themeId)) {
|
||||
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)) {
|
||||
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 {
|
||||
msg =
|
||||
'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) {
|
||||
if (artInfo || config.theme.default === options.themeId) {
|
||||
if (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);
|
||||
options.basePath = paths.join(config.paths.themes, defaultTheme);
|
||||
art.getArt(options.name, options, (err, artInfo) => {
|
||||
|
|
Loading…
Reference in New Issue