Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Beta][Misc] Improved cursor memory for target selection in Doubles #4849

Merged
merged 5 commits into from
Nov 15, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions src/ui/target-select-ui-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import { SubstituteTag } from "#app/data/battler-tags";
export type TargetSelectCallback = (targets: BattlerIndex[]) => void;

export default class TargetSelectUiHandler extends UiHandler {
private fieldIndex: integer;
private fieldIndex: number;
private move: Moves;
private targetSelectCallback: TargetSelectCallback;
private cursor0: number; // associated with BattlerIndex.PLAYER
private cursor1: number; // associated with BattlerIndex.PLAYER_2

private isMultipleTargets: boolean = false;
private targets: BattlerIndex[];
Expand All @@ -42,8 +44,9 @@ export default class TargetSelectUiHandler extends UiHandler {
this.fieldIndex = args[0] as integer;
this.move = args[1] as Moves;
this.targetSelectCallback = args[2] as TargetSelectCallback;
const user = this.scene.getPlayerField()[this.fieldIndex];

const moveTargets = getMoveTargets(this.scene.getPlayerField()[this.fieldIndex], this.move);
const moveTargets = getMoveTargets(user, this.move);
this.targets = moveTargets.targets;
this.isMultipleTargets = moveTargets.multiple ?? false;

Expand All @@ -53,11 +56,30 @@ export default class TargetSelectUiHandler extends UiHandler {

this.enemyModifiers = this.scene.getModifierBar(true);

this.setCursor(this.targets.includes(this.cursor) ? this.cursor : this.targets[0]);

if (this.fieldIndex === BattlerIndex.PLAYER) {
this.resetCursor(this.cursor0, user);
} else if (this.fieldIndex === BattlerIndex.PLAYER_2) {
this.resetCursor(this.cursor1, user);
}
return true;
}

/**
* Determines what value to assign the main cursor on previous history or the user's status
frutescens marked this conversation as resolved.
Show resolved Hide resolved
* @param cursorN the cursor associated with the user's field index
* @param user the Pokemon using the move
*/
resetCursor(cursorN: number, user: Pokemon): void {
if (!Utils.isNullOrUndefined(cursorN)) {
if ([ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2 ].includes(cursorN) || user.battleSummonData.waveTurnCount === 1) {
this.cursor = cursorN = -1;
} else if (user.battleSummonData.waveTurnCount > 1) {
this.cursor = cursorN;
}
frutescens marked this conversation as resolved.
Show resolved Hide resolved
}
this.setCursor(this.targets.includes(cursorN) ? cursorN : this.targets[0]);
}

processInput(button: Button): boolean {
const ui = this.getUi();

Expand All @@ -67,6 +89,15 @@ export default class TargetSelectUiHandler extends UiHandler {
const targetIndexes: BattlerIndex[] = this.isMultipleTargets ? this.targets : [ this.cursor ];
this.targetSelectCallback(button === Button.ACTION ? targetIndexes : []);
success = true;
if (this.fieldIndex === BattlerIndex.PLAYER) {
if (Utils.isNullOrUndefined(this.cursor0) || this.cursor0 !== this.cursor) {
this.cursor0 = this.cursor;
}
} else if (this.fieldIndex === BattlerIndex.PLAYER_2) {
if (Utils.isNullOrUndefined(this.cursor1) || this.cursor1 !== this.cursor) {
this.cursor1 = this.cursor;
}
}
} else if (this.isMultipleTargets) {
success = false;
} else {
Expand Down Expand Up @@ -152,7 +183,6 @@ export default class TargetSelectUiHandler extends UiHandler {
yoyo: true
}));
});

return ret;
}

Expand Down Expand Up @@ -184,7 +214,6 @@ export default class TargetSelectUiHandler extends UiHandler {
}

clear() {
this.cursor = -1;
super.clear();
this.eraseCursor();
}
Expand Down
Loading