From 6464a9764136ff498d09946bb2997f12e208e653 Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Sat, 17 Nov 2018 13:59:06 -0600 Subject: [PATCH] Support uhtml in battles Supporting it actually turns out to be very simple, so we might as well. In practice, we probably want to never use this feature for broadcast messages - I don't think I want it in replays. It could still be nice for stuff like /roomsettings, though. --- src/battle-log.ts | 12 +++++++++--- src/battle.ts | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/battle-log.ts b/src/battle-log.ts index 764bd3145..9ed694d3c 100644 --- a/src/battle-log.ts +++ b/src/battle-log.ts @@ -104,6 +104,10 @@ class BattleLog { divHTML = BattleLog.sanitizeHTML(args[1]); break; + case 'uhtml': case 'uhtmlchange': + this.changeUhtml(args[1], args[2], args[0] === 'uhtml'); + return ['', '']; + case 'error': case 'inactive': case 'inactiveoff': divClass = 'chat message-error'; divHTML = BattleLog.escapeHTML(args[1]); @@ -237,9 +241,11 @@ class BattleLog { elements.push(node); } } - for (const node of this.preemptElem.childNodes as any) { - if (node.className && (' ' + node.className + ' ').includes(classContains)) { - elements.push(node); + if (this.preemptElem) { + for (const node of this.preemptElem.childNodes as any) { + if (node.className && (' ' + node.className + ' ').includes(classContains)) { + elements.push(node); + } } } if (html && elements.length && !forceAdd) { diff --git a/src/battle.ts b/src/battle.ts index b241a496a..ef70ceff0 100644 --- a/src/battle.ts +++ b/src/battle.ts @@ -3162,7 +3162,7 @@ class Battle { case 'fieldhtml': case 'controlshtml': case 'bigerror': case 'debug': case 'tier': return {args: [cmd, str.slice(index + 1)], kwArgs: {}}; - case 'c': case 'chat': + case 'c': case 'chat': case 'uhtml': case 'uhtmlchange': // three parts const index2a = str.indexOf('|', index + 1); return {args: [cmd, str.slice(index + 1, index2a), str.slice(index2a + 1)], kwArgs: {}};