Skip to content

Commit

Permalink
Allow arbitraty gamestate callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
vrld committed Jan 26, 2013
1 parent bf862c9 commit d227499
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions gamestate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,15 @@ local current = setmetatable({leave = __NULL__}, {__index = __ERROR__})

local GS = {}
function GS.new()
return {
init = __NULL__,
enter = __NULL__,
leave = __NULL__,
update = __NULL__,
draw = __NULL__,
focus = __NULL__,
keyreleased = __NULL__,
keypressed = __NULL__,
mousepressed = __NULL__,
mousereleased = __NULL__,
joystickpressed = __NULL__,
joystickreleased = __NULL__,
quit = __NULL__,
}
return setmetatable({}, {__index = function() return __NULL__ end})
end

function GS.switch(to, ...)
assert(to, "Missing argument: Gamestate to switch to")
current:leave()
local pre = current
to:init()
to.init = __NULL__
to.init = nil
current = to
return current:enter(pre, ...)
end
Expand Down

0 comments on commit d227499

Please sign in to comment.