aboutsummaryrefslogtreecommitdiff
path: root/src/menu/main.moon
diff options
context:
space:
mode:
authorAlex Pickering <alex@cogarr.net>2026-02-01 13:14:32 -0600
committerAlexander M Pickering <alex@cogarr.net>2026-02-01 13:14:32 -0600
commit3a975db66a3711f34e8b64bb27a8eaca79fdeca9 (patch)
treefcc12f8f9d638ff575c1963796de76b7628854b4 /src/menu/main.moon
downloadggj26-3a975db66a3711f34e8b64bb27a8eaca79fdeca9.tar.gz
ggj26-3a975db66a3711f34e8b64bb27a8eaca79fdeca9.tar.bz2
ggj26-3a975db66a3711f34e8b64bb27a8eaca79fdeca9.zip
Initial commitHEADmaster
Diffstat (limited to 'src/menu/main.moon')
-rw-r--r--src/menu/main.moon137
1 files changed, 137 insertions, 0 deletions
diff --git a/src/menu/main.moon b/src/menu/main.moon
new file mode 100644
index 0000000..04f53b0
--- /dev/null
+++ b/src/menu/main.moon
@@ -0,0 +1,137 @@
+ui = require("ui")
+hub_mod = require("hub")
+client_mod = require("client")
+world = require("world")
+log = require("log")
+util = require("util")
+task = require("task")
+server_init = require("server.init")
+client_init = require("client.init")
+menu_lobby = require("menu.lobby")
+NetworkedComponent = require("ecs.networked")
+ecs = require("ecs")
+ScriptComponent = require("ecs.script")
+GraphicsComponent = require("ecs.graphics")
+menu = {}
+am.eval_js(require("party.qrcodejs.qrcode"))
+am.eval_js(require("clipboard_bridge"))
+params = am.eval_js("window.CLIPBOARD.get_params()")
+win = require("window")
+tutorial = require("menu.tutorial")
+
+buttons = {}
+menu.creating = false
+buttons_data = {
+ {
+ text: "Tutorial"
+ on: () =>
+ menu.destroy!
+ tutorial.create!
+ },
+ {
+ text: "Settings"
+ on: () =>
+ log.info("Menu pressed")
+ --menu.destroy!
+ --require("menu.settings").initialize!
+ },
+ {
+ text: "Host"
+ on: () =>
+ log.info("Host pressed")
+ if menu.creating
+ return false-- don't allow the user to click twice
+ menu.creating = true
+ listener = log.listen((chunk) ->
+ if chunk.tags.net or chunk.tags.server
+ @.text.text = chunk.message
+ --s = s .. chunk.message
+ --@.text.text = s
+ )
+ co = coroutine.create(() ->
+ -- Create and initialize the hub
+ hub = hub_mod.Hub!
+ hub\initialize!
+ assert(hub, "Hub was nil")
+ world.hub = hub
+ assert(world.hub, "Failed to set hub correctly")
+ server_init.initialize!
+
+ -- Create and connect the host's client to the hub
+ client = client_mod.Client("host")
+ client\initialize!
+ hub_id = hub.peer.id
+ log.info("Connecting host client to hub: " .. hub_id, {"net"})
+ client\connect_to_hub(hub_id)
+ while not client.connected
+ log.info("Connecting to hub",{"net"})
+ coroutine.yield!
+ -- For integration tests: expose a synthetic Join event to JS so
+ -- the hub/Join flow can be asserted without depending on the
+ -- underlying WebRTC transport.
+ if am and am.eval_js and am.to_json
+ js = string.format("window._hubJoinReceived = true; window._hubJoinData = %s;", am.to_json({name: client.name or "host"}))
+ am.eval_js(js)
+
+ world.network = client
+ world.network_mode = "host"
+ log.info("Hub created with ID: " .. hub_id, {"net"})
+ log.defen(listener)
+ menu_lobby.initialize!
+ client_init.initialize!
+ menu.destroy()
+ menu.creating = false
+ )
+ @.node\action(co)
+
+ }
+
+}
+menu.initialize = () ->
+ if params.i
+ peerid = util.code_to_peer(params.i)
+ co = coroutine.create(() ->
+ while am.eval_js('typeof(Peer) === "undefined"')
+ coroutine.yield!
+ log.info("Found invite param:" .. params.i, {"net"})
+ log.info("Got peer id:" .. tostring(peerid), {"net"})
+ client = client_mod.Client("player")
+ client\initialize!
+ client\connect_to_hub(peerid)
+ world.network = client
+ world.network_mode = "client"
+ log.info("Connected to hub",{"net"})
+ menu.destroy!
+ menu_lobby.initialize!
+ client_init.initialize!
+ )
+ task.add(co)
+ elseif params.dev
+ log.info("Doing game...",{"client"})
+ game = require("menu.game")
+ poems = require("poems")
+ game.create_graphic({
+ youare: "a pawn"
+ poem: poems[2]
+ })
+ --game.create_graphic({
+ --youare: "masked"
+ --poem: "Roses are red, violets are blue, here's a little game for you"
+ --})
+ game.create_graphic({
+ youare: "unmasked"
+ hint: "Roses are red, violets are blue, here's a little game for you"
+ })
+ else
+ print("Creating buttons")
+ starty = 0
+ for i = starty, ((#buttons_data-1) * (82 + 32)) + starty, 64 + 32
+ buttons[#buttons + 1] = ui.button(-150,i,300,82,buttons_data[#buttons + 1].text)
+ buttons[#buttons].on = buttons_data[#buttons].on
+
+menu.destroy = () ->
+ for button in *buttons
+ ui.delete(button)
+ buttons = {}
+
+menu