Skip to content

Commit 81c15a1

Browse files
committed
controllers
1 parent 24f01eb commit 81c15a1

File tree

353 files changed

+11126
-4608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

353 files changed

+11126
-4608
lines changed

Notes/README-BRIDGE-HTTP.md

Lines changed: 202 additions & 0 deletions
Large diffs are not rendered by default.

Notes/README-UNITY-STARTUP.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Unity WebGL Startup Sequence (SpaceCraft Template)
2+
3+
This document precisely outlines the step-by-step initialization sequence for the SpaceCraft Unity WebGL application, emphasizing the critical path of function calls and events between HTML, JavaScript (`spacecraft.js`), and the Bridge system.
4+
5+
For detailed information on the Bridge system's internal implementation, refer to its dedicated documentation (e.g., `Bridge/README.md`).
6+
7+
## Core Initialization Flow
8+
9+
1. **HTML Parsing (`index.html`)**: Browser parses HTML, identifies CSS and JS files.
10+
* CSS (`spacecraft.css`) is requested.
11+
* External JS libraries (Supabase, QRCode) are requested.
12+
* Bridge JS (`bridge.js`, `unity.js`) is requested.
13+
* Application JS (`spacecraft.js`) is requested.
14+
15+
2. **`spacecraft.js` Execution (Initial)**: Browser executes `spacecraft.js` as soon as it's loaded.
16+
* **`fetch` initiated**: `window.indexDeepPromise = fetch(...)` starts loading `index-deep.json` asynchronously.
17+
* **`SpaceCraft` object defined**: The global `window.SpaceCraft` object is created.
18+
* **`DOMContentLoaded` listener attached**: An event listener is set for `DOMContentLoaded` to trigger `SpaceCraft.initializeDOMAndQRCodes()`.
19+
20+
3. **DOM Ready**: Browser fires `DOMContentLoaded` event.
21+
* **Listener triggers**: `SpaceCraft.initializeDOMAndQRCodes()` is called.
22+
23+
4. **DOM Initialization (`SpaceCraft.initializeDOMAndQRCodes`)**:
24+
* Checks for `QRCode` library availability.
25+
* Calls `SpaceCraft.generateQRCodes()`.
26+
* Calls `SpaceCraft.configureAndLoadUnity()`.
27+
28+
5. **QR Code Generation (`SpaceCraft.generateQRCodes`)**:
29+
* Reads `SpaceCraft.qrCodeDefinitions`.
30+
* Loops through definitions, dynamically creating HTML elements (`<a>`, `<svg>`, `<div>`) and invoking `QRCode({...})` for each.
31+
* Appends generated elements to `#qrcodes-container`.
32+
33+
6. **Unity Configuration (`SpaceCraft.configureAndLoadUnity`)**:
34+
* Prepares the `config` object for Unity.
35+
* Dynamically creates a `<script>` tag for `Build/SpaceCraft.loader.js`.
36+
* Assigns an `onload` handler to this script tag.
37+
* Appends the script tag to the document, initiating the loader script download.
38+
39+
7. **Unity Loader Execution (`Build/SpaceCraft.loader.js`)**: Browser downloads and executes the loader script.
40+
* **`createUnityInstance` defined**: The loader script defines the global `createUnityInstance` function.
41+
* **`onload` handler triggers**: The handler assigned in Step 6 executes.
42+
* **`createUnityInstance()` called**: The handler calls `createUnityInstance(canvas, config, progressCallback)`.
43+
44+
8. **Unity Engine Loading (`createUnityInstance`)**:
45+
* Downloads Unity data (`.data`), framework (`.framework.js`), and code (`.wasm`).
46+
* Initializes the Unity engine and WebGL context.
47+
* Returns a Promise that resolves when the engine is ready.
48+
49+
9. **Unity Instance Ready (`.then()` handler in `SpaceCraft.configureAndLoadUnity`)**: The Promise from `createUnityInstance` resolves.
50+
* Fullscreen button handler is attached.
51+
* **`bridge.start()` called**: `window.bridge.start("WebGL", ...)` is invoked, notifying the Bridge JS that Unity is ready.
52+
53+
10. **Bridge C# Initialization**: The `bridge.start()` call triggers initialization within the Bridge's C# components in Unity.
54+
* **`StartedUnity` event sent**: The C# `BridgeTransportWebGL` sends the `StartedUnity` event back to JavaScript via JSLib (`_Bridge_SendBridgeToUnityEvents`).
55+
56+
11. **Bridge JS Event Handling (`bridge.js`)**: The Bridge's central event handler receives the `StartedUnity` event.
57+
* **Callback triggered**: Recognizing the event, `bridge.js` calls `SpaceCraft.loadCollectionsAndCreateSpaceCraft()`.
58+
59+
12. **Collections Load & SpaceCraft Creation (`SpaceCraft.loadCollectionsAndCreateSpaceCraft`)**:
60+
* **`await window.indexDeepPromise`**: Waits for the JSON data fetch (initiated in Step 2) to complete.
61+
* **`this.createSpaceCraftObject()` called**: If JSON fetch succeeded, passes the loaded `collections` data.
62+
63+
13. **Bridge Object Creation (`SpaceCraft.createSpaceCraftObject`)**:
64+
* **`bridge.createObject()` called**: Sends a request to the Bridge containing prefab path, object ID, interests, and initial `collections` data.
65+
* (Bridge system handles instantiation and data application in Unity).
66+
* **`this.setupSupabase()` called**: Initiates Supabase setup.
67+
68+
14. **Supabase Setup (`SpaceCraft.setupSupabase`)**:
69+
* Initializes the Supabase client.
70+
* Subscribes to `navigators` and `selectors` channels.
71+
72+
## Critical Dependencies & Timing
73+
74+
* **DOM Readiness**: `initializeDOMAndQRCodes` requires `DOMContentLoaded`.
75+
* **Script Load Order**: `bridge.js`/`unity.js` must load *before* `spacecraft.js`. `qrcode.min.js` must load *before* `generateQRCodes` executes.
76+
* **Unity Loader**: `createUnityInstance` function must be defined by `Build/SpaceCraft.loader.js` *before* the `onload` handler in `spacecraft.js` calls it.
77+
* **`StartedUnity` Event**: `SpaceCraft.loadCollectionsAndCreateSpaceCraft` *only* runs if the C# Bridge sends `StartedUnity` and the JS Bridge correctly handles it.
78+
* **JSON Data**: `SpaceCraft.createSpaceCraftObject` requires the `indexDeepPromise` to resolve successfully *before* it is called.
79+
80+
Failure to respect these dependencies will break the initialization chain.

SvelteKit/BackSpace/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:7e7c9558463b2c05ddf0a65b7395a8e9297bb4580a7afa1487d40837967f11fd
3-
size 5061
2+
oid sha256:6d52755eb310167d68ba86d674e54ae5b799df61df182d3467fc44bba06f6a7b
3+
size 4797
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server.crt
2+
server.key

SvelteKit/BackSpace/scripts/collection-debug.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

SvelteKit/BackSpace/scripts/collection-process.ts

Lines changed: 0 additions & 133 deletions
This file was deleted.

SvelteKit/BackSpace/scripts/connector-manage.js

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)