Better theming for achievements

This commit is contained in:
Bryan Ashby 2019-01-05 22:51:16 -07:00
parent 6496fd931a
commit 2b802cb534
5 changed files with 47 additions and 23 deletions

View File

@ -983,7 +983,10 @@
achievements: {
defaults: {
titleSGR: "|11"
format: "|08 > |10{title} |08(|11{points} |03points|08)\r\n\r\n {message}"
globalFformat: "|08 > |10{title} |08(|11{points} |03points|08)\r\n\r\n {message}"
titleSGR: "|10"
pointsSGR: "|12"
textSGR: "|00|03"
globalTextSGR: "|03"
boardName: "|10"

View File

@ -64,25 +64,25 @@
points: 5
}
10: {
title: "{boardName} Curious"
title: "Curious Caller"
globalText: "{userName} has logged into {boardName} {achievedValue} times!"
text: "You've logged into {boardName} {achievedValue} times!"
points: 5
}
25: {
title: "{boardName} Inquisitive"
title: "Inquisitive Caller"
globalText: "{userName} has logged into {boardName} {achievedValue} times!"
text: "You've logged into {boardName} {achievedValue} times!"
points: 10
}
100: {
title: "{boardName} Regular"
title: "Regular Customer"
globalText: "{userName} has logged into {boardName} {achievedValue} times!"
text: "You've logged into {boardName} {achievedValue} times!"
points: 10
}
500: {
title: "{boardName} Addict"
title: "System Addict"
globalText: "{userName} the BBS {boardName} addict has logged in {achievedValue} times!"
text: "You're a {boardName} addict! You've logged in {achievedValue} times!"
points: 25

View File

@ -314,29 +314,37 @@ class Achievements {
}
}
getFormattedTextFor(info, textType) {
getFormatObject(info) {
return {
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,
achievedValue : info.achievedValue,
matchField : info.matchField,
matchValue : info.matchValue,
timestamp : moment(info.timestamp).format(info.dateTimeFormat),
boardName : Config().general.boardName,
};
}
getFormattedTextFor(info, textType, defaultSgr = '|07') {
const themeDefaults = _.get(info.client.currentTheme, 'achievements.defaults', {});
const defSgr = themeDefaults[`${textType}SGR`] || '|07';
const defSgr = themeDefaults[`${textType}SGR`] || defaultSgr;
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),
};
let formatObj = this.getFormatObject(info);
formatObj = _.reduce(formatObj, (out, v, k) => {
out[k] = wrap(k, v);
return out;
}, {});
return stringFormat(`${defSgr}${info.details[textType]}`, formatObj);
}
@ -400,8 +408,21 @@ class Achievements {
pause : true,
};
if(headerArt || footerArt) {
const themeDefaults = _.get(info.client.currentTheme, 'achievements.defaults', {});
const defaultContentsFormat = '{title}\r\n${message}';
const contentsFormat = 'global' === itemType ?
themeDefaults.globalFormat || defaultContentsFormat :
themeDefaults.format || defaultContentsFormat;
const formatObj = Object.assign(this.getFormatObject(info), {
title : this.getFormattedTextFor(info, 'title', ''), // ''=defaultSgr
message : itemText,
});
const contents = pipeToAnsi(stringFormat(contentsFormat, formatObj));
interruptItems[itemType].contents =
`${headerArt || ''}\r\n${pipeToAnsi(title)}\r\n${pipeToAnsi(itemText)}\r\n${footerArt || ''}`;
`${headerArt || ''}\r\n${contents}\r\n${footerArt || ''}`;
}
return callback(null);
}