Refactor controls and add random starter function

pull/1/head
Flashfyre 2023-04-11 00:24:55 -04:00
parent 15c3318bd5
commit 8e6e1fd233
14 changed files with 171 additions and 150 deletions

View File

@ -1,5 +1,5 @@
import { SelectModifierPhase } from "./battle-phases";
import BattleScene from "./battle-scene";
import BattleScene, { Button } from "./battle-scene";
import { ModifierTier, ModifierType, PokemonBaseStatBoosterModifierType, PokemonHpRestoreModifierType, PokemonReviveModifierType } from "./modifier";
import Pokemon, { AiType, EnemyPokemon, PlayerPokemon, PokemonMove } from "./pokemon";
import { Species } from "./species";
@ -53,8 +53,6 @@ export function initAutoPlay() {
return originalAddCounter.apply(this, [ config ]);
};
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
PlayerPokemon.prototype.getNextMove = EnemyPokemon.prototype.getNextMove;
const playerPokemon = this.getParty()[0] as PlayerPokemon;
@ -132,14 +130,14 @@ export function initAutoPlay() {
callbackDelay = 0;
originalMessageUiHandlerShowPrompt.apply(this, [ callback, callbackDelay ]);
if (thisArg.auto)
thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z));
thisArg.time.delayedCall(20, () => this.processInput(Button.ACTION));
};
const originalMessageUiHandlerPromptLevelUpStats = messageUiHandler.promptLevelUpStats;
messageUiHandler.promptLevelUpStats = function (prevStats: integer[], showTotals: boolean, callback?: Function) {
originalMessageUiHandlerPromptLevelUpStats.apply(this, [ prevStats, showTotals, callback ]);
if (thisArg.auto)
thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z));
thisArg.time.delayedCall(20, () => this.processInput(Button.ACTION));
};
const originalCommandUiHandlerShow = commandUiHandler.show;
@ -153,10 +151,10 @@ export function initAutoPlay() {
console.log('Switching to ', Species[thisArg.getParty()[bestPartyMemberIndex].species.speciesId]);
nextPartyMemberIndex = bestPartyMemberIndex;
commandUiHandler.setCursor(2);
thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z));
thisArg.time.delayedCall(20, () => this.processInput(Button.ACTION));
} else {
commandUiHandler.setCursor(0);
thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z));
thisArg.time.delayedCall(20, () => this.processInput(Button.ACTION));
}
});
}
@ -171,7 +169,7 @@ export function initAutoPlay() {
thisArg.time.delayedCall(20, () => {
const nextMove = playerPokemon.getNextMove() as PokemonMove;
fightUiHandler.setCursor(playerPokemon.moveset.indexOf(nextMove));
thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z));
thisArg.time.delayedCall(20, () => this.processInput(Button.ACTION));
});
}
};
@ -186,10 +184,10 @@ export function initAutoPlay() {
partyUiHandler.setCursor(nextPartyMemberIndex);
nextPartyMemberIndex = -1;
if (partyUiHandler.partyUiMode === PartyUiMode.MODIFIER || partyUiHandler.getCursor()) {
this.processInput(keyCodes.Z);
thisArg.time.delayedCall(250, () => this.processInput(keyCodes.Z));
this.processInput(Button.ACTION);
thisArg.time.delayedCall(250, () => this.processInput(Button.ACTION));
} else
this.processInput(keyCodes.X);
this.processInput(Button.CANCEL);
});
}
};
@ -203,7 +201,7 @@ export function initAutoPlay() {
if (bestPartyMemberIndex)
nextPartyMemberIndex = bestPartyMemberIndex;
switchCheckUiHandler.setCursor(bestPartyMemberIndex ? 1 : 0);
thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z));
thisArg.time.delayedCall(20, () => this.processInput(Button.ACTION));
});
}
}
@ -285,7 +283,7 @@ export function initAutoPlay() {
const trySelectModifier = () => {
modifierSelectUiHandler.setCursor(optionIndex);
thisArg.time.delayedCall(20, () => {
modifierSelectUiHandler.processInput(keyCodes.Z);
modifierSelectUiHandler.processInput(Button.ACTION);
thisArg.time.delayedCall(250, () => {
console.log(modifierTypes[optionIndex]?.name);
if (thisArg.getCurrentPhase() instanceof SelectModifierPhase) {
@ -293,7 +291,7 @@ export function initAutoPlay() {
optionIndex++;
thisArg.time.delayedCall(250, () => trySelectModifier());
} else
modifierSelectUiHandler.processInput(keyCodes.X);
modifierSelectUiHandler.processInput(Button.CANCEL);
}
});
});

View File

@ -15,6 +15,19 @@ import { BattlePhase } from './battle-phase';
const enableAuto = true;
export enum Button {
UP,
DOWN,
LEFT,
RIGHT,
ACTION,
CANCEL,
RANDOM,
AUTO,
SPEED_UP,
SLOW_DOWN
}
export default class BattleScene extends Phaser.Scene {
public auto: boolean;
public autoSpeed: integer = 1;
@ -45,15 +58,7 @@ export default class BattleScene extends Phaser.Scene {
private bgm: Phaser.Sound.BaseSound;
private upKey: Phaser.Input.Keyboard.Key;
private downKey: Phaser.Input.Keyboard.Key;
private leftKey: Phaser.Input.Keyboard.Key;
private rightKey: Phaser.Input.Keyboard.Key;
private actionKey: Phaser.Input.Keyboard.Key;
private cancelKey: Phaser.Input.Keyboard.Key;
private f2Key: Phaser.Input.Keyboard.Key;
private plusKey: Phaser.Input.Keyboard.Key;
private minusKey: Phaser.Input.Keyboard.Key;
private buttonKeys: Phaser.Input.Keyboard.Key[][];
private blockInput: boolean;
@ -214,10 +219,20 @@ export default class BattleScene extends Phaser.Scene {
}
create() {
this.setupControls();
this.load.setBaseURL();
//this.spritePipeline = (this.renderer as Phaser.Renderer.WebGL.WebGLRenderer).pipelines.get('Sprite') as SpritePipeline;
this.time.delayedCall(20, () => this.launchBattle());
}
update() {
this.checkInput();
}
launchBattle() {
const field = this.add.container(0, 0);
field.setScale(6);
@ -264,8 +279,10 @@ export default class BattleScene extends Phaser.Scene {
let loadPokemonAssets = [];
const isRandom = this.isButtonPressed(Button.RANDOM); // For testing purposes
for (let s = 0; s < 3; s++) {
const playerSpecies = getPokemonSpecies(s === 0 ? Species.TORCHIC : s === 1 ? Species.TREECKO : Species.MUDKIP); //this.randomSpecies();
const playerSpecies = !isRandom ? getPokemonSpecies(s === 0 ? Species.TORCHIC : s === 1 ? Species.TREECKO : Species.MUDKIP) : this.randomSpecies(5);
const playerPokemon = new PlayerPokemon(this, playerSpecies, 5);
playerPokemon.setVisible(false);
loadPokemonAssets.push(playerPokemon.loadAssets());
@ -304,16 +321,6 @@ export default class BattleScene extends Phaser.Scene {
ui.setup();
this.upKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP);
this.downKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.DOWN);
this.leftKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT);
this.rightKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT);
this.actionKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Z);
this.cancelKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.X);
this.f2Key = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.F2);
this.plusKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.PLUS);
this.minusKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.MINUS);
Promise.all(loadPokemonAssets).then(() => {
if (enableAuto)
initAutoPlay.apply(this);
@ -326,8 +333,29 @@ export default class BattleScene extends Phaser.Scene {
});
}
update() {
this.checkInput();
setupControls() {
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
const keyConfig = {
[Button.UP]: [keyCodes.UP, keyCodes.W],
[Button.DOWN]: [keyCodes.DOWN, keyCodes.S],
[Button.LEFT]: [keyCodes.LEFT, keyCodes.A],
[Button.RIGHT]: [keyCodes.RIGHT, keyCodes.D],
[Button.ACTION]: [keyCodes.ENTER, keyCodes.SPACE, keyCodes.Z],
[Button.CANCEL]: [keyCodes.BACKSPACE, keyCodes.ESC, keyCodes.X],
[Button.RANDOM]: [keyCodes.R],
[Button.AUTO]: [keyCodes.F2],
[Button.SPEED_UP]: [keyCodes.PLUS],
[Button.SLOW_DOWN]: [keyCodes.MINUS]
};
this.buttonKeys = [];
for (let b of Utils.getEnumValues(Button)) {
const keys: Phaser.Input.Keyboard.Key[] = [];
if (keyConfig.hasOwnProperty(b)) {
for (let k of keyConfig[b])
keys.push(this.input.keyboard.addKey(k));
}
this.buttonKeys[b] = keys;
}
}
getParty(): PlayerPokemon[] {
@ -372,31 +400,31 @@ export default class BattleScene extends Phaser.Scene {
randomSpecies(level: integer, fromArenaPool?: boolean): PokemonSpecies {
return fromArenaPool
? this.arena.randomSpecies(1, level)
: allSpecies[(Utils.randInt(allSpecies.length)) - 1];
: getPokemonSpecies(allSpecies[(Utils.randInt(allSpecies.length)) - 1].getSpeciesForLevel(level));
}
checkInput(): boolean {
if (this.blockInput)
return;
if (this.upKey.isDown)
this.ui.processInput(this.upKey.keyCode);
else if (this.downKey.isDown)
this.ui.processInput(this.downKey.keyCode);
else if (this.leftKey.isDown)
this.ui.processInput(this.leftKey.keyCode);
else if (this.rightKey.isDown)
this.ui.processInput(this.rightKey.keyCode);
else if (this.actionKey.isDown)
this.ui.processInput(this.actionKey.keyCode);
else if (this.cancelKey.isDown)
this.ui.processInput(this.cancelKey.keyCode);
if (this.isButtonPressed(Button.UP))
this.ui.processInput(Button.UP);
else if (this.isButtonPressed(Button.DOWN))
this.ui.processInput(Button.DOWN);
else if (this.isButtonPressed(Button.LEFT))
this.ui.processInput(Button.LEFT);
else if (this.isButtonPressed(Button.RIGHT))
this.ui.processInput(Button.RIGHT);
else if (this.isButtonPressed(Button.ACTION))
this.ui.processInput(Button.ACTION);
else if (this.isButtonPressed(Button.CANCEL))
this.ui.processInput(Button.CANCEL);
else if (enableAuto) {
if (this.f2Key.isDown)
if (this.isButtonPressed(Button.AUTO))
this.auto = !this.auto;
else if (this.plusKey.isDown) {
else if (this.isButtonPressed(Button.SPEED_UP)) {
if (this.autoSpeed < 20)
this.autoSpeed++;
} else if (this.minusKey.isDown) {
} else if (this.isButtonPressed(Button.SLOW_DOWN)) {
if (this.autoSpeed > 1)
this.autoSpeed--;
}
@ -409,6 +437,10 @@ export default class BattleScene extends Phaser.Scene {
});
}
isButtonPressed(button: Button): boolean {
return this.buttonKeys[button].filter(k => k.isDown).length >= 1;
}
playBgm(bgmName?: string): void {
if (!bgmName && this.bgm) {
this.bgm.play({
@ -419,7 +451,7 @@ export default class BattleScene extends Phaser.Scene {
if (this.bgm && this.bgm.isPlaying)
this.bgm.stop();
this.bgm = this.sound.add(bgmName, { loop: true });
//this.bgm.play();
this.bgm.play();
}
pauseBgm(): void {

View File

@ -1,5 +1,5 @@
import { CommandPhase } from "../battle-phase";
import BattleScene from "../battle-scene";
import { CommandPhase } from "../battle-phases";
import BattleScene, { Button } from "../battle-scene";
import { getPokeballName, PokeballType } from "../pokeball";
import { addTextObject, TextStyle } from "../text";
import { Command } from "./command-ui-handler";
@ -55,17 +55,16 @@ export default class BallUiHandler extends UiHandler {
this.setCursor(this.cursor);
}
processInput(keyCode: integer) {
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
processInput(button: Button) {
const ui = this.getUi();
let success = false;
const pokeballTypeCount = Object.keys(this.scene.pokeballCounts).length;
if (keyCode === keyCodes.Z || keyCode === keyCodes.X) {
if (button === Button.ACTION || button === Button.CANCEL) {
success = true;
if (keyCode === keyCodes.Z && this.cursor < pokeballTypeCount) {
if (button === Button.ACTION && this.cursor < pokeballTypeCount) {
if (this.scene.pokeballCounts[this.cursor]) {
(this.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.BALL, this.cursor);
this.scene.ui.setMode(Mode.COMMAND);
@ -78,11 +77,11 @@ export default class BallUiHandler extends UiHandler {
success = true;
}
} else {
switch (keyCode) {
case keyCodes.UP:
switch (button) {
case Button.UP:
success = this.setCursor(this.cursor ? this.cursor - 1 : pokeballTypeCount);
break;
case keyCodes.DOWN:
case Button.DOWN:
success = this.setCursor(this.cursor < pokeballTypeCount ? this.cursor + 1 : 0);
break;
}

View File

@ -1,4 +1,4 @@
import BattleScene from "../battle-scene";
import BattleScene, { Button } from "../battle-scene";
import { addTextObject, TextStyle } from "../text";
import UI, { Mode } from "./ui";
import * as Utils from "../utils";
@ -87,11 +87,10 @@ export default class BattleMessageUiHandler extends MessageUiHandler {
this.message.setWordWrapWidth(1780);
}
processInput(keyCode: integer) {
processInput(button: Button) {
const ui = this.getUi();
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
if (this.awaitingActionInput) {
if (keyCode === keyCodes.X || keyCode === keyCodes.Z) {
if (button === Button.CANCEL || button === Button.ACTION) {
if (this.onActionInput) {
ui.playSelect();
const originalOnActionInput = this.onActionInput;

View File

@ -1,4 +1,4 @@
import BattleScene from "../battle-scene";
import BattleScene, { Button } from "../battle-scene";
import { addTextObject, TextStyle } from "../text";
import { toPokemonUpperCase } from "../utils";
import { PartyUiMode } from "./party-ui-handler";
@ -46,15 +46,14 @@ export default class CommandUiHandler extends UiHandler {
this.setCursor(this.cursor);
}
processInput(keyCode: integer) {
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
processInput(button: Button) {
const ui = this.getUi();
let success = false;
if (keyCode === keyCodes.X || keyCode === keyCodes.Z) {
if (button === Button.CANCEL || button === Button.ACTION) {
if (keyCode === keyCodes.Z) {
if (button === Button.ACTION) {
switch (this.cursor) {
case 0:
ui.setMode(Mode.FIGHT);
@ -71,20 +70,20 @@ export default class CommandUiHandler extends UiHandler {
}
}
} else {
switch (keyCode) {
case keyCodes.UP:
switch (button) {
case Button.UP:
if (this.cursor >= 2)
success = this.setCursor(this.cursor - 2);
break;
case keyCodes.DOWN:
case Button.DOWN:
if (this.cursor < 2)
success = this.setCursor(this.cursor + 2);
break;
case keyCodes.LEFT:
case Button.LEFT:
if (this.cursor % 2 === 1)
success = this.setCursor(this.cursor - 1);
break;
case keyCodes.RIGHT:
case Button.RIGHT:
if (this.cursor % 2 === 0)
success = this.setCursor(this.cursor + 1);
break;

View File

@ -1,4 +1,4 @@
import BattleScene from "../battle-scene";
import BattleScene, { Button } from "../battle-scene";
import { addTextObject, TextStyle } from "../text";
import { Mode } from "./ui";
import UiHandler from "./uiHandler";
@ -51,27 +51,26 @@ export default class ConfirmUiHandler extends UiHandler {
}
}
processInput(keyCode: integer) {
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
processInput(button: Button) {
const ui = this.getUi();
let success = false;
if (keyCode === keyCodes.Z || keyCode === keyCodes.X) {
if (button === Button.ACTION || button === Button.CANCEL) {
success = true;
if (keyCode === keyCodes.X)
if (button === Button.CANCEL)
this.setCursor(1);
const handler = this.cursor ? this.noHander : this.yesHandler;
handler();
console.log(this.cursor ? this.noHander : this.yesHandler);
this.clear();
} else {
switch (keyCode) {
case keyCodes.UP:
switch (button) {
case Button.UP:
if (this.cursor)
success = this.setCursor(0);
break;
case keyCodes.DOWN:
case Button.DOWN:
if (!this.cursor)
success = this.setCursor(1);
break;

View File

@ -1,4 +1,4 @@
import BattleScene from "../battle-scene";
import BattleScene, { Button } from "../battle-scene";
import { Mode } from "./ui";
import UiHandler from "./uiHandler";
@ -14,8 +14,8 @@ export default class EvolutionSceneHandler extends UiHandler {
this.scene.fieldUI.add(this.evolutionContainer);
}
processInput(keyCode: integer) {
this.scene.ui.getMessageHandler().processInput(keyCode);
processInput(button: Button) {
this.scene.ui.getMessageHandler().processInput(button);
}
setCursor(_cursor: integer): boolean {

View File

@ -1,4 +1,4 @@
import BattleScene from "../battle-scene";
import BattleScene, { Button } from "../battle-scene";
import { addTextObject, TextStyle } from "../text";
import { Type } from "../type";
import { Command } from "./command-ui-handler";
@ -42,14 +42,13 @@ export default class FightUiHandler extends UiHandler {
this.displayMoves();
}
processInput(keyCode: integer) {
processInput(button: Button) {
const ui = this.getUi();
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
let success = false;
if (keyCode === keyCodes.X || keyCode === keyCodes.Z) {
if (keyCode === keyCodes.Z) {
if (button === Button.CANCEL || button === Button.ACTION) {
if (button === Button.ACTION) {
if (((this.scene as BattleScene).getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, this.cursor))
success = true;
} else {
@ -57,20 +56,20 @@ export default class FightUiHandler extends UiHandler {
success = true;
}
} else {
switch (keyCode) {
case keyCodes.UP:
switch (button) {
case Button.UP:
if (this.cursor >= 2)
success = this.setCursor(this.cursor - 2);
break;
case keyCodes.DOWN:
case Button.DOWN:
if (this.cursor < 2)
success = this.setCursor(this.cursor + 2);
break;
case keyCodes.LEFT:
case Button.LEFT:
if (this.cursor % 2 === 1)
success = this.setCursor(this.cursor - 1);
break;
case keyCodes.RIGHT:
case Button.RIGHT:
if (this.cursor % 2 === 0)
success = this.setCursor(this.cursor + 1);
break;

View File

@ -1,4 +1,4 @@
import BattleScene from "../battle-scene";
import BattleScene, { Button } from "../battle-scene";
import { ModifierTier, ModifierType } from "../modifier";
import { getPokeballAtlasKey, PokeballType } from "../pokeball";
import { addTextObject, TextStyle } from "../text";
@ -87,8 +87,7 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
});
}
processInput(keyCode: integer) {
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
processInput(button: Button) {
const ui = this.getUi();
if (!this.awaitingActionInput)
@ -96,7 +95,7 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
let success = false;
if (keyCode === keyCodes.Z) {
if (button === Button.ACTION) {
success = true;
if (this.onActionInput) {
const originalOnActionInput = this.onActionInput;
@ -104,7 +103,7 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
this.onActionInput = null;
originalOnActionInput(this.cursor);
}
} else if (keyCode === keyCodes.X) {
} else if (button === Button.CANCEL) {
success = true;
if (this.onActionInput) {
const originalOnActionInput = this.onActionInput;
@ -113,12 +112,12 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
originalOnActionInput(-1);
}
} else {
switch (keyCode) {
case keyCodes.LEFT:
switch (button) {
case Button.LEFT:
if (this.cursor)
success = this.setCursor(this.cursor - 1);
break;
case keyCodes.RIGHT:
case Button.RIGHT:
if (this.cursor < this.options.length - 1)
success = this.setCursor(this.cursor + 1);
break;

View File

@ -1,5 +1,5 @@
import { CommandPhase } from "../battle-phases";
import BattleScene from "../battle-scene";
import BattleScene, { Button } from "../battle-scene";
import { PlayerPokemon } from "../pokemon";
import { addTextObject, TextStyle } from "../text";
import { Command } from "./command-ui-handler";
@ -123,15 +123,14 @@ export default class PartyUiHandler extends MessageUiHandler {
: PartyUiHandler.FilterAll;
}
processInput(keyCode: integer) {
processInput(button: Button) {
const ui = this.getUi();
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
if (this.pendingPrompt)
return;
if (this.awaitingActionInput) {
if (keyCode === keyCodes.Z || keyCode === keyCodes.X) {
if (button === Button.ACTION || button === Button.CANCEL) {
if (this.onActionInput) {
ui.playSelect();
const originalOnActionInput = this.onActionInput;
@ -146,7 +145,7 @@ export default class PartyUiHandler extends MessageUiHandler {
let success = false;
if (this.optionsMode) {
if (keyCode === keyCodes.Z) {
if (button === Button.ACTION) {
const option = this.options[this.optionsCursor];
if (option === PartyOption.SHIFT || option === PartyOption.SEND_OUT || option === PartyOption.APPLY) {
let filterResult: string = this.selectFilter(this.scene.getParty()[this.cursor]);
@ -175,32 +174,32 @@ export default class PartyUiHandler extends MessageUiHandler {
ui.playSelect();
ui.setModeWithoutClear(Mode.SUMMARY, this.scene.getParty()[this.cursor]).then(() => this.clearOptions());
} else if (option === PartyOption.CANCEL)
this.processInput(keyCodes.X);
} else if (keyCode === keyCodes.X) {
this.processInput(Button.CANCEL);
} else if (button === Button.CANCEL) {
this.clearOptions();
ui.playSelect();
}
else {
switch (keyCode) {
case keyCodes.UP:
switch (button) {
case Button.UP:
success = this.setCursor(this.optionsCursor ? this.optionsCursor - 1 : this.options.length - 1);
break;
case keyCodes.DOWN:
case Button.DOWN:
success = this.setCursor(this.optionsCursor < this.options.length - 1 ? this.optionsCursor + 1 : 0);
break;
}
}
} else {
if (keyCode === keyCodes.Z) {
if (button === Button.ACTION) {
if (this.cursor < 6) {
this.showOptions();
ui.playSelect();
} else if (this.partyUiMode === PartyUiMode.FAINT_SWITCH)
ui.playError();
else
this.processInput(keyCodes.X);
this.processInput(Button.CANCEL);
return;
} else if (keyCode === keyCodes.X) {
} else if (button === Button.CANCEL) {
if (this.partyUiMode !== PartyUiMode.FAINT_SWITCH) {
if (this.selectCallback) {
const selectCallback = this.selectCallback;
@ -217,18 +216,18 @@ export default class PartyUiHandler extends MessageUiHandler {
const slotCount = this.partySlots.length;
switch (keyCode) {
case keyCodes.UP:
switch (button) {
case Button.UP:
success = this.setCursor(this.cursor ? this.cursor < 6 ? this.cursor - 1 : slotCount - 1 : 6);
break;
case keyCodes.DOWN:
case Button.DOWN:
success = this.setCursor(this.cursor < 6 ? this.cursor < slotCount - 1 ? this.cursor + 1 : 6 : 0);
break;
case keyCodes.LEFT:
case Button.LEFT:
if (this.cursor && this.cursor < 6)
success = this.setCursor(0);
break;
case keyCodes.RIGHT:
case Button.RIGHT:
if (!this.cursor)
success = this.setCursor(this.lastCursor < 6 ? this.lastCursor || 1 : 1);
break;

View File

@ -1,4 +1,4 @@
import BattleScene from "../battle-scene";
import BattleScene, { Button } from "../battle-scene";
import { allSpecies } from "../pokemon-species";
import { Mode } from "./ui";
import UiHandler from "./uiHandler";
@ -41,14 +41,13 @@ export default class StarterSelectUiHandler extends UiHandler {
this.setCursor(0);
}
processInput(keyCode: integer) {
processInput(button: Button) {
const ui = this.getUi();
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
let success = false;
if (keyCode === keyCodes.Z) {
} else if (keyCode === keyCodes.X) {
if (button === Button.ACTION) {
} else if (button === Button.CANCEL) {
} else {
}

View File

@ -1,4 +1,4 @@
import BattleScene from "../battle-scene";
import BattleScene, { Button } from "../battle-scene";
import { Mode } from "./ui";
import UiHandler from "./uiHandler";
import * as Utils from "../utils";
@ -170,17 +170,16 @@ export default class SummaryUiHandler extends UiHandler {
}
}
processInput(keyCode: integer) {
processInput(button: Button) {
if (this.transitioning)
return;
const ui = this.getUi();
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
let success = false;
if (this.moveSelect) {
if (keyCode === keyCodes.Z) {
if (button === Button.ACTION) {
if (this.moveCursor < this.pokemon.moveset.length) {
if (this.summaryUiMode === SummaryUiMode.LEARN_MOVE)
this.moveSelectFunction(this.moveCursor);
@ -213,37 +212,37 @@ export default class SummaryUiHandler extends UiHandler {
}
success = true;
} else if (this.moveCursor === 4)
this.processInput(keyCodes.X);
this.processInput(Button.CANCEL);
else
ui.playError();
} else if (keyCode === keyCodes.X) {
} else if (button === Button.CANCEL) {
this.hideMoveSelect();
success = true;
} else {
switch (keyCode) {
case keyCodes.UP:
switch (button) {
case Button.UP:
success = this.setCursor(this.moveCursor ? this.moveCursor - 1 : 4);
break;
case keyCodes.DOWN:
case Button.DOWN:
success = this.setCursor(this.moveCursor < 4 ? this.moveCursor + 1 : 0);
break;
}
}
} else {
if (keyCode === keyCodes.Z) {
if (button === Button.ACTION) {
if (this.cursor === Page.MOVES) {
this.showMoveSelect();
success = true;
}
} else if (keyCode === keyCodes.X) {
} else if (button === Button.CANCEL) {
ui.setMode(Mode.PARTY);
success = true;
} else {
const pages = Utils.getEnumValues(Page);
switch (keyCode) {
case keyCodes.UP:
case keyCodes.DOWN:
const isDown = keyCode === keyCodes.DOWN;
switch (button) {
case Button.UP:
case Button.DOWN:
const isDown = button === Button.DOWN;
const party = this.scene.getParty();
const partyMemberIndex = party.indexOf(this.pokemon);
if ((isDown && partyMemberIndex < party.length - 1) || (!isDown && partyMemberIndex)) {
@ -252,11 +251,11 @@ export default class SummaryUiHandler extends UiHandler {
this.show([ party[partyMemberIndex + (isDown ? 1 : -1)], this.summaryUiMode, page ]);
}
break;
case keyCodes.LEFT:
case Button.LEFT:
if (this.cursor)
success = this.setCursor(this.cursor - 1);
break;
case keyCodes.RIGHT:
case Button.RIGHT:
if (this.cursor < pages.length - 1)
success = this.setCursor(this.cursor + 1);
break;

View File

@ -1,4 +1,4 @@
import { default as BattleScene } from '../battle-scene';
import { Button, default as BattleScene } from '../battle-scene';
import UiHandler from './uiHandler';
import BattleMessageUiHandler from './battle-message-ui-handler';
import CommandUiHandler from './command-ui-handler';
@ -79,11 +79,11 @@ export default class UI extends Phaser.GameObjects.Container {
return this.handlers[Mode.MESSAGE] as BattleMessageUiHandler;
}
processInput(keyCode: integer): void {
processInput(button: Button): void {
if (this.transitioning)
return;
this.getHandler().processInput(keyCode);
this.getHandler().processInput(button);
}
showText(text: string, delay?: integer, callback?: Function, callbackDelay?: integer, prompt?: boolean, promptDelay?: integer): void {

View File

@ -1,4 +1,4 @@
import BattleScene from "../battle-scene";
import BattleScene, { Button } from "../battle-scene";
import UI, { Mode } from "./ui";
export default abstract class UiHandler {
@ -18,7 +18,7 @@ export default abstract class UiHandler {
this.active = true;
}
abstract processInput(keyCode: integer);
abstract processInput(button: Button);
getUi() {
return this.scene.ui;