From 134edf345a30232d51febe38f2bef305c2bc22d3 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 7 Apr 2019 17:51:37 +0200 Subject: [PATCH] scenes: remove "keys" table and replace it by a source table --- gamecore/input.lua | 17 ++++++++++++----- gamecore/modules/scenes.lua | 20 ++++++++++++-------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/gamecore/input.lua b/gamecore/input.lua index d4427aa..752eefb 100644 --- a/gamecore/input.lua +++ b/gamecore/input.lua @@ -34,11 +34,8 @@ end function InputManager:initKeys() self.fakekeys = self:getKeyList(1) - self.sources = {} - for i,v in ipairs(self.data) do - self.sources[i] = {} - self.sources[i].keys = self:getKeyList(i) - end + self.sources = self:getSources() + self.fakesources = self:getSources() end function InputManager:isDown(sourceid, padkey) @@ -54,6 +51,16 @@ function InputManager:isDown(sourceid, padkey) return isdown end +function InputManager:getSources() + local sources = {} + for i,v in ipairs(self.data) do + sources[i] = {} + sources[i].keys = self:getKeyList(i) + end + + return sources +end + function InputManager:getKeyList(sourceid) local keys = {} if self.data[sourceid] ~= nil then diff --git a/gamecore/modules/scenes.lua b/gamecore/modules/scenes.lua index 0f885ba..a1840ca 100644 --- a/gamecore/modules/scenes.lua +++ b/gamecore/modules/scenes.lua @@ -34,7 +34,7 @@ function Scene:new() self.assets = Assets() self.menusystem = MenuSystem() - self.keys = core.input:getKeyList() + self.sources = core.input:getSources() self.inputLocked = false self.inputLockedTimer = 0 @@ -68,30 +68,34 @@ end function Scene:setKeys() if (self.inputLocked) then - self.keys = core.input.fakekeys + self.sources = core.input.fakesources self.inputLockedTimer = self.inputLockedTimer - 1 if (self.inputLockedTimer <= 0 ) then self.inputLocked = false end else - -- TODO: make the scene input system get all inputs - self.keys = core.input.sources[1].keys + self.sources = core.input.sources end - self.menusystem.keys = self.keys + self.menusystem.keys = self.sources[1].keys end function Scene:getKeys(sourceid) + if sourceid == nil then + print("WARNING", "no sourceid detected, will default to 1") + end + + local sourceid = sourceid or 1 if (self.inputLocked) then - return self.keys + return self.sources[sourceid].keys else return core.input.fakekeys end end function Scene:flushKeys() - core.input:flushKeys() - self.keys = core.input.keys + core.input:flushSourceKeys() + self.sources = core.input:getSources() self.inputLockedTimer = 1 self.inputLocked = true end