changed all user face commands to translatable, return reasons etc
This commit is contained in:
@@ -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}
|
||||
};
|
||||
|
||||
@@ -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}`,
|
||||
};
|
||||
}),
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ export function returnBalance(){
|
||||
}
|
||||
|
||||
export function printGateState(){
|
||||
console.log(JSON.stringify(getState().gates));
|
||||
log(JSON.stringify(getState().gates));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user