diff --git a/src/app.js b/src/app.js index ccf5b8d..51276aa 100644 --- a/src/app.js +++ b/src/app.js @@ -120,9 +120,14 @@ class App{ $ui.popup(UI.popups.ACHIEVEMENT, {achievement}); }) $$on('message', ([message, ...args]) => { - $ui.popup(UI.popups.MESSAGE, {message: $_.format( - $lang[message], ...args - ) }); + if(Array.isArray(message)) { + message = message.map(([m, ...a]) => $_.format($lang[m], ...a)) .join('\n'); + } else { + message = $_.format( + $lang[message], ...args + ); + } + $ui.popup(UI.popups.MESSAGE, {message}); }) } diff --git a/src/functions/util.js b/src/functions/util.js index 888ca9f..c502d26 100644 --- a/src/functions/util.js +++ b/src/functions/util.js @@ -83,10 +83,17 @@ function deepMapSet(target, source) { return target; } +function deepGet(obj, path) { + for(const key of path.split('.')) { + if(!(key in obj)) return undefined; + obj = obj[key]; + } + return obj; +} function format(str, ...args) { const replace = set => (match, key) => { - const value = set[key]; + const value = deepGet(set, key); switch(typeof value) { case 'object': return JSON.stringify(value); case 'boolean': diff --git a/src/i18n/zh-cn.js b/src/i18n/zh-cn.js index 526dcb4..de6f31b 100644 --- a/src/i18n/zh-cn.js +++ b/src/i18n/zh-cn.js @@ -143,5 +143,6 @@ export default ({ F_TalentConflict: '与已选的「{0}」天赋冲突', F_TalentSelectLimit: '只能选 {0} 个天赋', F_TalentSelectNotComplect: '要选满{0}个天赋', - F_PropertyPointLeft: '你还有 {0} 属性点没有分配完' + F_PropertyPointLeft: '你还有 {0} 属性点没有分配完', + F_TalentReplace: '天赋替换【{source.name}】->【{target.name}】', }); \ No newline at end of file diff --git a/src/modules/life.js b/src/modules/life.js index 02b2dbf..4865b59 100644 --- a/src/modules/life.js +++ b/src/modules/life.js @@ -22,6 +22,7 @@ class Life { #propertyAllocateLimit; #defaultPropertys; #specialThanks; + #initialData; async initial(i18nLoad, commonLoad) { const [age, talents, events, achievements, specialThanks] = await Promise.all([ @@ -58,25 +59,28 @@ class Life { this.#property.config(propertyConfig); } - restart(allocation) { - const propertys = clone(this.#defaultPropertys); - for(const key in allocation) { - propertys[key] = clone(allocation[key]); - } + remake(talents) { + this.#initialData = clone(this.#defaultPropertys); + this.#initialData.TLT = clone(talents); this.#triggerTalents = {}; - const contents = this.talentReplace(propertys.TLT); - this.#property.restart(propertys); + return this.talentReplace(this.#initialData.TLT); + } + + start(allocation) { + for(const key in allocation) { + this.#initialData[key] = clone(allocation[key]); + } + this.#property.restart(this.#initialData); this.doTalent() this.#property.restartLastStep(); this.#achievement.achieve( this.AchievementOpportunity.START, this.#property - ) - return contents; + ); } - getPropertyPoints(selectedTalentIds) { - return this.#defaultPropertyPoints + this.#talent.allocationAddition(selectedTalentIds); + getPropertyPoints() { + return this.#defaultPropertyPoints + this.#talent.allocationAddition(this.#initialData.TLT); } getTalentCurrentTriggerCount(talentId) { diff --git a/src/ui/themes/cyber/property.js b/src/ui/themes/cyber/property.js index dc6f783..8430e51 100644 --- a/src/ui/themes/cyber/property.js +++ b/src/ui/themes/cyber/property.js @@ -41,9 +41,11 @@ export default class CyberProperty extends ui.view.CyberTheme.CyberPropertyUI { init({talents}) { this.listSelectedTalents.array = talents; - const talentIds = talents.map(talent => talent.id); - // core.talentReplace(talentIds); - this.#propertyPoints = core.getPropertyPoints(talentIds); + const replace = core.remake(talents.map(talent => talent.id)); + if(replace.length > 0) { + $$event('message', [replace.map(v => ['F_TalentReplace', v])]); + } + this.#propertyPoints = core.getPropertyPoints(); this.#propertyAllocateLimit = core.propertyAllocateLimit; this.labLeftPropertyPoint.text = this.#propertyPoints; this.#propertyAllocate = { @@ -51,7 +53,6 @@ export default class CyberProperty extends ui.view.CyberTheme.CyberPropertyUI { [this.#types.INT]: 0, [this.#types.STR]: 0, [this.#types.MNY]: 0, - [this.#types.TLT]: talentIds, } this.updateAllocate(); } diff --git a/src/ui/themes/cyber/trajectory.js b/src/ui/themes/cyber/trajectory.js index d6780b9..3bb022e 100644 --- a/src/ui/themes/cyber/trajectory.js +++ b/src/ui/themes/cyber/trajectory.js @@ -74,7 +74,7 @@ export default class CyberTrajectory extends ui.view.CyberTheme.CyberTrajectoryU this.#trajectoryItems = []; this.#isEnd = false; this.#talents = talents; - core.restart(propertyAllocate); + core.start(propertyAllocate); this.updateProperty(); this.onNext(); } diff --git a/src/ui/themes/default/property.js b/src/ui/themes/default/property.js index 41fe4ac..e3aef99 100644 --- a/src/ui/themes/default/property.js +++ b/src/ui/themes/default/property.js @@ -41,9 +41,11 @@ export default class Property extends ui.view.DefaultTheme.PropertyUI { init({talents}) { this.listSelectedTalents.array = talents; - const talentIds = talents.map(talent => talent.id); - // core.talentReplace(talentIds); - this.#propertyPoints = core.getPropertyPoints(talentIds); + const replace = core.remake(talents.map(talent => talent.id)); + if(replace.length > 0) { + $$event('message', [replace.map(v => ['F_TalentReplace', v])]); + } + this.#propertyPoints = core.getPropertyPoints(); this.#propertyAllocateLimit = core.propertyAllocateLimit; this.labLeftPropertyPoint.text = this.#propertyPoints; this.#propertyAllocate = { @@ -51,7 +53,6 @@ export default class Property extends ui.view.DefaultTheme.PropertyUI { [this.#types.INT]: 0, [this.#types.STR]: 0, [this.#types.MNY]: 0, - [this.#types.TLT]: talentIds, } this.updateAllocate(); } diff --git a/src/ui/themes/default/trajectory.js b/src/ui/themes/default/trajectory.js index 9b7cc87..13694eb 100644 --- a/src/ui/themes/default/trajectory.js +++ b/src/ui/themes/default/trajectory.js @@ -53,7 +53,7 @@ export default class Trajectory extends ui.view.DefaultTheme.TrajectoryUI { this.#trajectoryItems = []; this.#isEnd = false; this.#talents = talents; - core.restart(propertyAllocate); + core.start(propertyAllocate); this.updateProperty(); this.onNext(); } diff --git a/src/ui/themes/message.js b/src/ui/themes/message.js index dd42d0b..2f2be4f 100644 --- a/src/ui/themes/message.js +++ b/src/ui/themes/message.js @@ -8,10 +8,12 @@ export default class MessagePopup extends ui.view.MessagePopupUI { } async popup({message}, parent) { + this.message.text = message; + this.message.commitMeasure(); + this.height = this.message.height + this.boxBg.radius * 2 + this.message.fontSize; Laya.Tween.clearAll(this); this.alpha = 0; this.y = - 2 * this.height; - this.message.text = message; await Laya.promises.Tween.to(this, { y: 0, alpha: 1 }, 300, Laya.Ease.backOut), await Laya.promises.Tween.to(this, { alpha: 0}, 300, Laya.Ease.strongIn, 3000); }