core/scenes: improve input locking system

This commit is contained in:
Kazhnuz 2019-04-01 08:25:02 +02:00
parent 824fdbdf86
commit 793c05117a
2 changed files with 28 additions and 3 deletions

View file

@ -36,6 +36,9 @@ function Scene:new()
self.menusystem = MenuSystem()
self.keys = core.input:getKeyList()
self.inputLocked = false
self.inputLockedTimer = 0
self:register()
end
@ -63,9 +66,33 @@ function Scene:clear()
end
function Scene:setKeys()
if (self.inputLocked) then
self.keys = core.input.fakekeys
self.inputLockedTimer = self.inputLockedTimer - 1
if (self.inputLockedTimer <= 0 ) then
self.inputLockedTimer = false
end
else
self.keys = core.input.keys
end
self.menusystem.keys = self.keys
end
function Scene:getKeys()
if (self.inputLocked) then
return self.keys
else
return core.input.fakekeys
end
end
function Scene:flushKeys()
core.input:flushKeys()
self.keys = core.input.keys
self.inputLockedTimer = 1
self.inputLocked = true
end
return Scene

View file

@ -54,9 +54,7 @@ end
function SceneManager:update(dt)
if (self.currentScene ~= nil) then
local keys = self.controller.input.keys
self.currentScene.keys = keys
self.currentScene.menusystem.keys = keys
self.currentScene:setKeys()
self.currentScene.assets:update(dt)
self.currentScene.menusystem:update(dt)
self.currentScene:update(dt)