changed all user face commands to translatable, return reasons etc

This commit is contained in:
MomokoKoigakubo
2026-09-24 11:51:41 -04:00
parent 8fbd3bd527
commit 1e17acc4cf
8 changed files with 67 additions and 28 deletions
+8 -4
View File
@@ -10,8 +10,12 @@
* @type {Record<string, Region>} * @type {Record<string, Region>}
*/ */
export const REGIONS = { export const REGIONS = {
lagoon: {nameKey: "tama.region.lagoon.name", order: 0, unlockedAtStart: true, unlockedCost: 0}, lagoon: {nameKey: "tama.region.lagoon.name",
farmland: {nameKey: "tama.region.farmland.name", order: 1, unlockedAtStart: false, unlockedCost: 100}, order: 0, unlockedAtStart: true, unlockedCost: 0},
seaside: {nameKey: "tama.region.seaside.name", order: 2, unlockedAtStart: false, unlockedCost: 500}, cropcountry: {nameKey: "tama.region.cropcountry.name",
skyland: {nameKey: "tama.region.skyland.name", order: 3, unlockedAtStart: false, unlockedCost: 1000} 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}
}; };
+28 -10
View File
@@ -161,38 +161,56 @@ system.beforeEvents.startup.subscribe(({ customCommandRegistry }) => {
if (!origin.sourceEntity) { return; } if (!origin.sourceEntity) { return; }
if (result.ok) { if (result.ok) {
origin.sourceEntity.sendMessage(`${region} unlocked`); origin.sourceEntity.sendMessage({
translate: "tama.unlock.success",
with: { rawtext: [{ translate: REGIONS[region].nameKey }] }
});
return; return;
} }
// reason codes are not display text - this is developer-facing // reason codes are turned into player-facing text here.
// for now. Player copy belongs in the lang file later. // Every branch produces a RawMessage - a plain string would be
// sent literally instead of being looked up in the lang file.
let why; let why;
switch (result.reason) { switch (result.reason) {
case "already_unlocked": case "already_unlocked":
why = `${region} is already unlocked`; why = {
translate: "tama.unlock.already_unlocked",
with: { rawtext: [{ translate: REGIONS[region].nameKey }] }
};
break; break;
case "missing_prior_region": case "missing_prior_region":
why = result.requires 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; break;
case "insufficient_funds": 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; break;
case "unknown_region": case "unknown_region":
why = `Unknown region: ${region}`; why = { translate: "tama.unlock.unknown_region" };
break; break;
default: default:
why = `Cannot unlock ${region}`; why = {
translate: "tama.unlock.default",
with: { rawtext: [{ translate: REGIONS[region].nameKey }] }
};
} }
origin.sourceEntity.sendMessage(why); 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 { return {
status: CustomCommandStatus.Success, status: CustomCommandStatus.Success,
message: `Unlock requested for ${region}`,
}; };
}), }),
View File
+1 -1
View File
@@ -128,7 +128,7 @@ export function returnBalance(){
} }
export function printGateState(){ export function printGateState(){
console.log(JSON.stringify(getState().gates)); log(JSON.stringify(getState().gates));
} }
/** /**
+15 -6
View File
@@ -42,22 +42,31 @@ export function canUnlock(regionID) {
WE ARE KEYING FOR THE KEY VALUE'S ORDER PRIOR TO PASSED REGION{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 the prior value has to be true for the passed region to unlock
*/ */
let answer = null; let priorRegion = null;
for (const id in REGIONS) { for (const id in REGIONS) {
// never pass lagoon otherwise all conditions fail // never pass lagoon otherwise all conditions fail
if (REGIONS[id].order === order - 1) { 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 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 }; return { ok: false, reason: "missing_prior_region", requires: null };
} }
//the region before this one must be open first /*
if (gates[answer] !== true) { the prior region before this one must be open first
return { ok: false, reason: "missing_prior_region", requires: answer }; */
if (gates[priorRegion] !== true) {
return { ok: false, reason: "missing_prior_region", requires: priorRegion };
} }
//they have to be able to pay for it. //they have to be able to pay for it.
+15
View File
@@ -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
-7
View File
@@ -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