From 0f08de787202b2a7c36c4da97621efc4a518eeff Mon Sep 17 00:00:00 2001 From: cha0s Date: Fri, 21 Jun 2024 06:03:56 -0500 Subject: [PATCH] refactor: item input --- app/ecs-systems/apply-control-item.js | 17 ----------------- app/engine/engine.js | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 21 deletions(-) delete mode 100644 app/ecs-systems/apply-control-item.js diff --git a/app/ecs-systems/apply-control-item.js b/app/ecs-systems/apply-control-item.js deleted file mode 100644 index 40d1629..0000000 --- a/app/ecs-systems/apply-control-item.js +++ /dev/null @@ -1,17 +0,0 @@ -import {System} from '@/ecs/index.js'; - -export default class ApplyControlMovement extends System { - - tick() { - const {diff} = this.ecs; - for (const id in diff) { - if ('changeSlot' in (diff[id].Controlled ?? {})) { - if (diff[id].Controlled.changeSlot > 0) { - this.ecs.get(id).Wielder.activeSlot = diff[id].Controlled.changeSlot - 1; - } - } - } - } - -} - diff --git a/app/engine/engine.js b/app/engine/engine.js index b1ca269..b4c2d60 100644 --- a/app/engine/engine.js +++ b/app/engine/engine.js @@ -81,7 +81,6 @@ export default class Engine { }, }); const defaultSystems = [ - 'ApplyControlItem', 'ApplyControlMovement', 'ApplyMomentum', 'ClampPositions', @@ -185,9 +184,19 @@ export default class Engine { for (const i in this.ecses) { this.ecses[i].setClean(); } - // TODO: SANITIZE - for (const [{Controlled}, payload] of this.incomingActions) { - Controlled[payload.type] = payload.value; + for (const [{Controlled, Wielder}, payload] of this.incomingActions) { + switch (payload.type) { + case 'moveUp': + case 'moveRight': + case 'moveDown': + case 'moveLeft': { + Controlled[payload.type] = payload.value; + break; + } + case 'changeSlot': { + Wielder.activeSlot = payload.value - 1; + } + } } this.incomingActions = []; for (const i in this.ecses) {