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)
table.insert(self.sources, source)
end
self.fakekeys = self:getKeyList(1)
end
-- INFO FUNCTIONS

View file

@ -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

View file

@ -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