From b134f1849aa91a7cb666e61e46b9f13037dc9c4d Mon Sep 17 00:00:00 2001 From: nolwn Date: Sat, 29 May 2021 12:54:57 -0700 Subject: [PATCH] Fix incorrect filtering of effect sources. --- User.ts | 4 ++-- Vessel.ts | 17 ++++++++--------- data/rooms.ts | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/User.ts b/User.ts index 2c0f422..4585e10 100644 --- a/User.ts +++ b/User.ts @@ -7,8 +7,8 @@ const DEFAULT_PROMPT = ">"; export default class User { #prompt: string; - constructor(prompt: string) { - this.#prompt = prompt || DEFAULT_PROMPT; + constructor(prompt: string = DEFAULT_PROMPT) { + this.#prompt = prompt; } ask(question: string): string { diff --git a/Vessel.ts b/Vessel.ts index 7aa0572..349195d 100644 --- a/Vessel.ts +++ b/Vessel.ts @@ -35,15 +35,14 @@ export default class Vessel { activePlayerEffects: string[], activeSceneEffects: string[] ): T { - const activeEffects = [...activePlayerEffects, ...activeSceneEffects]; - const map = this._conditions.effects.reduce( - (map: { [name: string]: Effect }, effect: Effect) => { - map[effect.name] = effect; - return map; - }, - {} - ); - const effects = activeEffects.map((e) => map[e]); + const playerSet = new Set(activePlayerEffects); + const sceneSet = new Set(activeSceneEffects); + + const effects = this._conditions.effects.filter(({ name, source }) => { + const set = source === "player" ? playerSet : sceneSet; + return set.has(name); + }); + const appliedProperties = { ...this._properties }; // for each effect, apply changed properties to the diff --git a/data/rooms.ts b/data/rooms.ts index 7c435b6..6da1628 100644 --- a/data/rooms.ts +++ b/data/rooms.ts @@ -35,7 +35,7 @@ export const hall: StoryScene = { effect: "flashlight-on", // can be "player" or "scene" - applyTo: "scene", + applyTo: "player", // When it's used, this is what should be reported back to // the user.