mirror of
https://github.com/vrld/hump.git
synced 2024-11-23 12:24:19 +00:00
Bug: prevent from switching to initial gamestate
This commit is contained in:
parent
5030f4db60
commit
6315155955
@ -1,10 +1,11 @@
|
|||||||
Gamestate = {}
|
Gamestate = {}
|
||||||
|
|
||||||
|
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
|
||||||
Gamestate.current = {
|
Gamestate.current = {
|
||||||
enter = __ERROR__,
|
enter = __ERROR__,
|
||||||
leave = __ERROR__,
|
leave = __NULL__,
|
||||||
update = __ERROR__,
|
update = __ERROR__,
|
||||||
draw = __ERROR__,
|
draw = __ERROR__,
|
||||||
keyreleased = __ERROR__,
|
keyreleased = __ERROR__,
|
||||||
@ -12,7 +13,6 @@ Gamestate.current = {
|
|||||||
mousereleased = __ERROR__,
|
mousereleased = __ERROR__,
|
||||||
}
|
}
|
||||||
|
|
||||||
local function __NULL__() end
|
|
||||||
function Gamestate.new()
|
function Gamestate.new()
|
||||||
return {
|
return {
|
||||||
enter = __NULL__,
|
enter = __NULL__,
|
||||||
@ -27,9 +27,7 @@ end
|
|||||||
|
|
||||||
function Gamestate.switch(to, ...)
|
function Gamestate.switch(to, ...)
|
||||||
if not to then return end
|
if not to then return end
|
||||||
if Gamestate.current then
|
|
||||||
Gamestate.current:leave()
|
Gamestate.current:leave()
|
||||||
end
|
|
||||||
local pre = Gamestate.current
|
local pre = Gamestate.current
|
||||||
Gamestate.current = to
|
Gamestate.current = to
|
||||||
Gamestate.current:enter(pre, ...)
|
Gamestate.current:enter(pre, ...)
|
||||||
|
Loading…
Reference in New Issue
Block a user