core/scenes: improve input locking system
This commit is contained in:
parent
824fdbdf86
commit
793c05117a
2 changed files with 28 additions and 3 deletions
|
@ -36,6 +36,9 @@ function Scene:new()
|
||||||
self.menusystem = MenuSystem()
|
self.menusystem = MenuSystem()
|
||||||
self.keys = core.input:getKeyList()
|
self.keys = core.input:getKeyList()
|
||||||
|
|
||||||
|
self.inputLocked = false
|
||||||
|
self.inputLockedTimer = 0
|
||||||
|
|
||||||
self:register()
|
self:register()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,9 +66,33 @@ function Scene:clear()
|
||||||
|
|
||||||
end
|
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()
|
function Scene:flushKeys()
|
||||||
core.input:flushKeys()
|
core.input:flushKeys()
|
||||||
self.keys = core.input.keys
|
self.keys = core.input.keys
|
||||||
|
self.inputLockedTimer = 1
|
||||||
|
self.inputLocked = true
|
||||||
end
|
end
|
||||||
|
|
||||||
return Scene
|
return Scene
|
||||||
|
|
|
@ -54,9 +54,7 @@ end
|
||||||
|
|
||||||
function SceneManager:update(dt)
|
function SceneManager:update(dt)
|
||||||
if (self.currentScene ~= nil) then
|
if (self.currentScene ~= nil) then
|
||||||
local keys = self.controller.input.keys
|
self.currentScene:setKeys()
|
||||||
self.currentScene.keys = keys
|
|
||||||
self.currentScene.menusystem.keys = keys
|
|
||||||
self.currentScene.assets:update(dt)
|
self.currentScene.assets:update(dt)
|
||||||
self.currentScene.menusystem:update(dt)
|
self.currentScene.menusystem:update(dt)
|
||||||
self.currentScene:update(dt)
|
self.currentScene:update(dt)
|
||||||
|
|
Loading…
Reference in a new issue