[Bug][UI/UX] Fix fiery fallout message bug (#5834)

* Fix fiery fallout message bug

* Ensure pokemon names are replaced when there is no separator
This commit is contained in:
Sirz Benjie 2025-05-18 00:22:09 -05:00 committed by GitHub
parent 22f5ed1232
commit 9ae969117b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -35,20 +35,22 @@ export class MessagePhase extends Phase {
this.text = this.text.split(pokename[p]).join(repname[p]);
}
const pageIndex = this.text.indexOf("$");
if (pageIndex !== -1) {
let page0 = this.text.slice(0, pageIndex);
let page1 = this.text.slice(pageIndex + 1);
// Pokemon names must be re-inserted _after_ the split, otherwise the index will be wrong
for (let p = 0; p < globalScene.getPlayerField().length; p++) {
page0 = page0.split(repname[p]).join(pokename[p]);
page1 = page1.split(repname[p]).join(pokename[p]);
}
globalScene.unshiftPhase(
new MessagePhase(page1, this.callbackDelay, this.prompt, this.promptDelay, this.speaker),
);
this.text = page0.trim();
} else {
for (let p = 0; p < globalScene.getPlayerField().length; p++) {
this.text = this.text.split(repname[p]).join(pokename[p]);
}
if (pageIndex !== -1) {
globalScene.unshiftPhase(
new MessagePhase(
this.text.slice(pageIndex + 1),
this.callbackDelay,
this.prompt,
this.promptDelay,
this.speaker,
),
);
this.text = this.text.slice(0, pageIndex).trim();
}
}