From ca1ae4b55621a38b6e72778f57be506f0c9f7c3c Mon Sep 17 00:00:00 2001 From: Matthew Olker Date: Sun, 19 May 2024 21:40:58 -0400 Subject: [PATCH] cleanup language and candy in starter select ui handler --- src/ui/starter-select-ui-handler.ts | 153 ++++++++++++---------------- 1 file changed, 63 insertions(+), 90 deletions(-) diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index c3681651964..264062c20fd 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -42,48 +42,69 @@ export interface Starter { pokerus: boolean; } +interface LanguageSetting { + starterInfoTextSize: string, + instructionTextSize: string, + starterInfoXPosition: integer +} + +const languageSettings: { [key: string]: LanguageSetting } = { + "en":{ + starterInfoTextSize: '56px', + instructionTextSize: '42px', + starterInfoXPosition: 31 + }, + "de":{ + starterInfoTextSize: '56px', + instructionTextSize: '35px', + starterInfoXPosition: 31 + }, + "es":{ + starterInfoTextSize: '56px', + instructionTextSize: '35px', + starterInfoXPosition: 31 + }, + "it":{ + starterInfoTextSize: '56px', + instructionTextSize: '38px', + starterInfoXPosition: 31 + }, + "fr":{ + starterInfoTextSize: '54px', + instructionTextSize: '42px', + starterInfoXPosition: 31 + }, + "zh_CN":{ + starterInfoTextSize: '56px', + instructionTextSize: '42px', + starterInfoXPosition: 31 + }, + "pt_BR":{ + starterInfoTextSize: '47px', + instructionTextSize: '38px', + starterInfoXPosition: 32 + }, +} + +const starterCandyCosts: { passive: integer, costReduction: [integer, integer] }[] = [ + { passive: 50, costReduction: [30, 75] }, // 1 + { passive: 45, costReduction: [25, 60] }, // 2 + { passive: 30, costReduction: [20, 50] }, // 3 + { passive: 25, costReduction: [15, 40] }, // 4 + { passive: 20, costReduction: [12, 35] }, // 5 + { passive: 15, costReduction: [10, 30] }, // 6 + { passive: 10, costReduction: [8, 20] }, // 7 + { passive: 10, costReduction: [5, 15] }, // 8 + { passive: 10, costReduction: [3, 10] }, // 9 + { passive: 10, costReduction: [3, 10] }, // 10 +] + function getPassiveCandyCount(baseValue: integer): integer { - switch (baseValue) { - case 1: - return 50; - case 2: - return 45; - case 3: - return 40; - case 4: - return 30; - case 5: - return 25; - case 6: - return 20; - case 7: - return 15; - default: - return 10; - } + return starterCandyCosts[baseValue - 1].passive; } function getValueReductionCandyCounts(baseValue: integer): [integer, integer] { - switch (baseValue) { - case 1: - return [ 30, 75]; - case 2: - return [ 25, 60 ]; - case 3: - return [ 20, 50 ]; - case 4: - return [ 15, 40 ]; - case 5: - return [ 12, 35 ]; - case 6: - return [ 10, 30 ]; - case 7: - return [ 8, 20 ]; - case 8: - return [ 5, 15 ]; - default: - return [ 3, 10 ]; - } + return starterCandyCosts[baseValue - 1].costReduction; } const gens = [ @@ -255,32 +276,12 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonUncaughtText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonUncaughtText); - let starterInfoXPosition = 31; // Only text - // The position should be set per language const currentLanguage = i18next.language; - switch (currentLanguage) { - case 'pt_BR': - starterInfoXPosition = 32; - break; - default: - starterInfoXPosition = 31; - break - } + // The position should be set per language + let starterInfoXPosition = languageSettings[currentLanguage].starterInfoXPosition; - let starterInfoTextSize = '56px'; // Labels and text // The font size should be set per language - // currentLanguage is already defined - switch (currentLanguage) { - case 'fr': - starterInfoTextSize = '54px'; - break; - case 'pt_BR': - starterInfoTextSize = '47px'; - break; - default: - starterInfoTextSize = '56px'; - break - } + let starterInfoTextSize = languageSettings[currentLanguage].starterInfoTextSize; this.pokemonAbilityLabelText = addTextObject(this.scene, 6, 127, i18next.t("starterSelectUiHandler:ability"), TextStyle.SUMMARY_ALT, { fontSize: starterInfoTextSize }); this.pokemonAbilityLabelText.setOrigin(0, 0); @@ -589,36 +590,8 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.starterSelectContainer.add(this.pokemonEggMovesContainer); - - - let instructionTextSize = '42px'; // The font size should be set per language - // currentLanguage is already defined in the previous code block - switch (currentLanguage) { - case 'de': - instructionTextSize = '35px'; - break; - case 'en': - instructionTextSize = '42px'; - break; - case 'es': - instructionTextSize = '35px'; - break; - case 'fr': - instructionTextSize = '42px'; - break; - case 'it': - instructionTextSize = '38px'; - break; - case 'pt_BR': - instructionTextSize = '38px'; - break; - case 'zh_CN': - instructionTextSize = '42px'; - break; - - } - + let instructionTextSize = languageSettings[currentLanguage].instructionTextSize; this.instructionsText = addTextObject(this.scene, 4, 156, '', TextStyle.PARTY, { fontSize: instructionTextSize }); this.starterSelectContainer.add(this.instructionsText);