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 lg = assert( love.graphics )
|
||||||
|
local scene = assert( require 'client.scene' )
|
||||||
local browser = {}
|
local browser = {}
|
||||||
|
|
||||||
function browser.draw()
|
function browser.draw()
|
||||||
|
@ -14,5 +14,4 @@ function browser.onLoad( )
|
||||||
lg.setColor( 1, 1, 1, 1 )
|
lg.setColor( 1, 1, 1, 1 )
|
||||||
end
|
end
|
||||||
|
|
||||||
client.addScene( browser, "browser" )
|
return scene.add( browser, 'browser' )
|
||||||
return browser
|
|
|
@ -1,6 +1,6 @@
|
||||||
--Main menu for client.
|
--Main menu for client.
|
||||||
local lg = assert( love.graphics )
|
local lg = assert( love.graphics )
|
||||||
local client = assert( client )
|
local scene = assert( require 'client.scene' )
|
||||||
local strings = assert( require 'client.strings' )
|
local strings = assert( require 'client.strings' )
|
||||||
local menu = {}
|
local menu = {}
|
||||||
|
|
||||||
|
@ -50,13 +50,11 @@ function menu.mousemoved( x, y, dx, dy, istouch )
|
||||||
end
|
end
|
||||||
|
|
||||||
function menu.mousepressed( x, y, button, istouch, presses )
|
function menu.mousepressed( x, y, button, istouch, presses )
|
||||||
client.loadScene( "browser" )
|
scene.load( 'browser' )
|
||||||
end
|
end
|
||||||
|
|
||||||
function menu.keypressed( key, code, isrepeat )
|
function menu.keypressed( key, code, isrepeat )
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
client.addScene( menu, "menu" )
|
return scene.add( menu, 'menu' )
|
||||||
|
|
||||||
return 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 } )
|
20
src/main.lua
20
src/main.lua
|
@ -1,26 +1,10 @@
|
||||||
--Client starts here!
|
--Client starts here!
|
||||||
client = { scenes = {} }
|
|
||||||
local client = client
|
|
||||||
local shared = assert( require 'shared' )
|
local shared = assert( require 'shared' )
|
||||||
local love = assert( love )
|
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()
|
function love.load()
|
||||||
|
local scenes = assert( require 'client.scene' )
|
||||||
assert( require 'client.menu' )
|
assert( require 'client.menu' )
|
||||||
assert( require 'client.browser' )
|
assert( require 'client.browser' )
|
||||||
|
scenes.load( 'menu' )
|
||||||
client.loadScene( "menu" )
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue