[Bug] skip-seen-dialogue storing strings instead of i18n keys (#3900)
* fix skipSeenDialogue storing seen dialogues were stores as actual string instead of their i18n-keys. This fixes it. Reported on discord: https://discord.com/channels/1125469663833370665/1176874654015684739/1278794542648131695 * fix falling back to english * Victory-Rival Dialgoue * Update src/phases/game-over-phase.ts Co-authored-by: Adrian T. <68144167+torranx@users.noreply.github.com> * fix showDialogue for non i18n-key calls showDialogue can be called with either text or an i18n key. This wasn't taken into account and caused some console spamming. --------- Co-authored-by: frutescens <info@laptop> Co-authored-by: innerthunder <168692175+innerthunder@users.noreply.github.com> Co-authored-by: Adrian T. <68144167+torranx@users.noreply.github.com>
This commit is contained in:
parent
e2db9cb8a4
commit
87d2300ee8
|
@ -1,7 +1,7 @@
|
||||||
import { clientSessionId } from "#app/account";
|
import { clientSessionId } from "#app/account";
|
||||||
import BattleScene from "#app/battle-scene";
|
import BattleScene from "#app/battle-scene";
|
||||||
import { BattleType } from "#app/battle";
|
import { BattleType } from "#app/battle";
|
||||||
import { miscDialogue, getCharVariantFromDialogue } from "#app/data/dialogue";
|
import { getCharVariantFromDialogue } from "#app/data/dialogue";
|
||||||
import { pokemonEvolutions } from "#app/data/pokemon-evolutions";
|
import { pokemonEvolutions } from "#app/data/pokemon-evolutions";
|
||||||
import PokemonSpecies, { getPokemonSpecies } from "#app/data/pokemon-species";
|
import PokemonSpecies, { getPokemonSpecies } from "#app/data/pokemon-species";
|
||||||
import { trainerConfigs } from "#app/data/trainer-config";
|
import { trainerConfigs } from "#app/data/trainer-config";
|
||||||
|
@ -136,12 +136,16 @@ export class GameOverPhase extends BattlePhase {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.victory && this.scene.gameMode.isClassic) {
|
if (this.victory && this.scene.gameMode.isClassic) {
|
||||||
const message = miscDialogue.ending[this.scene.gameData.gender === PlayerGender.FEMALE ? 0 : 1];
|
const dialogueKey = "miscDialogue:ending";
|
||||||
|
|
||||||
if (!this.scene.ui.shouldSkipDialogue(message)) {
|
if (!this.scene.ui.shouldSkipDialogue(dialogueKey)) {
|
||||||
this.scene.ui.fadeIn(500).then(() => {
|
this.scene.ui.fadeIn(500).then(() => {
|
||||||
this.scene.charSprite.showCharacter(`rival_${this.scene.gameData.gender === PlayerGender.FEMALE ? "m" : "f"}`, getCharVariantFromDialogue(miscDialogue.ending[this.scene.gameData.gender === PlayerGender.FEMALE ? 0 : 1])).then(() => {
|
const genderIndex = this.scene.gameData.gender ?? PlayerGender.UNSET;
|
||||||
this.scene.ui.showDialogue(message, this.scene.gameData.gender === PlayerGender.FEMALE ? trainerConfigs[TrainerType.RIVAL].name : trainerConfigs[TrainerType.RIVAL].nameFemale, null, () => {
|
const genderStr = PlayerGender[genderIndex].toLowerCase();
|
||||||
|
// Dialogue has to be retrieved so that the rival's expressions can be loaded and shown via getCharVariantFromDialogue
|
||||||
|
const dialogue = i18next.t(dialogueKey, { context: genderStr });
|
||||||
|
this.scene.charSprite.showCharacter(`rival_${this.scene.gameData.gender === PlayerGender.FEMALE ? "m" : "f"}`, getCharVariantFromDialogue(dialogue)).then(() => {
|
||||||
|
this.scene.ui.showDialogue(dialogueKey, this.scene.gameData.gender === PlayerGender.FEMALE ? trainerConfigs[TrainerType.RIVAL].name : trainerConfigs[TrainerType.RIVAL].nameFemale, null, () => {
|
||||||
this.scene.ui.fadeOut(500).then(() => {
|
this.scene.ui.fadeOut(500).then(() => {
|
||||||
this.scene.charSprite.hide().then(() => {
|
this.scene.charSprite.hide().then(() => {
|
||||||
const endCardPhase = new EndCardPhase(this.scene);
|
const endCardPhase = new EndCardPhase(this.scene);
|
||||||
|
|
22
src/ui/ui.ts
22
src/ui/ui.ts
|
@ -306,30 +306,32 @@ export default class UI extends Phaser.GameObjects.Container {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showDialogue(i18nKey: string, name: string | undefined, delay: integer | null = 0, callback: Function, callbackDelay?: integer, promptDelay?: integer): void {
|
showDialogue(keyOrText: string, name: string | undefined, delay: integer | null = 0, callback: Function, callbackDelay?: integer, promptDelay?: integer): void {
|
||||||
const battleScene = this.scene as BattleScene;
|
const battleScene = this.scene as BattleScene;
|
||||||
|
|
||||||
// Get localized dialogue (if available)
|
// Get localized dialogue (if available)
|
||||||
let hasi18n = false;
|
let hasi18n = false;
|
||||||
if (i18next.exists(i18nKey) ) {
|
let text = keyOrText;
|
||||||
const genderIndex = battleScene.gameData.gender ?? PlayerGender.UNSET;
|
const genderIndex = battleScene.gameData.gender ?? PlayerGender.UNSET;
|
||||||
const genderStr = PlayerGender[genderIndex].toLowerCase();
|
const genderStr = PlayerGender[genderIndex].toLowerCase();
|
||||||
i18nKey = i18next.t(i18nKey, { context: genderStr });
|
|
||||||
|
if (i18next.exists(keyOrText) ) {
|
||||||
|
const i18nKey = keyOrText;
|
||||||
hasi18n = true;
|
hasi18n = true;
|
||||||
|
text = i18next.t(i18nKey, { context: genderStr }); // override text with translation
|
||||||
|
|
||||||
// Skip dialogue if the player has enabled the option and the dialogue has been already seen
|
// Skip dialogue if the player has enabled the option and the dialogue has been already seen
|
||||||
if (battleScene.skipSeenDialogues &&battleScene.gameData.getSeenDialogues()[i18nKey] === true) {
|
if (battleScene.skipSeenDialogues && battleScene.gameData.getSeenDialogues()[i18nKey] === true) {
|
||||||
console.log(`Dialogue ${i18nKey} skipped`);
|
console.log(`Dialogue ${i18nKey} skipped`);
|
||||||
callback();
|
callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let showMessageAndCallback = () => {
|
let showMessageAndCallback = () => {
|
||||||
hasi18n && battleScene.gameData.saveSeenDialogue(i18nKey);
|
hasi18n && battleScene.gameData.saveSeenDialogue(keyOrText);
|
||||||
callback();
|
callback();
|
||||||
};
|
};
|
||||||
if (i18nKey.indexOf("$") > -1) {
|
if (text.indexOf("$") > -1) {
|
||||||
const messagePages = i18nKey.split(/\$/g).map(m => m.trim());
|
const messagePages = text.split(/\$/g).map(m => m.trim());
|
||||||
for (let p = messagePages.length - 1; p >= 0; p--) {
|
for (let p = messagePages.length - 1; p >= 0; p--) {
|
||||||
const originalFunc = showMessageAndCallback;
|
const originalFunc = showMessageAndCallback;
|
||||||
showMessageAndCallback = () => this.showDialogue(messagePages[p], name, null, originalFunc);
|
showMessageAndCallback = () => this.showDialogue(messagePages[p], name, null, originalFunc);
|
||||||
|
@ -338,9 +340,9 @@ export default class UI extends Phaser.GameObjects.Container {
|
||||||
} else {
|
} else {
|
||||||
const handler = this.getHandler();
|
const handler = this.getHandler();
|
||||||
if (handler instanceof MessageUiHandler) {
|
if (handler instanceof MessageUiHandler) {
|
||||||
(handler as MessageUiHandler).showDialogue(i18nKey, name, delay, showMessageAndCallback, callbackDelay, true, promptDelay);
|
(handler as MessageUiHandler).showDialogue(text, name, delay, showMessageAndCallback, callbackDelay, true, promptDelay);
|
||||||
} else {
|
} else {
|
||||||
this.getMessageHandler().showDialogue(i18nKey, name, delay, showMessageAndCallback, callbackDelay, true, promptDelay);
|
this.getMessageHandler().showDialogue(text, name, delay, showMessageAndCallback, callbackDelay, true, promptDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue