[Beta][QoL] Improved cursor memory for target selection in Doubles (#4849)

* Added more intelligent cursor memory for target selection in Doubles

* Added documentation

* Fixed variable name.

* Apply suggestions from code review

Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com>

---------

Co-authored-by: frutescens <info@laptop>
Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com>
This commit is contained in:
Mumble 2024-11-15 09:45:21 -08:00 committed by GitHub
parent eb3c0d731a
commit c535e928d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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[];
@ -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;
@ -53,11 +56,29 @@ 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 based on the previous turn's target or the user's status
* @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) {
// Reset cursor on the first turn of a fight or if an ally was targeted last turn
cursorN = -1;
}
}
this.setCursor(this.targets.includes(cursorN) ? cursorN : this.targets[0]);
}
processInput(button: Button): boolean {
const ui = this.getUi();
@ -67,6 +88,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 {
@ -152,7 +182,6 @@ export default class TargetSelectUiHandler extends UiHandler {
yoyo: true
}));
});
return ret;
}
@ -184,7 +213,6 @@ export default class TargetSelectUiHandler extends UiHandler {
}
clear() {
this.cursor = -1;
super.clear();
this.eraseCursor();
}