Finish evolution logic and sequence

This commit is contained in:
Flashfyre committed 2023-04-10 13:54:06 -04:00
1 parent 824106c2a3
commit 5b097b347b
17 files changed
+693 -361

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
import BattleScene from "../battle-scene";
import { Mode } from "./ui";
import UiHandler from "./uiHandler";
export default class EvolutionSceneHandler extends UiHandler {
public evolutionContainer: Phaser.GameObjects.Container;
constructor(scene: BattleScene) {
super(scene, Mode.EVOLUTION_SCENE);
}
setup() {
this.evolutionContainer = this.scene.add.container(0, -this.scene.game.canvas.height / 6);
this.scene.fieldUI.add(this.evolutionContainer);
}
processInput(keyCode: integer) {
this.scene.ui.getMessageHandler().processInput(keyCode);
}
setCursor(_cursor: integer): boolean {
return false;
}
clear() {
this.evolutionContainer.removeAll(true);
}
}
+55 -14
View File
@@ -16,9 +16,25 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler {
this.pendingPrompt = false;
}
showText(text: string, delay?: integer, callback?: Function, callbackDelay?: integer, prompt?: boolean) {
showText(text: string, delay?: integer, callback?: Function, callbackDelay?: integer, prompt?: boolean, promptDelay?: integer) {
if (delay === null || delay === undefined)
delay = 20;
let delayMap = new Map<integer, integer>();
let soundMap = new Map<integer, string>();
const actionPattern = /@(d|s)\{(.*?)\}/;
let actionMatch: RegExpExecArray;
while ((actionMatch = actionPattern.exec(text))) {
switch (actionMatch[1]) {
case 'd':
delayMap.set(actionMatch.index, parseInt(actionMatch[2]));
break;
case 's':
soundMap.set(actionMatch.index, actionMatch[2]);
break;
}
text = text.slice(0, actionMatch.index) + text.slice(actionMatch.index + actionMatch[2].length + 4);
}
if (this.textTimer) {
this.textTimer.remove();
if (this.textCallbackTimer)
@@ -26,7 +42,13 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler {
};
if (prompt) {
const originalCallback = callback;
callback = () => this.showPrompt(originalCallback, callbackDelay);
callback = () => {
const showPrompt = () => this.showPrompt(originalCallback, callbackDelay);
if (promptDelay)
this.scene.time.delayedCall(promptDelay, showPrompt);
else
showPrompt();
};
}
if (delay) {
this.clearText();
@@ -35,19 +57,38 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler {
this.textTimer = this.scene.time.addEvent({
delay: delay,
callback: () => {
this.message.setText(text.slice(0, text.length - this.textTimer.repeatCount));
if (callback && !this.textTimer.repeatCount) {
if (callbackDelay && !prompt) {
this.textCallbackTimer = this.scene.time.delayedCall(callbackDelay, () => {
if (this.textCallbackTimer) {
this.textCallbackTimer.destroy();
this.textCallbackTimer = null;
}
const charIndex = text.length - this.textTimer.repeatCount;
const charSound = soundMap.get(charIndex);
const charDelay = delayMap.get(charIndex);
this.message.setText(text.slice(0, charIndex));
const advance = () => {
if (charSound)
this.scene.sound.play(charSound);
if (callback && !this.textTimer.repeatCount) {
if (callbackDelay && !prompt) {
this.textCallbackTimer = this.scene.time.delayedCall(callbackDelay, () => {
if (this.textCallbackTimer) {
this.textCallbackTimer.destroy();
this.textCallbackTimer = null;
}
callback();
});
} else
callback();
});
} else
callback();
}
}
};
if (charDelay) {
this.textTimer.paused = true;
this.scene.tweens.addCounter({
duration: charDelay,
useFrames: true,
onComplete: () => {
this.textTimer.paused = false;
advance();
}
});
} else
advance();
},
repeat: text.length
});
+24 -1
View File
@@ -411,6 +411,12 @@ export default class SummaryUiHandler extends UiHandler {
extraRowText.setOrigin(0, 1);
this.extraMoveRowContainer.add(extraRowText);
if (this.summaryUiMode === SummaryUiMode.LEARN_MOVE) {
const newMoveTypeIcon = this.scene.add.sprite(0, 0, 'types', Type[this.newMove.type].toLowerCase());
newMoveTypeIcon.setOrigin(0, 1);
this.extraMoveRowContainer.add(newMoveTypeIcon);
}
this.moveRowsContainer = this.scene.add.container(0, 0);
this.movesContainer.add(this.moveRowsContainer);
@@ -518,7 +524,24 @@ export default class SummaryUiHandler extends UiHandler {
this.pokemon = null;
this.cursor = -1;
this.newMove = null;
this.moveSelectFunction = null;
if (this.moveSelect) {
this.moveSelect = false;
this.moveSelectFunction = null;
this.extraMoveRowContainer.setVisible(false);
if (this.moveCursorBlinkTimer) {
this.moveCursorBlinkTimer.destroy();
this.moveCursorBlinkTimer = null;
}
if (this.moveCursorObj) {
this.moveCursorObj.destroy();
this.moveCursorObj = null;
}
if (this.selectedMoveCursorObj) {
this.selectedMoveCursorObj.destroy();
this.selectedMoveCursorObj = null;
}
this.hideMoveEffect(true);
}
this.summaryContainer.setVisible(false);
this.summaryPageContainer.setVisible(false);
}
+29 -15
View File
@@ -10,7 +10,7 @@ import ModifierSelectUiHandler from './modifier-select-ui-handler';
import BallUiHandler from './ball-ui-handler';
import SummaryUiHandler from './summary-ui-handler';
import StarterSelectUiHandler from './starter-select-ui-handler';
import EvolutionUiHandler from './evolution-ui-handler';
import EvolutionSceneHandler from './evolution-scene-handler';
export enum Mode {
MESSAGE = 0,
@@ -21,13 +21,19 @@ export enum Mode {
MODIFIER_SELECT,
PARTY,
SUMMARY,
STARTER_SELECT
STARTER_SELECT,
EVOLUTION_SCENE
};
const transitionModes = [
Mode.PARTY,
Mode.SUMMARY,
Mode.STARTER_SELECT,
Mode.EVOLUTION_SCENE
];
const noTransitionModes = [
Mode.CONFIRM
];
export default class UI extends Phaser.GameObjects.Container {
@@ -50,7 +56,8 @@ export default class UI extends Phaser.GameObjects.Container {
new ModifierSelectUiHandler(scene),
new PartyUiHandler(scene),
new SummaryUiHandler(scene),
new StarterSelectUiHandler(scene)
new StarterSelectUiHandler(scene),
new EvolutionSceneHandler(scene)
];
}
@@ -79,12 +86,12 @@ export default class UI extends Phaser.GameObjects.Container {
this.getHandler().processInput(keyCode);
}
showText(text: string, delay?: integer, callback?: Function, callbackDelay?: integer, prompt?: boolean): void {
showText(text: string, delay?: integer, callback?: Function, callbackDelay?: integer, prompt?: boolean, promptDelay?: integer): void {
const handler = this.getHandler();
if (handler instanceof MessageUiHandler)
(handler as MessageUiHandler).showText(text, delay, callback, callbackDelay, prompt);
(handler as MessageUiHandler).showText(text, delay, callback, callbackDelay, prompt, promptDelay);
else
this.getMessageHandler().showText(text, delay, callback, callbackDelay, prompt);
this.getMessageHandler().showText(text, delay, callback, callbackDelay, prompt, promptDelay);
}
clearText(): void {
@@ -111,20 +118,23 @@ export default class UI extends Phaser.GameObjects.Container {
this.scene.sound.play('error');
}
private setModeInternal(mode: Mode, clear: boolean, args: any[]): Promise<void> {
private setModeInternal(mode: Mode, clear: boolean, forceTransition: boolean, args: any[]): Promise<void> {
return new Promise(resolve => {
if (this.mode === mode) {
if (this.mode === mode && !forceTransition) {
resolve();
return;
}
const doSetMode = () => {
if (clear)
this.getHandler().clear();
this.mode = mode;
this.getHandler().show(args);
if (this.mode !== mode) {
if (clear)
this.getHandler().clear();
this.mode = mode;
this.getHandler().show(args);
}
resolve();
};
if ((transitionModes.indexOf(this.mode) > -1 || transitionModes.indexOf(mode) > -1) && !(this.scene as BattleScene).auto) {
if ((transitionModes.indexOf(this.mode) > -1 || transitionModes.indexOf(mode) > -1)
&& (noTransitionModes.indexOf(this.mode) === -1 && noTransitionModes.indexOf(mode) === -1) && !(this.scene as BattleScene).auto) {
this.transitioning = true;
this.overlay.setAlpha(0);
this.overlay.setVisible(true);
@@ -153,10 +163,14 @@ export default class UI extends Phaser.GameObjects.Container {
}
setMode(mode: Mode, ...args: any[]): Promise<void> {
return this.setModeInternal(mode, true, args);
return this.setModeInternal(mode, true, false, args);
}
setModeForceTransition(mode: Mode, ...args: any[]): Promise<void> {
return this.setModeInternal(mode, true, true, args);
}
setModeWithoutClear(mode: Mode, ...args: any[]): Promise<void> {
return this.setModeInternal(mode, false, args);
return this.setModeInternal(mode, false, false, args);
}
}