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
+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}`,
};
}),