diff --git a/src/client/browser.lua b/src/client/browser.lua index 6413e9c..1365656 100644 --- a/src/client/browser.lua +++ b/src/client/browser.lua @@ -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 \ No newline at end of file +return scene.add( browser, 'browser' ) \ No newline at end of file diff --git a/src/client/menu.lua b/src/client/menu.lua index 3a8b791..9197755 100644 --- a/src/client/menu.lua +++ b/src/client/menu.lua @@ -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 \ No newline at end of file +return scene.add( menu, 'menu' ) \ No newline at end of file diff --git a/src/client/scene.lua b/src/client/scene.lua new file mode 100644 index 0000000..7532b5f --- /dev/null +++ b/src/client/scene.lua @@ -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 } ) \ No newline at end of file diff --git a/src/main.lua b/src/main.lua index cfd39fc..2abcde2 100644 --- a/src/main.lua +++ b/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