51 lines
794 B
Lua
51 lines
794 B
Lua
local love = assert( love )
|
|
local button = require( "button" )
|
|
local t = {}
|
|
t.__index = t
|
|
|
|
local i = 0
|
|
function t.start( self )
|
|
i = i + 1
|
|
t[i] = t[i] or {}
|
|
|
|
--store callbacks
|
|
for name in pairs( self ) do
|
|
if love[name] then
|
|
t[i][name] = love[name]
|
|
love[name] = self[name]
|
|
end
|
|
end
|
|
|
|
--store menus
|
|
local b = button.next
|
|
repeat
|
|
t[i][b] = b.visible
|
|
b = b.next
|
|
until b == button
|
|
end
|
|
|
|
function t.stop( self )
|
|
--restore callbacks
|
|
for name in pairs( self ) do
|
|
if love[name] then
|
|
love[name] = t[i][name]
|
|
end
|
|
end
|
|
|
|
--restore menus
|
|
local b = button
|
|
repeat
|
|
b = b.next
|
|
b.visible = t[i][b]
|
|
until b == button
|
|
|
|
t[i] = nil
|
|
i = i - 1
|
|
|
|
end
|
|
|
|
function t.new( modal )
|
|
return setmetatable( modal or {}, t )
|
|
end
|
|
|
|
return t |