scenes: remove "keys" table and replace it by a source table
This commit is contained in:
parent
0dce34e33a
commit
134edf345a
2 changed files with 24 additions and 13 deletions
|
@ -34,11 +34,8 @@ end
|
||||||
function InputManager:initKeys()
|
function InputManager:initKeys()
|
||||||
self.fakekeys = self:getKeyList(1)
|
self.fakekeys = self:getKeyList(1)
|
||||||
|
|
||||||
self.sources = {}
|
self.sources = self:getSources()
|
||||||
for i,v in ipairs(self.data) do
|
self.fakesources = self:getSources()
|
||||||
self.sources[i] = {}
|
|
||||||
self.sources[i].keys = self:getKeyList(i)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function InputManager:isDown(sourceid, padkey)
|
function InputManager:isDown(sourceid, padkey)
|
||||||
|
@ -54,6 +51,16 @@ function InputManager:isDown(sourceid, padkey)
|
||||||
return isdown
|
return isdown
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function InputManager:getSources()
|
||||||
|
local sources = {}
|
||||||
|
for i,v in ipairs(self.data) do
|
||||||
|
sources[i] = {}
|
||||||
|
sources[i].keys = self:getKeyList(i)
|
||||||
|
end
|
||||||
|
|
||||||
|
return sources
|
||||||
|
end
|
||||||
|
|
||||||
function InputManager:getKeyList(sourceid)
|
function InputManager:getKeyList(sourceid)
|
||||||
local keys = {}
|
local keys = {}
|
||||||
if self.data[sourceid] ~= nil then
|
if self.data[sourceid] ~= nil then
|
||||||
|
|
|
@ -34,7 +34,7 @@ function Scene:new()
|
||||||
|
|
||||||
self.assets = Assets()
|
self.assets = Assets()
|
||||||
self.menusystem = MenuSystem()
|
self.menusystem = MenuSystem()
|
||||||
self.keys = core.input:getKeyList()
|
self.sources = core.input:getSources()
|
||||||
|
|
||||||
self.inputLocked = false
|
self.inputLocked = false
|
||||||
self.inputLockedTimer = 0
|
self.inputLockedTimer = 0
|
||||||
|
@ -68,30 +68,34 @@ end
|
||||||
|
|
||||||
function Scene:setKeys()
|
function Scene:setKeys()
|
||||||
if (self.inputLocked) then
|
if (self.inputLocked) then
|
||||||
self.keys = core.input.fakekeys
|
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
|
||||||
else
|
else
|
||||||
-- TODO: make the scene input system get all inputs
|
self.sources = core.input.sources
|
||||||
self.keys = core.input.sources[1].keys
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.menusystem.keys = self.keys
|
self.menusystem.keys = self.sources[1].keys
|
||||||
end
|
end
|
||||||
|
|
||||||
function Scene:getKeys(sourceid)
|
function Scene:getKeys(sourceid)
|
||||||
|
if sourceid == nil then
|
||||||
|
print("WARNING", "no sourceid detected, will default to 1")
|
||||||
|
end
|
||||||
|
|
||||||
|
local sourceid = sourceid or 1
|
||||||
if (self.inputLocked) then
|
if (self.inputLocked) then
|
||||||
return self.keys
|
return self.sources[sourceid].keys
|
||||||
else
|
else
|
||||||
return core.input.fakekeys
|
return core.input.fakekeys
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Scene:flushKeys()
|
function Scene:flushKeys()
|
||||||
core.input:flushKeys()
|
core.input:flushSourceKeys()
|
||||||
self.keys = core.input.keys
|
self.sources = core.input:getSources()
|
||||||
self.inputLockedTimer = 1
|
self.inputLockedTimer = 1
|
||||||
self.inputLocked = true
|
self.inputLocked = true
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue