Skip to content

Commit

Permalink
Finally remove deprecated legacy API
Browse files Browse the repository at this point in the history
It's gone! The last remnants of the old choice parsing system is
finally gone!
  • Loading branch information
Zarel committed Feb 20, 2019
1 parent 34f90a9 commit fa602b8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 38 deletions.
8 changes: 0 additions & 8 deletions sim/battle.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ class Battle extends Dex.ModdedDex {
this.abilityOrder = 0;
/** @type {''} */
this.NOT_FAILURE = '';
/** @type {boolean} */
this.LEGACY_API_DO_NOT_USE = false;

/** @type {PRNG} */
this.prng = options.prng || new PRNG(options.seed || undefined);
Expand Down Expand Up @@ -3183,26 +3181,20 @@ class Battle extends Dex.ModdedDex {
* @param {string[]} inputs
*/
makeChoices(...inputs) {
const oldFlag = this.LEGACY_API_DO_NOT_USE;
this.LEGACY_API_DO_NOT_USE = false;
for (const [i, input] of inputs.entries()) {
this.sides[i].choose(input);
}
this.commitDecisions();
this.LEGACY_API_DO_NOT_USE = oldFlag;
}

commitDecisions() {
this.updateSpeed();

let oldQueue = this.queue;
this.queue = [];
let oldFlag = this.LEGACY_API_DO_NOT_USE;
this.LEGACY_API_DO_NOT_USE = false;
for (const side of this.sides) {
side.autoChoose();
}
this.LEGACY_API_DO_NOT_USE = oldFlag;
let p1choice = this.p1.getChoice();
if (p1choice) this.inputLog.push(`>p1 ${p1choice}`);
let p2choice = this.p2.getChoice();
Expand Down
23 changes: 0 additions & 23 deletions sim/side.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ class Side {
if (ultra) this.choice.ultra = true;
if (zMove) this.choice.zMove = true;

if (this.battle.LEGACY_API_DO_NOT_USE && !this.battle.checkActions()) return this;
return true;
}

Expand Down Expand Up @@ -548,7 +547,6 @@ class Side {
target: targetPokemon,
});

if (this.battle.LEGACY_API_DO_NOT_USE && !this.battle.checkActions()) return this;
return true;
}

Expand Down Expand Up @@ -602,7 +600,6 @@ class Side {
});
}

if (this.battle.LEGACY_API_DO_NOT_USE && !this.battle.checkActions()) return this;
return true;
}

Expand All @@ -628,7 +625,6 @@ class Side {
pokemon: pokemon,
});

if (this.battle.LEGACY_API_DO_NOT_USE && !this.battle.checkActions()) return this;
return true;
}

Expand Down Expand Up @@ -787,28 +783,9 @@ class Side {
this.choice.actions.push({
choice: 'pass',
});
if (this.battle.LEGACY_API_DO_NOT_USE && !this.battle.checkActions()) return this;
return true;
}

/**
* @return {boolean | Side}
*/
chooseDefault() {
if (!this.battle.LEGACY_API_DO_NOT_USE) throw new Error(`This is a legacy API, it's called autoChoose now`);
if (this.isChoiceDone()) {
throw new Error(`You've already chosen actions for ${this.id}.`);
}
if (this.currentRequest === 'teampreview') {
this.chooseTeam();
} else if (this.currentRequest === 'switch') {
while (this.chooseSwitch() !== true && !this.isChoiceDone());
} else if (this.currentRequest === 'move') {
while (this.chooseMove() !== true && !this.isChoiceDone());
}
return this;
}

/**
* Automatically finish a choice if not currently complete
*/
Expand Down
1 change: 0 additions & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ class TestTools {
// will be used.
seed: options.seed || DEFAULT_SEED,
});
battle.LEGACY_API_DO_NOT_USE = true;
if (teams) {
for (let i = 0; i < teams.length; i++) {
assert(Array.isArray(teams[i]), "Team provided is not an array");
Expand Down
14 changes: 8 additions & 6 deletions test/simulator/misc/decisions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1164,17 +1164,19 @@ describe('Choice internals', function () {
]);

assert.strictEqual(battle.turn, 1);
p1.chooseMove(1).chooseSwitch(4);
assert(!p2.chooseSwitch(3));
p2.chooseMove(1).chooseMove(1);
p1.choose('move recover, switch 4');
assert(!p2.choose('switch 3'));
p2.choose('move recover, move recover');
battle.checkActions();

assert.strictEqual(battle.turn, 2);
assert.strictEqual(p1.active[0].name, 'Mew');
assert.strictEqual(p1.active[1].name, 'Ekans');

p1.chooseSwitch(4).chooseMove(1);
assert(!p2.chooseSwitch(3));
p2.chooseMove(1).chooseMove(1);
p1.choose('switch 4, move leer');
assert(!p2.choose('switch 3'));
p2.choose('move recover, move recover');
battle.checkActions();

assert.strictEqual(battle.turn, 3);
assert.strictEqual(p1.active[0].name, 'Bulbasaur');
Expand Down

0 comments on commit fa602b8

Please sign in to comment.