mirror of
https://github.com/vrld/hump.git
synced 2024-11-23 12:24:19 +00:00
Add gamestate:init()
This commit is contained in:
parent
94da317ed9
commit
e885ec90d4
@ -31,6 +31,7 @@ local function __NULL__() end
|
|||||||
-- default gamestate produces error on every callback
|
-- default gamestate produces error on every callback
|
||||||
local function __ERROR__() error("Gamestate not initialized. Use Gamestate.switch()") end
|
local function __ERROR__() error("Gamestate not initialized. Use Gamestate.switch()") end
|
||||||
current = {
|
current = {
|
||||||
|
init = __ERROR__,
|
||||||
enter = __ERROR__,
|
enter = __ERROR__,
|
||||||
leave = __NULL__,
|
leave = __NULL__,
|
||||||
update = __ERROR__,
|
update = __ERROR__,
|
||||||
@ -47,6 +48,7 @@ current = {
|
|||||||
|
|
||||||
function new()
|
function new()
|
||||||
return {
|
return {
|
||||||
|
init = __NULL__,
|
||||||
enter = __NULL__,
|
enter = __NULL__,
|
||||||
leave = __NULL__,
|
leave = __NULL__,
|
||||||
update = __NULL__,
|
update = __NULL__,
|
||||||
@ -66,6 +68,8 @@ function switch(to, ...)
|
|||||||
assert(to, "Missing argument: Gamestate to switch to")
|
assert(to, "Missing argument: Gamestate to switch to")
|
||||||
current:leave()
|
current:leave()
|
||||||
local pre = current
|
local pre = current
|
||||||
|
to:init()
|
||||||
|
to.init = __NULL__
|
||||||
current = to
|
current = to
|
||||||
return current:enter(pre, ...)
|
return current:enter(pre, ...)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user