From 2b802cb53439c2448b096cf105a2440fc4a9efce Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sat, 5 Jan 2019 22:51:16 -0700 Subject: [PATCH] Better theming for achievements --- .../achievement_global_header.ans | Bin 247 -> 240 bytes .../achievement_local_header.ans | Bin 247 -> 240 bytes art/themes/luciano_blocktronics/theme.hjson | 5 +- config/achievements.hjson | 8 +-- core/achievement.js | 57 ++++++++++++------ 5 files changed, 47 insertions(+), 23 deletions(-) diff --git a/art/themes/luciano_blocktronics/achievement_global_header.ans b/art/themes/luciano_blocktronics/achievement_global_header.ans index 87592fa3fcc8fda4bdcde2b176a922a0355a26b4..6104c2caccd3734f4fe8705453da53311734ffab 100644 GIT binary patch delta 19 bcmey)_!UQz`BM@9zu delta 44 zcmeys_?>Zrxa{rQ_Z1ZG+`pqB9c^H3Y?S*C$S|}vHp_K%_VApjJD0I?;%QX?pYIVa diff --git a/art/themes/luciano_blocktronics/achievement_local_header.ans b/art/themes/luciano_blocktronics/achievement_local_header.ans index 87592fa3fcc8fda4bdcde2b176a922a0355a26b4..6104c2caccd3734f4fe8705453da53311734ffab 100644 GIT binary patch delta 19 bcmey)_!UQz`BM@9zu delta 44 zcmeys_?>Zrxa{rQ_Z1ZG+`pqB9c^H3Y?S*C$S|}vHp_K%_VApjJD0I?;%QX?pYIVa diff --git a/art/themes/luciano_blocktronics/theme.hjson b/art/themes/luciano_blocktronics/theme.hjson index d38137c8..28f17ff9 100644 --- a/art/themes/luciano_blocktronics/theme.hjson +++ b/art/themes/luciano_blocktronics/theme.hjson @@ -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" diff --git a/config/achievements.hjson b/config/achievements.hjson index ce841e93..41bfd4c1 100644 --- a/config/achievements.hjson +++ b/config/achievements.hjson @@ -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 diff --git a/core/achievement.js b/core/achievement.js index e5eecd87..adfae332 100644 --- a/core/achievement.js +++ b/core/achievement.js @@ -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); }