Drop BattleLog dependency from headless Battles

Mostly, this involves removing `BattleLog.escapeHTML` from `battle.ts`.
All previous use-cases have been replaced with something like
`Tools.sanitizeName`.

Technically, the dependency remains for `|controlshtml|` and
`|fieldhtml|`, but these will be dropped for BattleRoom/GameRoom
separation, to be done in the Preact rewrite.
This commit is contained in:
Guangcong Luo 2018-11-14 22:04:49 -06:00
parent bec475e602
commit 2721c0b8a0
4 changed files with 16 additions and 11 deletions

View File

@ -1200,6 +1200,12 @@ class BattleScene {
}
}
typeAnim(pokemon: Pokemon, types: string) {
const result = BattleLog.escapeHTML(types).split('/').map(type =>
'<img src="' + Tools.resourcePrefix + 'sprites/types/' + type + '.png" alt="' + type + '" />'
).join(' ');
this.resultAnim(pokemon, types, 'neutral');
}
resultAnim(pokemon: Pokemon, result: string, type: 'bad' | 'good' | 'neutral' | StatusName) {
if (!this.animating) return;
let $effect = $('<div class="result ' + type + 'result"><strong>' + result + '</strong></div>');

View File

@ -28,6 +28,7 @@ class BattleSceneStub {
removeSideCondition(siden: number, id: ID): void { }
reset(): void { }
resultAnim(pokemon: Pokemon, result: string, type: "bad" | "good" | "neutral" | "par" | "psn" | "frz" | "slp" | "brn"): void { }
typeAnim(pokemon: Pokemon, types: string): void { }
resume(): void { }
runMoveAnim(moveid: ID, participants: Pokemon[]): void { }
runOtherAnim(moveid: ID, participants: Pokemon[]): void { }

View File

@ -2086,22 +2086,20 @@ class Battle {
this.activateAbility(ofpoke || poke, fromeffect);
switch (effect.id) {
case 'typechange':
const types = BattleLog.escapeHTML(args[3]);
const types = Tools.sanitizeName(args[3]);
poke.removeVolatile('typeadd' as ID);
poke.addVolatile('typechange' as ID, types);
if (kwArgs.silent) {
this.scene.updateStatbar(poke);
break;
}
this.scene.resultAnim(poke, types.split('/').map(function (type) {
return '<img src="' + Tools.resourcePrefix + 'sprites/types/' + type + '.png" alt="' + type + '" />';
}).join(' '), 'neutral');
this.scene.typeAnim(poke, types);
break;
case 'typeadd':
const type = BattleLog.escapeHTML(args[3]);
const type = Tools.sanitizeName(args[3]);
poke.addVolatile('typeadd' as ID, type);
if (kwArgs.silent) break;
this.scene.resultAnim(poke, '<img src="' + Tools.resourcePrefix + 'sprites/types/' + type + '.png" alt="' + type + '" />', 'neutral');
this.scene.typeAnim(poke, type);
break;
case 'powertrick':
this.scene.resultAnim(poke, 'Power Trick', 'neutral');
@ -2444,8 +2442,9 @@ class Battle {
break;
case 'spite':
let move = Tools.getMove(args[3]).name;
let pp = BattleLog.escapeHTML(args[4]);
poke.rememberMove(move, Number(pp));
let pp = Number(args[4]);
if (isNaN(pp)) pp = 4;
poke.rememberMove(move, pp);
break;
case 'gravity':
poke.removeVolatile('magnetrise' as ID);
@ -2454,8 +2453,8 @@ class Battle {
break;
case 'skillswap':
if (this.gen <= 4) break;
let pokeability = BattleLog.escapeHTML(args[3]) || ofpoke!.ability;
let ofpokeability = BattleLog.escapeHTML(args[4]) || poke.ability;
let pokeability = Tools.sanitizeName(args[3]) || ofpoke!.ability;
let ofpokeability = Tools.sanitizeName(args[4]) || poke.ability;
if (pokeability) {
poke.ability = pokeability;
if (!ofpoke!.baseAbility) ofpoke!.baseAbility = pokeability;

View File

@ -8,7 +8,6 @@ window = global;
// Without making these modules, the best we can do is directly include them into this workspace.
eval('' + fs.readFileSync(`js/battle-scene-stub.js`));
eval('' + fs.readFileSync(`js/battle-log.js`));
eval('' + fs.readFileSync(`js/battle-dex.js`));
eval('' + fs.readFileSync(`js/battle-dex-data.js`));
eval('' + fs.readFileSync(`js/battle.js`));