Start of theming of achievements

+ default text/SGR styles can now be set for quick customization of colors
This commit is contained in:
Bryan Ashby 2019-01-05 16:55:37 -07:00
parent 3cc905ea84
commit f56a72e0c3
3 changed files with 61 additions and 28 deletions

View File

@ -980,5 +980,28 @@
} }
} }
} }
achievements: {
defaults: {
titleSGR: "|11"
textSGR: "|00|03"
globalTextSGR: "|03"
boardName: "|10"
userName: "|11"
achievedValue: "|15"
}
overrides: {
user_login_count: {
match: {
2: {
//
// You may override title, text, and globalText here
//
}
}
}
}
}
} }
} }

View File

@ -115,18 +115,18 @@ class Achievements {
init(cb) { init(cb) {
let achievementConfigPath = _.get(Config(), 'general.achievementFile'); let achievementConfigPath = _.get(Config(), 'general.achievementFile');
if(!achievementConfigPath) { if(!achievementConfigPath) {
// :TODO: Log me Log.info('Achievements are not configured');
return cb(null); return cb(null);
} }
achievementConfigPath = getConfigPath(achievementConfigPath); // qualify achievementConfigPath = getConfigPath(achievementConfigPath); // qualify
// :TODO: Log enabled
const configLoaded = (achievementConfig) => { const configLoaded = (achievementConfig) => {
if(true !== achievementConfig.enabled) { if(true !== achievementConfig.enabled) {
Log.info('Achievements are not enabled');
this.stopMonitoringUserStatUpdateEvents(); this.stopMonitoringUserStatUpdateEvents();
delete this.achievementConfig; delete this.achievementConfig;
} else { } else {
Log.info('Achievements are enabled');
this.achievementConfig = achievementConfig; this.achievementConfig = achievementConfig;
this.monitorUserStatUpdateEvents(); this.monitorUserStatUpdateEvents();
} }
@ -318,35 +318,45 @@ class Achievements {
} }
} }
getFormattedTextFor(info, textType) {
const themeDefaults = _.get(info.client.currentTheme, 'achievements.defaults', {});
const defSgr = themeDefaults[`${textType}SGR`] || '|07';
const wrap = (fieldName, value) => {
return `${themeDefaults[fieldName] || defSgr}${value}${defSgr}`;
};
const formatObj = {
userName : wrap('userName', info.user.username),
userRealName : wrap('userRealName', info.user.properties[UserProps.RealName]),
userLocation : wrap('userLocation', info.user.properties[UserProps.Location]),
userAffils : wrap('userAffils', info.user.properties[UserProps.Affiliations]),
nodeId : wrap('nodeId', info.client.node),
title : wrap('title', info.details.title),
text : wrap('text', info.global ? info.details.globalText : info.details.text),
points : wrap('points', info.details.points),
achievedValue : wrap('achievedValue', info.achievedValue),
matchField : wrap('matchField', info.matchField),
matchValue : wrap('matchValue', info.matchValue),
timestamp : wrap('timestamp', moment(info.timestamp).format(info.dateTimeFormat)),
boardName : wrap('boardName', Config().general.boardName),
};
return stringFormat(`${defSgr}${info.details[textType]}`, formatObj);
}
createAchievementInterruptItems(info, cb) { createAchievementInterruptItems(info, cb) {
const dateTimeFormat = info.dateTimeFormat =
info.details.dateTimeFormat || info.details.dateTimeFormat ||
info.achievement.dateTimeFormat || info.achievement.dateTimeFormat ||
info.client.currentTheme.helpers.getDateTimeFormat(); info.client.currentTheme.helpers.getDateTimeFormat();
const config = Config(); const title = this.getFormattedTextFor(info, 'title');
const text = this.getFormattedTextFor(info, 'text');
const formatObj = {
userName : info.user.username,
userRealName : info.user.properties[UserProps.RealName],
userLocation : info.user.properties[UserProps.Location],
userAffils : info.user.properties[UserProps.Affiliations],
nodeId : info.client.node,
title : info.details.title,
text : info.global ? info.details.globalText : info.details.text,
points : info.details.points,
matchField : info.matchField,
matchValue : info.matchValue,
timestamp : moment(info.timestamp).format(dateTimeFormat),
boardName : config.general.boardName,
};
const title = stringFormat(info.details.title, formatObj);
const text = stringFormat(info.details.text, formatObj);
let globalText; let globalText;
if(info.details.globalText) { if(info.details.globalText) {
globalText = stringFormat(info.details.globalText, formatObj); globalText = this.getFormattedTextFor(info, 'globalText');
} }
const getArt = (name, callback) => { const getArt = (name, callback) => {
@ -416,4 +426,3 @@ exports.moduleInitialize = (initInfo, cb) => {
achievements = new Achievements(initInfo.events); achievements = new Achievements(initInfo.events);
return achievements.init(cb); return achievements.init(cb);
}; };

View File

@ -96,7 +96,7 @@ function loadTheme(themeId, cb) {
} }
if(false === _.get(theme, 'info.enabled')) { if(false === _.get(theme, 'info.enabled')) {
return cb(Errors.General('Theme is not enalbed', ErrorReasons.ErrNotEnabled)); return cb(Errors.General('Theme is not enabled', ErrorReasons.ErrNotEnabled));
} }
refreshThemeHelpers(theme); refreshThemeHelpers(theme);
@ -131,8 +131,9 @@ function getMergedTheme(menuConfig, promptConfig, theme) {
// //
// Add in data we won't be altering directly from the theme // Add in data we won't be altering directly from the theme
// //
mergedTheme.info = theme.info; mergedTheme.info = theme.info;
mergedTheme.helpers = theme.helpers; mergedTheme.helpers = theme.helpers;
mergedTheme.achievements = _.get(theme, 'customization.achievements');
// //
// merge customizer to disallow immutable MCI properties // merge customizer to disallow immutable MCI properties