From 479bf4cfbacbc3eef38f8a806d9cdd79c74bb65e Mon Sep 17 00:00:00 2001 From: Matt Isenhower Date: Fri, 12 Jan 2018 16:26:43 -0800 Subject: [PATCH] Fix an issue where some gear displayed the wrong name The "Annaki Blue Cuff" and "Moist Ghillie Helmet" both share the same ID (7010), but they are of different kinds. I didn't realize gear of different kinds could share the same ID, so the localization code didn't take this into account. This change also makes the localization code work with multi-part IDs. --- src/js/components/splatoon/MerchandiseBox.vue | 2 +- src/updater/LocalizationProcessor.js | 31 +++++++++++++------ src/updater/update.js | 4 ++- src/updater/updaters/MerchandisesUpdater.js | 2 +- src/updater/updaters/TimelineUpdater.js | 2 +- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/js/components/splatoon/MerchandiseBox.vue b/src/js/components/splatoon/MerchandiseBox.vue index 4f731d6..454158c 100644 --- a/src/js/components/splatoon/MerchandiseBox.vue +++ b/src/js/components/splatoon/MerchandiseBox.vue @@ -96,7 +96,7 @@ export default { }, gearName() { let gear = this.merchandise.gear; - return this.$t(`splatnet.gear.${gear.id}.name`, gear.name); + return this.$t(`splatnet.gear.${gear.kind}.${gear.id}.name`, gear.name); }, }, } diff --git a/src/updater/LocalizationProcessor.js b/src/updater/LocalizationProcessor.js index ba6f652..77d92fd 100644 --- a/src/updater/LocalizationProcessor.js +++ b/src/updater/LocalizationProcessor.js @@ -37,16 +37,27 @@ class LocalizationProcessor { writeJson(this.getFilename(), this.data); } - getExpression(id, valueKey) { - return [this.ruleset.name, id, valueKey]; + getExpression(ids, valueKey) { + return [this.ruleset.name, ...ids, valueKey]; } - readValue(id, valueKey) { - return _.get(this.data, this.getExpression(id, valueKey)); + readValue(ids, valueKey) { + return _.get(this.data, this.getExpression(ids, valueKey)); } - writeValue(id, valueKey, newValue) { - return _.setWith(this.data, this.getExpression(id, valueKey), newValue, Object); + writeValue(ids, valueKey, newValue) { + return _.setWith(this.data, this.getExpression(ids, valueKey), newValue, Object); + } + + getIdValues(entity) { + let idParts = this.ruleset.id; + + // Support multi-part IDs + if (!Array.isArray(idParts)) + idParts = [idParts]; + + // Get the ID part values + return idParts.map(id => _.get(entity, id)); } eachEntity(data, callback) { @@ -67,10 +78,10 @@ class LocalizationProcessor { updateLocalizationsForEntity(entity) { for (let valueKey of this.valueExpressions) { - let id = _.get(entity, this.ruleset.id); + let ids = this.getIdValues(entity); let value = _.get(entity, valueKey); - this.writeValue(id, valueKey, value); + this.writeValue(ids, valueKey, value); } this.writeData(); @@ -83,9 +94,9 @@ class LocalizationProcessor { hasLocalizationsForEntity(entity) { for (let valueKey of this.valueExpressions) { - let id = _.get(entity, this.ruleset.id); + let ids = this.getIdValues(entity); - if (this.readValue(id, valueKey) === undefined) + if (this.readValue(ids, valueKey) === undefined) return false; } diff --git a/src/updater/update.js b/src/updater/update.js index 940233b..fbd5c4e 100644 --- a/src/updater/update.js +++ b/src/updater/update.js @@ -23,7 +23,9 @@ async function updateAll() { for (let updater of updaters) { try { await updater.update(); - } catch (e) { } + } catch (e) { + console.error(e); + } } return 'Done'; diff --git a/src/updater/updaters/MerchandisesUpdater.js b/src/updater/updaters/MerchandisesUpdater.js index bf61bde..6ff5e9b 100644 --- a/src/updater/updaters/MerchandisesUpdater.js +++ b/src/updater/updaters/MerchandisesUpdater.js @@ -19,7 +19,7 @@ class MerchandisesUpdater extends Updater { { name: 'gear', entities: '$..gear', - id: 'id', + id: ['kind', 'id'], values: 'name', }, { diff --git a/src/updater/updaters/TimelineUpdater.js b/src/updater/updaters/TimelineUpdater.js index 3cba335..51a2a06 100644 --- a/src/updater/updaters/TimelineUpdater.js +++ b/src/updater/updaters/TimelineUpdater.js @@ -18,7 +18,7 @@ class TimelineUpdater extends Updater { { name: 'gear', entities: '$.coop..gear', - id: 'id', + id: ['kind', 'id'], values: 'name', }, {