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>}
*/
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}
};
+28 -10
View File
@@ -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}`,
};
}),
View File
+1 -1
View File
@@ -128,7 +128,7 @@ export function returnBalance(){
}
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}
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.