From 8e000dbc44003357e28b9fd4e420fa6ba384bc67 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 7 Sep 2019 21:51:20 +0200 Subject: [PATCH] fix(input): improve key flushing --- gamecore/input.lua | 2 ++ gamecore/modules/scenes.lua | 21 +++++++++++---------- gamecore/modules/world/baseworld.lua | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/gamecore/input.lua b/gamecore/input.lua index 21e5f70..4653aa1 100644 --- a/gamecore/input.lua +++ b/gamecore/input.lua @@ -41,6 +41,8 @@ function InputManager:initSources() local source = VirtualPad(self, sourceid, data) table.insert(self.sources, source) end + + self.fakekeys = self:getKeyList(1) end -- INFO FUNCTIONS diff --git a/gamecore/modules/scenes.lua b/gamecore/modules/scenes.lua index a28f18f..3484df6 100644 --- a/gamecore/modules/scenes.lua +++ b/gamecore/modules/scenes.lua @@ -40,8 +40,9 @@ function Scene:new() self.menusystem = MenuSystem(self) self.sources = core.input:getSources() - self.inputLocked = false - self.inputLockedTimer = 0 + self.inputLocked = true + self.inputLockedTimer = 2 + self:flushKeys() self:initWorld() @@ -136,16 +137,15 @@ end function Scene:setKeys() if (self.inputLocked) then - self.sources = core.input.fakesources self.inputLockedTimer = self.inputLockedTimer - 1 if (self.inputLockedTimer <= 0 ) then self.inputLocked = false end + self.menusystem.keys = self:getKeys(1) else self.sources = core.input.sources + self.menusystem.keys = self:getKeys(1) end - - self.menusystem.keys = self.sources[1].keys end function Scene:getKeys(sourceid) @@ -155,16 +155,17 @@ function Scene:getKeys(sourceid) local sourceid = sourceid or 1 if (self.inputLocked) then - return self.sources[sourceid].keys - else + core.debug:print("scene", "inputs are currently locked") return core.input.fakekeys + else + return self.sources[sourceid].keys end end -function Scene:flushKeys() +function Scene:flushKeys(timer) core.input:flushKeys() - self.sources = core.input:getSources() - self.inputLockedTimer = 1 + self.sources = core.input.sources + self.inputLockedTimer = timer or 2 self.inputLocked = true end diff --git a/gamecore/modules/world/baseworld.lua b/gamecore/modules/world/baseworld.lua index f7c53f5..3804867 100644 --- a/gamecore/modules/world/baseworld.lua +++ b/gamecore/modules/world/baseworld.lua @@ -253,7 +253,7 @@ end function BaseWorld:sendInputToPlayers(actor) for i, player in ipairs(self.players) do - local keys = self.scene.sources[player.sourceid].keys + local keys = self.scene:getKeys(player.sourceid) player.actor:getInput(keys) end end