-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
36 lines (29 loc) · 1.15 KB
/
game.js
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
// GUARDIANS
// This is the first game created for Croquet for Unity.
import { App, Constants, StartWorldcore} from "@croquet/worldcore-kernel";
import { MyModelRoot } from "./src/Actors";
import { MyViewRoot } from "./src/Pawns";
import apiKey from "./apiKey";
// redirect to lobby if not in iframe or session
const inIframe = window.parent !== window;
const url = new URL(window.location.href);
const sessionName = url.searchParams.get("session");
url.pathname = url.pathname.replace(/[^/]*$/, "index.html");
if (!inIframe || !sessionName) window.location.href = url.href;
// ensure unique session per lobby URL
const BaseUrl = url.href.replace(/[^/?#]*([?#].*)?$/, "");
Constants.LobbyUrl = BaseUrl + "index.html"; // hashed into sessionId without params
// QR code points to lobby, with session name in hash
url.searchParams.delete("session");
url.hash = encodeURIComponent(sessionName);
App.sessionURL = url.href;
App.makeWidgetDock({ iframe: true });
StartWorldcore({
...apiKey,
appId: 'io.croquet.guardians', // <-- feel free to change
name: sessionName,
password: "none",
location: true,
model: MyModelRoot,
view: MyViewRoot,
});