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