Commit e640847e authored by Delisa Mason's avatar Delisa Mason

feat: Fill in initial system config

parent 77a36e0d
local systems = {}
-- Loop over every system, invoking a function by name if present
local function system_func(name, ...)
for i, system in ipairs(systems) do
if type(system) == 'table' and type(system[name]) == 'function' then
system[name](...)
end
end
end
-- Remove a system from being run
function systems.remove(systemToPop)
for i, system in ipairs(systems) do
if system == systemToPop then
systems[i + 1] = nil
break
end
end
end
-- Add a system to run
function systems.add(systemToAdd)
for i, system in ipairs(systems) do
if system == nil then
systems[i] = systemToAdd
return
end
end
systems[#systems + 1] = systemToAdd
end
-- Run update loops on each system
function systems.update(game, dt)
system_func('preUpdate', game, dt)
system_func('update', game, dt)
system_func('postUpdate', game, dt)
end
-- Run keyreleased loop on each system
function systems.keyreleased(game, key, code)
system_func('keyreleased', game, key, code)
end
-- Run draw loops on each system
function systems.draw(game, dt)
system_func('draw', game, dt)
end
return systems
return function (tiny)
local input = tiny.processingSystem()
input.filter = tiny.requireAll("input", "velocity", "action", "facing")
return function()
local system = {}
function system.keyreleased(game, key, code)
local entity = game.player
if key == entity.input.keymap.pause then
game.paused = not game.paused
return
end
end
function system.update(game, dt)
local entity = game.player
if game.paused then
return
end
function input:process(entity, dt)
if entity.input.moveUp() then
entity.facing = "up"
entity.velocity.dy = -entity.velocity.speed * dt
......@@ -24,5 +36,5 @@ return function (tiny)
end
end
return input
return system
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment