mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-09-23 15:03:24 +02:00
Merge 2c2ea6b3d8
into 1c9843618c
This commit is contained in:
commit
c18640078c
@ -22,7 +22,6 @@ import { TrainerType } from "#enums/trainer-type";
|
||||
import { TrainerVariant } from "#enums/trainer-variant";
|
||||
import type { EnemyPokemon } from "#field/pokemon";
|
||||
import { PokemonMove } from "#moves/pokemon-move";
|
||||
import { getIsInitialized, initI18n } from "#plugins/i18n";
|
||||
import type { EvilTeam } from "#trainers/evil-admin-trainer-pools";
|
||||
import { evilAdminTrainerPools } from "#trainers/evil-admin-trainer-pools";
|
||||
import {
|
||||
@ -176,15 +175,9 @@ export class TrainerConfig {
|
||||
setName(name: string): TrainerConfig {
|
||||
if (name === "Finn") {
|
||||
// Give the rival a localized name
|
||||
// First check if i18n is initialized
|
||||
if (!getIsInitialized()) {
|
||||
initI18n();
|
||||
}
|
||||
// This is only the male name, because the female name is handled in a different function (setHasGenders)
|
||||
if (name === "Finn") {
|
||||
name = i18next.t("trainerNames:rival");
|
||||
}
|
||||
}
|
||||
|
||||
this.name = name;
|
||||
|
||||
@ -200,11 +193,6 @@ export class TrainerConfig {
|
||||
}
|
||||
|
||||
setTitle(title: string): TrainerConfig {
|
||||
// First check if i18n is initialized
|
||||
if (!getIsInitialized()) {
|
||||
initI18n();
|
||||
}
|
||||
|
||||
title = toCamelCase(title);
|
||||
|
||||
// Get the title from the i18n file
|
||||
@ -293,11 +281,6 @@ export class TrainerConfig {
|
||||
setHasGenders(nameFemale?: string, femaleEncounterBgm?: TrainerType | string): TrainerConfig {
|
||||
// If the female name is 'Ivy' (the rival), assign a localized name.
|
||||
if (nameFemale === "Ivy") {
|
||||
// Check if the internationalization (i18n) system is initialized.
|
||||
if (!getIsInitialized()) {
|
||||
// Initialize the i18n system if it is not already initialized.
|
||||
initI18n();
|
||||
}
|
||||
// Set the localized name for the female rival.
|
||||
this.nameFemale = i18next.t("trainerNames:rivalFemale");
|
||||
} else {
|
||||
@ -371,11 +354,6 @@ export class TrainerConfig {
|
||||
* @returns The updated TrainerConfig instance.
|
||||
*/
|
||||
setDoubleTitle(titleDouble: string): TrainerConfig {
|
||||
// First check if i18n is initialized
|
||||
if (!getIsInitialized()) {
|
||||
initI18n();
|
||||
}
|
||||
|
||||
titleDouble = toCamelCase(titleDouble);
|
||||
|
||||
// Get the title from the i18n file
|
||||
@ -564,10 +542,6 @@ export class TrainerConfig {
|
||||
signatureSpecies: (SpeciesId | SpeciesId[])[],
|
||||
specialtyType?: PokemonType,
|
||||
): TrainerConfig {
|
||||
if (!getIsInitialized()) {
|
||||
initI18n();
|
||||
}
|
||||
|
||||
if (specialtyType != null) {
|
||||
this.setSpecialtyType(specialtyType);
|
||||
}
|
||||
@ -600,10 +574,6 @@ export class TrainerConfig {
|
||||
* @returns The updated TrainerConfig instance.
|
||||
*/
|
||||
initForStatTrainer(_isMale = false): TrainerConfig {
|
||||
if (!getIsInitialized()) {
|
||||
initI18n();
|
||||
}
|
||||
|
||||
this.setPartyTemplates(trainerPartyTemplates.ELITE_FOUR);
|
||||
|
||||
const nameForCall = toCamelCase(this.name);
|
||||
@ -632,9 +602,6 @@ export class TrainerConfig {
|
||||
rematch = false,
|
||||
specialtyType?: PokemonType,
|
||||
): TrainerConfig {
|
||||
if (!getIsInitialized()) {
|
||||
initI18n();
|
||||
}
|
||||
if (rematch) {
|
||||
this.setPartyTemplates(trainerPartyTemplates.ELITE_FOUR);
|
||||
} else {
|
||||
@ -676,11 +643,6 @@ export class TrainerConfig {
|
||||
ignoreMinTeraWave = false,
|
||||
teraSlot?: number,
|
||||
): TrainerConfig {
|
||||
// Check if the internationalization (i18n) system is initialized.
|
||||
if (!getIsInitialized()) {
|
||||
initI18n();
|
||||
}
|
||||
|
||||
// Set the function to generate the Gym Leader's party template.
|
||||
this.setPartyTemplateFunc(getGymLeaderPartyTemplate);
|
||||
|
||||
@ -733,11 +695,6 @@ export class TrainerConfig {
|
||||
specialtyType?: PokemonType,
|
||||
teraSlot?: number,
|
||||
): TrainerConfig {
|
||||
// Check if the internationalization (i18n) system is initialized.
|
||||
if (!getIsInitialized()) {
|
||||
initI18n();
|
||||
}
|
||||
|
||||
// Set the party templates for the Elite Four.
|
||||
this.setPartyTemplates(trainerPartyTemplates.ELITE_FOUR);
|
||||
|
||||
@ -784,11 +741,6 @@ export class TrainerConfig {
|
||||
* @returns The updated TrainerConfig instance.
|
||||
*/
|
||||
initForChampion(isMale: boolean): TrainerConfig {
|
||||
// Check if the internationalization (i18n) system is initialized.
|
||||
if (!getIsInitialized()) {
|
||||
initI18n();
|
||||
}
|
||||
|
||||
// Set the party templates for the Champion.
|
||||
this.setPartyTemplates(trainerPartyTemplates.CHAMPION);
|
||||
|
||||
@ -819,10 +771,6 @@ export class TrainerConfig {
|
||||
* @returns The updated TrainerConfig instance.
|
||||
*/
|
||||
setLocalizedName(name: string): TrainerConfig {
|
||||
// Check if the internationalization (i18n) system is initialized.
|
||||
if (!getIsInitialized()) {
|
||||
initI18n();
|
||||
}
|
||||
this.name = i18next.t(`trainerNames:${toCamelCase(name)}`);
|
||||
return this;
|
||||
}
|
||||
@ -854,17 +802,11 @@ export class TrainerConfig {
|
||||
}
|
||||
}
|
||||
// Check if !variant is true, if so return the name, else return the name with _female appended
|
||||
else if (variant) {
|
||||
if (!getIsInitialized()) {
|
||||
initI18n();
|
||||
}
|
||||
// Check if the female version exists in the i18n file
|
||||
if (i18next.exists(`trainerClasses:${toCamelCase(this.name)}Female`)) {
|
||||
// If it does, return
|
||||
else if (variant && i18next.exists(`trainerClasses:${toCamelCase(this.name)}Female`)) {
|
||||
return ret + "Female";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import { TrainerType } from "#enums/trainer-type";
|
||||
import { TrainerVariant } from "#enums/trainer-variant";
|
||||
import type { EnemyPokemon } from "#field/pokemon";
|
||||
import type { PersistentModifier } from "#modifiers/modifier";
|
||||
import { getIsInitialized, initI18n } from "#plugins/i18n";
|
||||
import type { TrainerConfig } from "#trainers/trainer-config";
|
||||
import { trainerConfigs } from "#trainers/trainer-config";
|
||||
import { TrainerPartyCompoundTemplate, type TrainerPartyTemplate } from "#trainers/trainer-party-template";
|
||||
@ -174,11 +173,6 @@ export class Trainer extends Phaser.GameObjects.Container {
|
||||
if (this.name) {
|
||||
// If the title should be included.
|
||||
if (includeTitle) {
|
||||
// Check if the internationalization (i18n) system is initialized.
|
||||
if (!getIsInitialized()) {
|
||||
// Initialize the i18n system if it is not already initialized.
|
||||
initI18n();
|
||||
}
|
||||
// Get the localized trainer class name from the i18n file and set it as the title.
|
||||
// This is used for trainer class names, not titles like "Elite Four, Champion, etc."
|
||||
title = i18next.t(`trainerClasses:${toCamelCase(name)}`);
|
||||
|
@ -1,8 +1,9 @@
|
||||
import "#app/polyfills";
|
||||
// All polyfills MUST be loaded first for side effects
|
||||
import "#app/polyfills";
|
||||
// Initializes i18n on import
|
||||
import "#app/plugins/i18n";
|
||||
|
||||
import { InvertPostFX } from "#app/pipelines/invert";
|
||||
import { initI18n } from "#app/plugins/i18n";
|
||||
import { version } from "#package.json";
|
||||
import Phaser from "phaser";
|
||||
import BBCodeTextPlugin from "phaser3-rex-plugins/plugins/bbcodetext-plugin";
|
||||
@ -53,7 +54,6 @@ let game;
|
||||
let manifest;
|
||||
|
||||
const startGame = async () => {
|
||||
await initI18n();
|
||||
const LoadingScene = (await import("./loading-scene")).LoadingScene;
|
||||
const BattleScene = (await import("./battle-scene")).BattleScene;
|
||||
game = new Phaser.Game({
|
||||
|
@ -3,7 +3,7 @@ import { toKebabCase } from "#utils/strings";
|
||||
import i18next from "i18next";
|
||||
import LanguageDetector from "i18next-browser-languagedetector";
|
||||
import HttpBackend from "i18next-http-backend";
|
||||
import processor, { KoreanPostpositionProcessor } from "i18next-korean-postposition-processor";
|
||||
import processor from "i18next-korean-postposition-processor";
|
||||
|
||||
//#region Interfaces/Types
|
||||
|
||||
@ -15,8 +15,6 @@ interface LoadingFontFaceProperty {
|
||||
|
||||
//#region Constants
|
||||
|
||||
let isInitialized = false;
|
||||
|
||||
const unicodeRanges = {
|
||||
fullwidth: "U+FF00-FFEF",
|
||||
hangul: "U+1100-11FF,U+3130-318F,U+A960-A97F,U+AC00-D7AF,U+D7B0-D7FF",
|
||||
@ -136,19 +134,9 @@ function i18nMoneyFormatter(amount: any): string {
|
||||
return `@[MONEY]{${i18next.t("common:money", { amount })}}`;
|
||||
}
|
||||
|
||||
//#region Exports
|
||||
//#region Initialization
|
||||
|
||||
/**
|
||||
* Initialize i18n with fonts
|
||||
*/
|
||||
export async function initI18n(): Promise<void> {
|
||||
// Prevent reinitialization
|
||||
if (isInitialized) {
|
||||
return;
|
||||
}
|
||||
isInitialized = true;
|
||||
|
||||
/**
|
||||
/*
|
||||
* i18next is a localization library for maintaining and using translation resources.
|
||||
*
|
||||
* Q: How do I add a new language?
|
||||
@ -165,11 +153,12 @@ export async function initI18n(): Promise<void> {
|
||||
* A: In src/system/settings.ts, add a new case to the Setting.Language switch statement.
|
||||
*/
|
||||
|
||||
i18next.use(HttpBackend);
|
||||
i18next.use(LanguageDetector);
|
||||
i18next.use(processor);
|
||||
i18next.use(new KoreanPostpositionProcessor());
|
||||
await i18next.init({
|
||||
await i18next
|
||||
.use(HttpBackend)
|
||||
.use(LanguageDetector)
|
||||
.use(processor)
|
||||
.init(
|
||||
{
|
||||
fallbackLng: {
|
||||
"es-MX": ["es-ES", "en"],
|
||||
default: ["en"],
|
||||
@ -191,7 +180,6 @@ export async function initI18n(): Promise<void> {
|
||||
"tr",
|
||||
"ro",
|
||||
"ru",
|
||||
"tl",
|
||||
],
|
||||
backend: {
|
||||
loadPath(lng: string, [ns]: string[]) {
|
||||
@ -306,23 +294,19 @@ export async function initI18n(): Promise<void> {
|
||||
detection: {
|
||||
lookupLocalStorage: "prLang",
|
||||
},
|
||||
debug: Number(import.meta.env.VITE_I18N_DEBUG) === 1,
|
||||
debug: import.meta.env.VITE_I18N_DEBUG === "1",
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
postProcess: ["korean-postposition"],
|
||||
});
|
||||
|
||||
},
|
||||
async () => {
|
||||
if (i18next.services.formatter) {
|
||||
i18next.services.formatter.add("money", i18nMoneyFormatter);
|
||||
}
|
||||
|
||||
await initFonts(localStorage.getItem("prLang") ?? undefined);
|
||||
}
|
||||
|
||||
export function getIsInitialized(): boolean {
|
||||
return isInitialized;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
export default i18next;
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
import "vitest-canvas-mock";
|
||||
import "#plugins/i18n"; // Initializes i18n on import
|
||||
|
||||
import { MockConsole } from "#test/test-utils/mocks/mock-console/mock-console";
|
||||
import { logTestEnd, logTestStart } from "#test/test-utils/setup/test-end-log";
|
||||
import { initTests } from "#test/test-utils/test-file-initialization";
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { SESSION_ID_COOKIE_NAME } from "#app/constants";
|
||||
import { initializeGame } from "#app/init/init";
|
||||
import { initI18n } from "#plugins/i18n";
|
||||
import { blobToString } from "#test/test-utils/game-manager-utils";
|
||||
import { manageListeners } from "#test/test-utils/listeners-manager";
|
||||
import { MockConsole } from "#test/test-utils/mocks/mock-console/mock-console";
|
||||
@ -15,26 +14,18 @@ import InputText from "phaser3-rex-plugins/plugins/inputtext";
|
||||
let wasInitialized = false;
|
||||
|
||||
/**
|
||||
* Run initialization code upon starting a new file, both per-suite and per-instance oncess.
|
||||
* Run initialization code upon starting a new file, both per-suite and per-instance ones.
|
||||
*/
|
||||
export function initTests(): void {
|
||||
setupStubs();
|
||||
if (!wasInitialized) {
|
||||
initTestFile();
|
||||
initializeGame();
|
||||
wasInitialized = true;
|
||||
}
|
||||
|
||||
manageListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize various values at the beginning of each testing instance.
|
||||
*/
|
||||
function initTestFile(): void {
|
||||
initI18n();
|
||||
initializeGame();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup various stubs for testing.
|
||||
* @todo Move this into a dedicated stub file instead of running it once per test instance
|
||||
|
Loading…
Reference in New Issue
Block a user