summaryrefslogtreecommitdiff
path: root/src/menu/main.moon
blob: 764ce281d252c5476e12d63a7bdda7fbf7b3b4c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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