tidy up scene management
This commit is contained in:
parent
bef5a5e6c7
commit
beb5d71f03
|
@ -1,5 +1,5 @@
|
|||
local client = assert( client )
|
||||
local lg = assert( love.graphics )
|
||||
local scene = assert( require 'client.scene' )
|
||||
local browser = {}
|
||||
|
||||
function browser.draw()
|
||||
|
@ -14,5 +14,4 @@ function browser.onLoad( )
|
|||
lg.setColor( 1, 1, 1, 1 )
|
||||
end
|
||||
|
||||
client.addScene( browser, "browser" )
|
||||
return browser
|
||||
return scene.add( browser, 'browser' )
|
|
@ -1,6 +1,6 @@
|
|||
--Main menu for client.
|
||||
local lg = assert( love.graphics )
|
||||
local client = assert( client )
|
||||
local scene = assert( require 'client.scene' )
|
||||
local strings = assert( require 'client.strings' )
|
||||
local menu = {}
|
||||
|
||||
|
@ -50,13 +50,11 @@ function menu.mousemoved( x, y, dx, dy, istouch )
|
|||
end
|
||||
|
||||
function menu.mousepressed( x, y, button, istouch, presses )
|
||||
client.loadScene( "browser" )
|
||||
scene.load( 'browser' )
|
||||
end
|
||||
|
||||
function menu.keypressed( key, code, isrepeat )
|
||||
|
||||
end
|
||||
|
||||
client.addScene( menu, "menu" )
|
||||
|
||||
return menu
|
||||
return scene.add( menu, 'menu' )
|
|
@ -0,0 +1,20 @@
|
|||
local scene = {}
|
||||
local love = assert( love )
|
||||
local mt = {}
|
||||
|
||||
function mt.load( name )
|
||||
print( "Loading Scene:", name )
|
||||
local scene = assert( scene[name] )
|
||||
for k, v in pairs( scene ) do
|
||||
love[k] = v
|
||||
end
|
||||
scene.onLoad()
|
||||
end
|
||||
|
||||
function mt.add( t, name )
|
||||
print( "Adding Scene:", t.name or name )
|
||||
scene[name] = t
|
||||
return t
|
||||
end
|
||||
|
||||
return setmetatable( scene, {__index = mt } )
|
24
src/main.lua
24
src/main.lua
|
@ -1,26 +1,10 @@
|
|||
--Client starts here!
|
||||
client = { scenes = {} }
|
||||
local client = client
|
||||
local shared = assert( require 'shared' )
|
||||
local love = assert( love )
|
||||
|
||||
function client.loadScene( name )
|
||||
print( "Loading Scene:", name )
|
||||
local scene = assert( client.scenes[name] )
|
||||
for k, v in pairs( scene ) do
|
||||
love[k] = v
|
||||
end
|
||||
scene.onLoad()
|
||||
end
|
||||
|
||||
function client.addScene( t, name )
|
||||
print( "Adding Scene:", name )
|
||||
client.scenes[name] = t
|
||||
end
|
||||
|
||||
function love.load()
|
||||
assert( require 'client.menu' )
|
||||
assert( require 'client.browser' )
|
||||
|
||||
client.loadScene( "menu" )
|
||||
local scenes = assert( require 'client.scene' )
|
||||
assert( require 'client.menu' )
|
||||
assert( require 'client.browser' )
|
||||
scenes.load( 'menu' )
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue