From 36c5f03a246b8b37f4cf6bb2e1e661518f40647a Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Tue, 28 Jul 2020 14:20:03 -0400 Subject: [PATCH] Filter out nilLogs --- src/game/combat/actions.ts | 6 +++--- src/game/interface.ts | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/game/combat/actions.ts b/src/game/combat/actions.ts index 2f96521..97ecb4f 100644 --- a/src/game/combat/actions.ts +++ b/src/game/combat/actions.ts @@ -3,7 +3,7 @@ import { DynText, LiveText, TextLike, Verb, PairLine, PairLineArgs } from '../la import { Entity } from '../entity' import { Creature } from "../creature" import { Damage, DamageFormula, Stat, Vigor, Action } from '../combat' -import { LogLine, LogLines, LogEntry, CompositeLog, nilLog } from '../interface' +import { LogLine, LogLines, LogEntry, nilLog } from '../interface' import { VoreContainer, Container } from '../vore' import { CapableCondition, UserDrainedVigorCondition, TogetherCondition, EnemyCondition, SoloCondition, PairCondition, ContainsCondition, ContainedByCondition } from './conditions' @@ -43,7 +43,7 @@ export class AttackAction extends Action { const damage = this.damage.calc(user, target) const targetResult = target.takeDamage(damage) const ownResult = this.successLine(user, target, { damage: damage }) - return new CompositeLog(ownResult, targetResult) + return new LogLines(ownResult, targetResult) } else { return this.failLine(user, target) } @@ -217,7 +217,7 @@ export class DigestAction extends Action { execute (user: Creature, target: Creature): LogEntry { const results = this.container.tick(60) - return new CompositeLog(results) + return new LogLines(results) } describe (user: Creature, target: Creature): LogEntry { diff --git a/src/game/interface.ts b/src/game/interface.ts index 1a61880..9cbfb80 100644 --- a/src/game/interface.ts +++ b/src/game/interface.ts @@ -8,6 +8,15 @@ export interface LogEntry { render: () => HTMLElement[]; } +/** + * Represents nothing. Other elements should filter this out if they don't want blank spaces + */ +export const nilLog = { + render (): HTMLElement[] { + return [] + } +} + /** * Takes zero or more strings or [[LogEntry]] objects * @@ -28,7 +37,7 @@ export class LogLines implements LogEntry { const partDiv = document.createElement("div") partDiv.innerText = part div.appendChild(partDiv) - } else { + } else if (part !== nilLog) { (part as LogEntry).render().forEach(logPart => { const partDiv = document.createElement("div") partDiv.appendChild(logPart) @@ -103,7 +112,7 @@ export class LogLine implements LogEntry { const partSpan = document.createElement("span") partSpan.innerText = part div.appendChild(partSpan) - } else { + } else if (part !== nilLog) { (part as LogEntry).render().forEach(logPart => { div.appendChild(logPart) }) @@ -230,12 +239,3 @@ export class CompositeLog implements LogEntry { return this.entries.flatMap(e => e.render()) } } - -/** - * Represents nothing. Other elements should filter this out if they don't want blank spaces - */ -export const nilLog = { - render (): HTMLElement[] { - return [] - } -}