From 23d2d675cdd75265d21fdd8cbc2755d04da46a99 Mon Sep 17 00:00:00 2001 From: grothedev Date: Tue, 22 Nov 2022 16:07:15 -0500 Subject: [PATCH] optimization: make events a hashmap --- game/public/brain/brainGame.js | 13 +++---------- game/public/brain/gen/world/world.js | 9 ++++----- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/game/public/brain/brainGame.js b/game/public/brain/brainGame.js index d559f36..c04297e 100644 --- a/game/public/brain/brainGame.js +++ b/game/public/brain/brainGame.js @@ -367,17 +367,10 @@ class BrainGame { } getWorldEventByName = (e) => { - if (this.world?.events) { - const eventKeys = Object.keys(this.world.events) - for (let i = 0; i < eventKeys.length; i++) { - if (eventKeys[i].toLowerCase() === e.toLowerCase()) { - return eventKeys[i] - } - } - // If no match, return null - return null + if (this.world?.events.has(e)) { + return this.world.events[e] } - else return null + return null } doWorldEvent = (e) => { diff --git a/game/public/brain/gen/world/world.js b/game/public/brain/gen/world/world.js index 627d7f9..93ae58c 100644 --- a/game/public/brain/gen/world/world.js +++ b/game/public/brain/gen/world/world.js @@ -28,13 +28,12 @@ class World { // } // Events (these should all be strings to house chat commands) - this.events = { - worldStart: "", - gameStart: "", - gameEnd: "", + this.events = new Map() + this.events["worldStart"] = "" + this.events["gameStart"] = "" + this.events["gameEnd"] = "" // playerDie: "" // ... - } this.getWorldSeed = () => { return this._wSeed }