From e489b36856445b0555d434a0c9db0e9050fc46ad Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Mon, 7 Jan 2019 21:45:58 -0600 Subject: [PATCH] Fix Confusion message grouping --- src/battle-text-parser.ts | 14 +++++++++++--- test/battle-test.test.js | 17 +++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/battle-text-parser.ts b/src/battle-text-parser.ts index 466e4dfe6..f05b29f92 100644 --- a/src/battle-text-parser.ts +++ b/src/battle-text-parser.ts @@ -110,9 +110,13 @@ class BattleTextParser { return {args, kwArgs}; } - extractMessage(line: string) { - const {args, kwArgs} = BattleTextParser.parseLine(line); - return this.parseArgs(args, kwArgs) || ''; + extractMessage(buf: string) { + let out = ''; + for (const line of buf.split('\n')) { + const {args, kwArgs} = BattleTextParser.parseLine(line); + out += this.parseArgs(args, kwArgs) || ''; + } + return out; } fixLowercase(input: string) { @@ -267,18 +271,22 @@ class BattleTextParser { case '-damage': { const id = BattleTextParser.effectId(kwArgs.from); if (id === 'confusion') return 'major'; + return 'postMajor'; } case '-curestatus': { const id = BattleTextParser.effectId(kwArgs.from); if (id === 'naturalcure') return 'preMajor'; + return 'postMajor'; } case '-start': { const id = BattleTextParser.effectId(kwArgs.from); if (id === 'protean') return 'preMajor'; + return 'postMajor'; } case '-activate': { const id = BattleTextParser.effectId(args[2]); if (id === 'confusion' || id === 'attract') return 'preMajor'; + return 'postMajor'; } } return (cmd.charAt(0) === '-' ? 'postMajor' : ''); diff --git a/test/battle-test.test.js b/test/battle-test.test.js index 8d8cdab0e..48724169e 100644 --- a/test/battle-test.test.js +++ b/test/battle-test.test.js @@ -99,13 +99,26 @@ describe('Text parser', () => { it('should process messages correctly', () => { let parser = new BattleTextParser(); - assert.equal(parser.extractMessage('|-activate|p2a: Cool.|move: Skill Swap|Speed Boost|Cute Charm|[of] p1a: Speedy'), ` [The opposing Cool.'s Speed Boost] + assert.equal(parser.extractMessage(`|-activate|p2a: Cool.|move: Skill Swap|Speed Boost|Cute Charm|[of] p1a: Speedy`), ` [The opposing Cool.'s Speed Boost] [Speedy's Cute Charm] The opposing Cool. swapped Abilities with its target! `); - assert.equal(parser.extractMessage('|-activate|p2a: Cool.|move: Skill Swap|p1a: Speedy|[ability]Speed Boost|[ability2]Cute Charm'), ` [The opposing Cool.'s Speed Boost] + assert.equal(parser.extractMessage(`|-activate|p2a: Cool.|move: Skill Swap|p1a: Speedy|[ability]Speed Boost|[ability2]Cute Charm`), ` [The opposing Cool.'s Speed Boost] [Speedy's Cute Charm] The opposing Cool. swapped Abilities with its target! +`); + assert.equal(parser.extractMessage(`|move|p2a: Palkia|Swagger|p1a: Shroomish +|-boost|p1a: Shroomish|atk|2 +|-start|p1a: Shroomish|confusion +|-activate|p1a: Shroomish|confusion +|move|p1a: Shroomish|Power-Up Punch|p2a: Palkia +`), ` +The opposing Palkia used **Swagger**! + Shroomish's Attack rose sharply! + Shroomish became confused! + + Shroomish is confused! +Shroomish used **Power-Up Punch**! `); }); }); \ No newline at end of file