From 1e17acc4cf404239bfe560cbe66c95076efa0345 Mon Sep 17 00:00:00 2001 From: MomokoKoigakubo Date: Thu, 24 Sep 2026 11:51:41 -0400 Subject: [PATCH] changed all user face commands to translatable, return reasons etc --- ti_bp/scripts/config/regions.js | 12 +++++--- ti_bp/scripts/core/commands.js | 38 +++++++++++++++++++------- ti_bp/scripts/core/time.js | 0 ti_bp/scripts/save/state.js | 2 +- ti_bp/scripts/systems/progression.js | 21 ++++++++++---- ti_bp/texts/{en_us.lang => en_US.lang} | 0 ti_rp/texts/en_US.lang | 15 ++++++++++ ti_rp/texts/en_us.lang | 7 ----- 8 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 ti_bp/scripts/core/time.js rename ti_bp/texts/{en_us.lang => en_US.lang} (100%) create mode 100644 ti_rp/texts/en_US.lang delete mode 100644 ti_rp/texts/en_us.lang diff --git a/ti_bp/scripts/config/regions.js b/ti_bp/scripts/config/regions.js index 560ff2a..8f91626 100644 --- a/ti_bp/scripts/config/regions.js +++ b/ti_bp/scripts/config/regions.js @@ -10,8 +10,12 @@ * @type {Record} */ export const REGIONS = { - lagoon: {nameKey: "tama.region.lagoon.name", order: 0, unlockedAtStart: true, unlockedCost: 0}, - farmland: {nameKey: "tama.region.farmland.name", order: 1, unlockedAtStart: false, unlockedCost: 100}, - seaside: {nameKey: "tama.region.seaside.name", order: 2, unlockedAtStart: false, unlockedCost: 500}, - skyland: {nameKey: "tama.region.skyland.name", order: 3, unlockedAtStart: false, unlockedCost: 1000} + lagoon: {nameKey: "tama.region.lagoon.name", + order: 0, unlockedAtStart: true, unlockedCost: 0}, + cropcountry: {nameKey: "tama.region.cropcountry.name", + order: 1, unlockedAtStart: false, unlockedCost: 100}, + seaside: {nameKey: "tama.region.seaside.name", + order: 2, unlockedAtStart: false, unlockedCost: 500}, + skyland: {nameKey: "tama.region.skyland.name", + order: 3, unlockedAtStart: false, unlockedCost: 1000} }; diff --git a/ti_bp/scripts/core/commands.js b/ti_bp/scripts/core/commands.js index 9b5fdc0..0ddf942 100644 --- a/ti_bp/scripts/core/commands.js +++ b/ti_bp/scripts/core/commands.js @@ -161,38 +161,56 @@ system.beforeEvents.startup.subscribe(({ customCommandRegistry }) => { if (!origin.sourceEntity) { return; } if (result.ok) { - origin.sourceEntity.sendMessage(`${region} unlocked`); + origin.sourceEntity.sendMessage({ + translate: "tama.unlock.success", + with: { rawtext: [{ translate: REGIONS[region].nameKey }] } + }); return; } - // reason codes are not display text - this is developer-facing - // for now. Player copy belongs in the lang file later. + // reason codes are turned into player-facing text here. + // Every branch produces a RawMessage - a plain string would be + // sent literally instead of being looked up in the lang file. let why; switch (result.reason) { case "already_unlocked": - why = `${region} is already unlocked`; + why = { + translate: "tama.unlock.already_unlocked", + with: { rawtext: [{ translate: REGIONS[region].nameKey }] } + }; break; case "missing_prior_region": why = result.requires - ? `You must unlock ${result.requires} first` - : `${region} has nothing before it in the chain`; + ? { + translate: "tama.unlock.missing_prior", + with: { rawtext: [{ translate: REGIONS[result.requires].nameKey }] } + } + : { translate: "tama.unlock.first_region" }; break; case "insufficient_funds": - why = `You need ${result.cost} coins, you have ${result.balance}`; + why = { + translate: "tama.unlock.insufficient_funds", + with: [String(result.cost), String(result.balance)] + }; break; case "unknown_region": - why = `Unknown region: ${region}`; + why = { translate: "tama.unlock.unknown_region" }; break; default: - why = `Cannot unlock ${region}`; + why = { + translate: "tama.unlock.default", + with: { rawtext: [{ translate: REGIONS[region].nameKey }] } + }; } origin.sourceEntity.sendMessage(why); }); + // note: CustomCommandResult.message is typed `string`, so it cannot + // carry a RawMessage and can never be translated. All player-facing + // text for this command goes through sendMessage above instead. return { status: CustomCommandStatus.Success, - message: `Unlock requested for ${region}`, }; }), diff --git a/ti_bp/scripts/core/time.js b/ti_bp/scripts/core/time.js new file mode 100644 index 0000000..e69de29 diff --git a/ti_bp/scripts/save/state.js b/ti_bp/scripts/save/state.js index ea299db..1c1bcac 100644 --- a/ti_bp/scripts/save/state.js +++ b/ti_bp/scripts/save/state.js @@ -128,7 +128,7 @@ export function returnBalance(){ } export function printGateState(){ -console.log(JSON.stringify(getState().gates)); +log(JSON.stringify(getState().gates)); } /** diff --git a/ti_bp/scripts/systems/progression.js b/ti_bp/scripts/systems/progression.js index a586034..d925e23 100644 --- a/ti_bp/scripts/systems/progression.js +++ b/ti_bp/scripts/systems/progression.js @@ -42,22 +42,31 @@ export function canUnlock(regionID) { WE ARE KEYING FOR THE KEY VALUE'S ORDER PRIOR TO PASSED REGION{RegionID} the prior value has to be true for the passed region to unlock */ - let answer = null; + let priorRegion = null; for (const id in REGIONS) { // never pass lagoon otherwise all conditions fail if (REGIONS[id].order === order - 1) { - answer = id; + /* + again tdlr we get the key prior to the past key + so for example command canUnlock("seaside"); + we are retrieving farm land for comparison + it's sequential you can't unlock zones non + out of order + */ + priorRegion = id; } } // if first region is auto unlocked we will never meet this condition - if (answer === null) { + if (priorRegion === null) { return { ok: false, reason: "missing_prior_region", requires: null }; } - //the region before this one must be open first - if (gates[answer] !== true) { - return { ok: false, reason: "missing_prior_region", requires: answer }; + /* + the prior region before this one must be open first + */ + if (gates[priorRegion] !== true) { + return { ok: false, reason: "missing_prior_region", requires: priorRegion }; } //they have to be able to pay for it. diff --git a/ti_bp/texts/en_us.lang b/ti_bp/texts/en_US.lang similarity index 100% rename from ti_bp/texts/en_us.lang rename to ti_bp/texts/en_US.lang diff --git a/ti_rp/texts/en_US.lang b/ti_rp/texts/en_US.lang new file mode 100644 index 0000000..66cff27 --- /dev/null +++ b/ti_rp/texts/en_US.lang @@ -0,0 +1,15 @@ +pack.name=The Tamagotchi Resource Pack +pack.description=A Resource pack for the Tamagotchi Map + +tama.region.lagoon.name=Lagoon Town +tama.region.cropcountry.name=Crop Country +tama.region.seaside.name=Seaside +tama.region.skyland.name=Skyland + +tama.unlock.already_unlocked=%1 is already unlocked +tama.unlock.missing_prior=You must unlock %1 first +tama.unlock.insufficient_funds=You need %1 coins, you have %2 +tama.unlock.first_region=First region is already unlocked +tama.unlock.unknown_region=Requested region not found +tama.unlock.default=Cannot unlock Region: %1 +tama.unlock.success=%1 unlocked \ No newline at end of file diff --git a/ti_rp/texts/en_us.lang b/ti_rp/texts/en_us.lang deleted file mode 100644 index 1340d8a..0000000 --- a/ti_rp/texts/en_us.lang +++ /dev/null @@ -1,7 +0,0 @@ -pack.name=The Tamagotchi Resource Pack -pack.description=A Resource pack for the Tamagotchi Map - -tama.region.lagoon.name=Lagoon Town -tama.region.farmland.name=Farmland -tama.region.seaside.name=Seaside -tama.region.skyland.name=Skyland \ No newline at end of file