fix(input): improve key flushing

This commit is contained in:
Kazhnuz 2019-09-07 21:51:20 +02:00
parent 47c6bab698
commit 8e000dbc44
3 changed files with 14 additions and 11 deletions

View file

@ -41,6 +41,8 @@ function InputManager:initSources()
local source = VirtualPad(self, sourceid, data) local source = VirtualPad(self, sourceid, data)
table.insert(self.sources, source) table.insert(self.sources, source)
end end
self.fakekeys = self:getKeyList(1)
end end
-- INFO FUNCTIONS -- INFO FUNCTIONS

View file

@ -40,8 +40,9 @@ function Scene:new()
self.menusystem = MenuSystem(self) self.menusystem = MenuSystem(self)
self.sources = core.input:getSources() self.sources = core.input:getSources()
self.inputLocked = false self.inputLocked = true
self.inputLockedTimer = 0 self.inputLockedTimer = 2
self:flushKeys()
self:initWorld() self:initWorld()
@ -136,16 +137,15 @@ end
function Scene:setKeys() function Scene:setKeys()
if (self.inputLocked) then if (self.inputLocked) then
self.sources = core.input.fakesources
self.inputLockedTimer = self.inputLockedTimer - 1 self.inputLockedTimer = self.inputLockedTimer - 1
if (self.inputLockedTimer <= 0 ) then if (self.inputLockedTimer <= 0 ) then
self.inputLocked = false self.inputLocked = false
end end
self.menusystem.keys = self:getKeys(1)
else else
self.sources = core.input.sources self.sources = core.input.sources
self.menusystem.keys = self:getKeys(1)
end end
self.menusystem.keys = self.sources[1].keys
end end
function Scene:getKeys(sourceid) function Scene:getKeys(sourceid)
@ -155,16 +155,17 @@ function Scene:getKeys(sourceid)
local sourceid = sourceid or 1 local sourceid = sourceid or 1
if (self.inputLocked) then if (self.inputLocked) then
return self.sources[sourceid].keys core.debug:print("scene", "inputs are currently locked")
else
return core.input.fakekeys return core.input.fakekeys
else
return self.sources[sourceid].keys
end end
end end
function Scene:flushKeys() function Scene:flushKeys(timer)
core.input:flushKeys() core.input:flushKeys()
self.sources = core.input:getSources() self.sources = core.input.sources
self.inputLockedTimer = 1 self.inputLockedTimer = timer or 2
self.inputLocked = true self.inputLocked = true
end end

View file

@ -253,7 +253,7 @@ end
function BaseWorld:sendInputToPlayers(actor) function BaseWorld:sendInputToPlayers(actor)
for i, player in ipairs(self.players) do 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) player.actor:getInput(keys)
end end
end end