summaryrefslogtreecommitdiff
path: root/src/menu/main.moon
diff options
context:
space:
mode:
Diffstat (limited to 'src/menu/main.moon')
-rw-r--r--src/menu/main.moon67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/menu/main.moon b/src/menu/main.moon
new file mode 100644
index 0000000..764ce28
--- /dev/null
+++ b/src/menu/main.moon
@@ -0,0 +1,67 @@
+ui = require("ui")
+router = require("router")
+world = require("world")
+menu = {}
+
+buttons = {}
+buttons_data = {
+ {
+ text: "Settings"
+ on: () =>
+ menu.destroy!
+ require("menu.settings").initalize!
+ }
+ {
+ text: "Join"
+ on: () =>
+ menu.destroy!
+ require("menu.join").initalize!
+ }
+ {
+ text: "Host"
+ on: () =>
+ print("Setting co...")
+ if not @node.co
+ @node.co = coroutine.create(() ->
+ server = router.Router!
+ server\initalize!
+ server
+ )
+ button = @
+ @node\action(() =>
+ print("In coroutine, menu is", menu)
+ if @co and coroutine.status(@co) ~= "dead"
+ succ, val = coroutine.resume(@co)
+ if not succ
+ error(debug.traceback(@co,val))
+ if type(val) == "string"
+ print("Setting text", val)
+ button.text.text = val
+ else
+ print("Returned router")
+ world.router = val
+ menu.destroy!
+ require("menu.playername").initalize(true)
+ )
+ }
+ {
+ text: "Tutorial"
+ on: () =>
+ menu.destroy!
+ print("Load tutorial level")
+ }
+}
+menu.initalize = () ->
+ starty = -200
+ for i = starty, ((#buttons_data-1) * (64 + 32)) + starty, 64 + 32
+ print("making button", #buttons + 1)
+ buttons[#buttons + 1] = ui.button(-100,i,200,64,buttons_data[#buttons + 1].text)
+ buttons[#buttons].on = buttons_data[#buttons].on
+
+ print("intalize")
+
+menu.destroy = () ->
+ for button in *buttons
+ ui.delete(button)
+
+menu