@ksaa-nlp/gamehub-sdk 0.9.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +154 -374
- package/SPEC.md +865 -0
- package/dist/gamehub-sdk.js +164 -1191
- package/dist/gamehub-sdk.js.map +3 -3
- package/dist/src/api-client.d.ts +15 -5
- package/dist/src/api-client.d.ts.map +1 -1
- package/dist/src/api-client.js +21 -5
- package/dist/src/api-client.js.map +1 -1
- package/dist/src/bridge.d.ts +31 -14
- package/dist/src/bridge.d.ts.map +1 -1
- package/dist/src/bridge.js +148 -159
- package/dist/src/bridge.js.map +1 -1
- package/dist/src/constants.d.ts +8 -6
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +8 -6
- package/dist/src/constants.js.map +1 -1
- package/dist/src/init.d.ts +18 -12
- package/dist/src/init.d.ts.map +1 -1
- package/dist/src/init.js +23 -156
- package/dist/src/init.js.map +1 -1
- package/dist/src/main.d.ts +45 -85
- package/dist/src/main.d.ts.map +1 -1
- package/dist/src/main.js +27 -52
- package/dist/src/main.js.map +1 -1
- package/dist/src/match-context.d.ts.map +1 -1
- package/dist/src/match-context.js +0 -14
- package/dist/src/match-context.js.map +1 -1
- package/dist/src/server-dev-harness.d.ts +85 -0
- package/dist/src/server-dev-harness.d.ts.map +1 -0
- package/dist/src/server-dev-harness.js +233 -0
- package/dist/src/server-dev-harness.js.map +1 -0
- package/dist/src/server-entry.d.ts +127 -0
- package/dist/src/server-entry.d.ts.map +1 -0
- package/dist/src/server-entry.js +26 -0
- package/dist/src/server-entry.js.map +1 -0
- package/dist/src/session.d.ts +16 -9
- package/dist/src/session.d.ts.map +1 -1
- package/dist/src/session.js +38 -27
- package/dist/src/session.js.map +1 -1
- package/dist/src/state.d.ts +17 -55
- package/dist/src/state.d.ts.map +1 -1
- package/dist/src/state.js +13 -32
- package/dist/src/state.js.map +1 -1
- package/dist/src/utils.d.ts +3 -14
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +3 -31
- package/dist/src/utils.js.map +1 -1
- package/dist/types/bootstrap.d.ts +56 -36
- package/dist/types/bootstrap.d.ts.map +1 -1
- package/dist/types/question.d.ts +36 -0
- package/dist/types/question.d.ts.map +1 -0
- package/dist/types/question.js +21 -0
- package/dist/types/question.js.map +1 -0
- package/dist/types/session.d.ts +23 -20
- package/dist/types/session.d.ts.map +1 -1
- package/package.json +14 -4
- package/CHANGELOG.md +0 -545
- package/MIGRATION.md +0 -322
- package/dist/src/multiplayer-match.d.ts +0 -42
- package/dist/src/multiplayer-match.d.ts.map +0 -1
- package/dist/src/multiplayer-match.js +0 -551
- package/dist/src/multiplayer-match.js.map +0 -1
- package/dist/src/multiplayer.d.ts +0 -96
- package/dist/src/multiplayer.d.ts.map +0 -1
- package/dist/src/multiplayer.js +0 -536
- package/dist/src/multiplayer.js.map +0 -1
- package/dist/types/multiplayer-match.d.ts +0 -204
- package/dist/types/multiplayer-match.d.ts.map +0 -1
- package/dist/types/multiplayer-match.js +0 -15
- package/dist/types/multiplayer-match.js.map +0 -1
- package/dist/types/multiplayer.d.ts +0 -194
- package/dist/types/multiplayer.d.ts.map +0 -1
- package/dist/types/multiplayer.js +0 -2
- package/dist/types/multiplayer.js.map +0 -1
package/dist/src/session.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { state } from './state.js';
|
|
2
2
|
import { QUESTIONS_LIMIT_CAP } from './constants.js';
|
|
3
3
|
import { apiRequest } from './api-client.js';
|
|
4
|
-
import { unwrapResult
|
|
4
|
+
import { unwrapResult } from './utils.js';
|
|
5
5
|
import { sendToParent } from './bridge.js';
|
|
6
6
|
import { ensureInitialized } from './init.js';
|
|
7
7
|
/**
|
|
8
|
-
* Starts a new game session and caches the returned session token. Safe
|
|
9
|
-
* call multiple times — the cached token short-circuits subsequent
|
|
8
|
+
* Starts a new game session and caches the returned session token. Safe
|
|
9
|
+
* to call multiple times — the cached token short-circuits subsequent
|
|
10
|
+
* calls.
|
|
10
11
|
*
|
|
11
12
|
* Endpoint is selected from the active context:
|
|
12
13
|
* - league + game + match → scoped match session
|
|
@@ -27,11 +28,7 @@ export async function startSession() {
|
|
|
27
28
|
let body = { gameSlug: state.gameSlug };
|
|
28
29
|
if (state.leagueId && state.gameId && state.matchId) {
|
|
29
30
|
endpoint =
|
|
30
|
-
'/leagues/' +
|
|
31
|
-
state.leagueId +
|
|
32
|
-
'/matches/' +
|
|
33
|
-
state.matchId +
|
|
34
|
-
'/session';
|
|
31
|
+
'/leagues/' + state.leagueId + '/matches/' + state.matchId + '/session';
|
|
35
32
|
body = { gameId: state.gameId };
|
|
36
33
|
}
|
|
37
34
|
else if (state.leagueId && state.gameId) {
|
|
@@ -58,8 +55,13 @@ export async function startSession() {
|
|
|
58
55
|
}
|
|
59
56
|
}
|
|
60
57
|
/**
|
|
61
|
-
* Submit a score to the current session. If no session exists yet we try
|
|
62
|
-
* open one (re-using any in-flight start attempt).
|
|
58
|
+
* Submit a score to the current session. If no session exists yet we try
|
|
59
|
+
* to open one (re-using any in-flight start attempt).
|
|
60
|
+
*
|
|
61
|
+
* Multiplayer authority lives on the Colyseus server now — score
|
|
62
|
+
* submission is no longer gated by a client-side host role. Games that
|
|
63
|
+
* want only one peer to call this should make that decision based on
|
|
64
|
+
* their room state (e.g. `room.state.hostPeerId === selfId`).
|
|
63
65
|
*/
|
|
64
66
|
export async function submitScore(score, meta = {}) {
|
|
65
67
|
await ensureInitialized();
|
|
@@ -69,14 +71,6 @@ export async function submitScore(score, meta = {}) {
|
|
|
69
71
|
error: 'SDK could not initialize. Is game slug set?',
|
|
70
72
|
};
|
|
71
73
|
}
|
|
72
|
-
// Online-mode gate: when the SDK is joined to a multiplayer room, only the
|
|
73
|
-
// host is allowed to submit. Guests and viewers short-circuit with
|
|
74
|
-
// `{ skipped: true }` so games can call `submitScore` from shared code
|
|
75
|
-
// without double-counting the match.
|
|
76
|
-
if (state.mpRoom && state.mpRoom.role !== 'host') {
|
|
77
|
-
warn('submitScore skipped: only the multiplayer host may submit scores');
|
|
78
|
-
return { success: true, skipped: true };
|
|
79
|
-
}
|
|
80
74
|
if (!state.sessionToken) {
|
|
81
75
|
if (state.sessionStartPromise) {
|
|
82
76
|
await state.sessionStartPromise;
|
|
@@ -133,8 +127,8 @@ export async function submitScore(score, meta = {}) {
|
|
|
133
127
|
}
|
|
134
128
|
/**
|
|
135
129
|
* Convenience wrapper that tags a score with the current league match
|
|
136
|
-
* context. Fails early if there's no matchId — a plain `submitScore` is
|
|
137
|
-
* right call in that case.
|
|
130
|
+
* context. Fails early if there's no matchId — a plain `submitScore` is
|
|
131
|
+
* the right call in that case.
|
|
138
132
|
*/
|
|
139
133
|
export async function submitMatchScore(score, meta = {}) {
|
|
140
134
|
if (!state.matchId) {
|
|
@@ -162,8 +156,9 @@ export async function submitMatchResult(result = {}) {
|
|
|
162
156
|
return await submitMatchScore(0, { matchResult: result });
|
|
163
157
|
}
|
|
164
158
|
/**
|
|
165
|
-
* Fetch questions for this game. Returns an empty array on any failure
|
|
166
|
-
* invalid input — callers can treat "no questions" as the degraded
|
|
159
|
+
* Fetch questions for this game. Returns an empty array on any failure
|
|
160
|
+
* or invalid input — callers can treat "no questions" as the degraded
|
|
161
|
+
* state.
|
|
167
162
|
*/
|
|
168
163
|
export async function getQuestions(options = {}) {
|
|
169
164
|
await ensureInitialized();
|
|
@@ -177,6 +172,10 @@ export async function getQuestions(options = {}) {
|
|
|
177
172
|
if (limit !== undefined && (typeof limit !== 'number' || limit < 1)) {
|
|
178
173
|
return [];
|
|
179
174
|
}
|
|
175
|
+
// Profile selection: explicit option wins, else the bootstrap-supplied
|
|
176
|
+
// profileId (the player's pre-start picker choice). Omitted → resolver
|
|
177
|
+
// falls back to the game's isDefault profile (identical to today).
|
|
178
|
+
const profileId = options.profileId || state.bootstrapProfileId || '';
|
|
180
179
|
try {
|
|
181
180
|
const params = new URLSearchParams({
|
|
182
181
|
limit: String(Math.min(limit || QUESTIONS_LIMIT_CAP, QUESTIONS_LIMIT_CAP)),
|
|
@@ -188,19 +187,31 @@ export async function getQuestions(options = {}) {
|
|
|
188
187
|
params.set('difficulty', difficulty);
|
|
189
188
|
if (category)
|
|
190
189
|
params.set('category', String(category));
|
|
190
|
+
if (profileId)
|
|
191
|
+
params.set('profileId', profileId);
|
|
191
192
|
const result = await apiRequest('/games/' +
|
|
192
193
|
encodeURIComponent(gameIdentifier) +
|
|
193
194
|
'/questions?' +
|
|
194
195
|
params.toString(), { method: 'GET' });
|
|
195
196
|
const data = unwrapResult(result);
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
197
|
+
const raw = Array.isArray(data)
|
|
198
|
+
? data
|
|
199
|
+
: Array.isArray(data?.questions)
|
|
200
|
+
? data.questions
|
|
201
|
+
: [];
|
|
202
|
+
// The Mongoose `Question.answer` field allows numeric values for
|
|
203
|
+
// numeric-answer questions. Coerce to string at the API boundary so
|
|
204
|
+
// the canonical `Question.answer: string` invariant holds everywhere
|
|
205
|
+
// downstream (offline games, UGC bundles, scoring code).
|
|
206
|
+
return raw.map(normalizeQuestion);
|
|
201
207
|
}
|
|
202
208
|
catch {
|
|
203
209
|
return [];
|
|
204
210
|
}
|
|
205
211
|
}
|
|
212
|
+
function normalizeQuestion(raw) {
|
|
213
|
+
const q = raw;
|
|
214
|
+
const answer = typeof q.answer === 'number' ? String(q.answer) : q.answer;
|
|
215
|
+
return { ...q, answer };
|
|
216
|
+
}
|
|
206
217
|
//# sourceMappingURL=session.js.map
|
package/dist/src/session.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAA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,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QACvD,IAAI,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAElD,MAAM,MAAM,GAAG,MAAM,UAAU,CAC7B,SAAS;YACP,kBAAkB,CAAC,cAAc,CAAC;YAClC,aAAa;YACb,MAAM,CAAC,QAAQ,EAAE,EACnB,EAAE,MAAM,EAAE,KAAK,EAAE,CAClB,CAAC;QAEF,MAAM,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;QAClC,MAAM,GAAG,GAAc,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;YACxC,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;gBAC9B,CAAC,CAAC,IAAI,CAAC,SAAS;gBAChB,CAAC,CAAC,EAAE,CAAC;QACT,iEAAiE;QACjE,oEAAoE;QACpE,qEAAqE;QACrE,yDAAyD;QACzD,OAAO,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAY;IACrC,MAAM,CAAC,GAAG,GAA6C,CAAC;IACxD,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC1E,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;AAC1B,CAAC"}
|
package/dist/src/state.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Centralised mutable state for the SDK singleton.
|
|
3
3
|
*
|
|
4
|
-
* Everything here lives on a single `state` object so
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Everything here lives on a single `state` object so feature modules
|
|
5
|
+
* can mutate it (`state.foo = bar`). ES modules don't allow reassigning
|
|
6
|
+
* imported `let` bindings from the consumer side, so a single shared
|
|
7
|
+
* object is the cleanest replacement for the namespace + `export let`
|
|
8
|
+
* pattern used in earlier SDK versions.
|
|
9
9
|
*/
|
|
10
|
+
import type { BootstrapConfig, BootstrapMultiplayer } from '../types/bootstrap.js';
|
|
10
11
|
import type { MatchContext } from '../types/match.js';
|
|
11
|
-
import type { BootstrapConfig } from '../types/bootstrap.js';
|
|
12
12
|
import type { StartSessionResult } from '../types/session.js';
|
|
13
|
-
import type { MpRoom, MpJoinRequest, Peer, MpEventHandler } from '../types/multiplayer.js';
|
|
14
13
|
export interface SdkState {
|
|
15
14
|
sdkOrigin: string;
|
|
16
15
|
sdkPathPrefix: string;
|
|
@@ -22,20 +21,14 @@ export interface SdkState {
|
|
|
22
21
|
leagueId: string | null;
|
|
23
22
|
gameId: string | null;
|
|
24
23
|
matchId: string | null;
|
|
25
|
-
|
|
26
|
-
participant2Id: string | null;
|
|
27
|
-
participant1MemberIds: string[];
|
|
28
|
-
participant2MemberIds: string[];
|
|
29
|
-
matchContext: MatchContext | null;
|
|
30
|
-
matchContextPromise: Promise<MatchContext | null> | null;
|
|
31
|
-
bootstrapShareId: string | null;
|
|
32
|
-
bootstrapRoomCode: string | null;
|
|
33
|
-
bootstrapRoomRole: string | null;
|
|
34
|
-
bootstrapRoomToken: string | null;
|
|
35
|
-
bootstrapWsUrl: string | null;
|
|
24
|
+
bootstrapMode: string | null;
|
|
36
25
|
bootstrapPlayerName: string | null;
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
bootstrapPlayerCount: string | null;
|
|
27
|
+
bootstrapTeamOneName: string | null;
|
|
28
|
+
bootstrapTeamTwoName: string | null;
|
|
29
|
+
/** Player's pre-start profile choice; default for `getQuestions`. */
|
|
30
|
+
bootstrapProfileId: string | null;
|
|
31
|
+
bootstrapMultiplayer: BootstrapMultiplayer | null;
|
|
39
32
|
bootstrapReceived: boolean;
|
|
40
33
|
isInitialized: boolean;
|
|
41
34
|
isAutoInitializing: boolean;
|
|
@@ -43,41 +36,10 @@ export interface SdkState {
|
|
|
43
36
|
bootstrapRequestPromise: Promise<BootstrapConfig | null> | null;
|
|
44
37
|
parentOrigin: string | null;
|
|
45
38
|
sessionStartPromise: Promise<StartSessionResult> | null;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
mpReconnectAttempts: number;
|
|
51
|
-
mpExpectedClose: boolean;
|
|
52
|
-
mpRoom: MpRoom | null;
|
|
53
|
-
mpLastJoinRequest: MpJoinRequest | null;
|
|
54
|
-
readonly mpPeers: Map<string, Peer>;
|
|
55
|
-
readonly mpHandlers: Map<string, Set<MpEventHandler>>;
|
|
56
|
-
/**
|
|
57
|
-
* Highest `seq` we've already delivered to game code, per sending peer.
|
|
58
|
-
* Used to drop late/duplicate `game_event` frames so a reconnect or a
|
|
59
|
-
* buffered message can't double-advance game state.
|
|
60
|
-
*/
|
|
61
|
-
readonly mpLastSeqByPeer: Map<string, number>;
|
|
62
|
-
/**
|
|
63
|
-
* Local override for view-only guests. The server doesn't know about
|
|
64
|
-
* viewers — this is a client-side flag the SDK flips when the game joins
|
|
65
|
-
* with `{ asViewer: true }`. It gates outbound `send` / `broadcast` and
|
|
66
|
-
* score submission.
|
|
67
|
-
*/
|
|
68
|
-
mpViewerOverride: boolean;
|
|
69
|
-
/**
|
|
70
|
-
* EMA-smoothed offset between the realtime server's clock and ours.
|
|
71
|
-
* `serverNow() === Date.now() + mpServerOffsetMs`. Updated from every
|
|
72
|
-
* incoming frame's `sentAt` field. Initialized to 0 (no skew assumed).
|
|
73
|
-
*/
|
|
74
|
-
mpServerOffsetMs: number;
|
|
75
|
-
/**
|
|
76
|
-
* Number of `sentAt` samples folded into `mpServerOffsetMs`. The first
|
|
77
|
-
* sample replaces the offset wholesale; subsequent samples blend via
|
|
78
|
-
* EMA so a single network blip doesn't yank the clock around.
|
|
79
|
-
*/
|
|
80
|
-
mpServerOffsetSamples: number;
|
|
39
|
+
/** Cached league match context, loaded on demand. */
|
|
40
|
+
matchContext: MatchContext | null;
|
|
41
|
+
/** In-flight match-context fetch, deduped across callers. */
|
|
42
|
+
matchContextPromise: Promise<MatchContext | null> | null;
|
|
81
43
|
}
|
|
82
44
|
export declare const state: SdkState;
|
|
83
45
|
//# sourceMappingURL=state.d.ts.map
|
package/dist/src/state.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,MAAM,WAAW,QAAQ;IAEvB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAGhB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAGvB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,qEAAqE;IACrE,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAMlC,oBAAoB,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAClD,iBAAiB,EAAE,OAAO,CAAC;IAG3B,aAAa,EAAE,OAAO,CAAC;IACvB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,eAAe,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IACzC,uBAAuB,EAAE,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAChE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,mBAAmB,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAAC;IAGxD,qDAAqD;IACrD,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAClC,6DAA6D;IAC7D,mBAAmB,EAAE,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;CAC1D;AAED,eAAO,MAAM,KAAK,EAAE,QAgCnB,CAAC"}
|
package/dist/src/state.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Centralised mutable state for the SDK singleton.
|
|
3
3
|
*
|
|
4
|
-
* Everything here lives on a single `state` object so
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Everything here lives on a single `state` object so feature modules
|
|
5
|
+
* can mutate it (`state.foo = bar`). ES modules don't allow reassigning
|
|
6
|
+
* imported `let` bindings from the consumer side, so a single shared
|
|
7
|
+
* object is the cleanest replacement for the namespace + `export let`
|
|
8
|
+
* pattern used in earlier SDK versions.
|
|
9
9
|
*/
|
|
10
10
|
export const state = {
|
|
11
11
|
sdkOrigin: '',
|
|
@@ -18,20 +18,13 @@ export const state = {
|
|
|
18
18
|
leagueId: null,
|
|
19
19
|
gameId: null,
|
|
20
20
|
matchId: null,
|
|
21
|
-
|
|
22
|
-
participant2Id: null,
|
|
23
|
-
participant1MemberIds: [],
|
|
24
|
-
participant2MemberIds: [],
|
|
25
|
-
matchContext: null,
|
|
26
|
-
matchContextPromise: null,
|
|
27
|
-
bootstrapShareId: null,
|
|
28
|
-
bootstrapRoomCode: null,
|
|
29
|
-
bootstrapRoomRole: null,
|
|
30
|
-
bootstrapRoomToken: null,
|
|
31
|
-
bootstrapWsUrl: null,
|
|
21
|
+
bootstrapMode: null,
|
|
32
22
|
bootstrapPlayerName: null,
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
bootstrapPlayerCount: null,
|
|
24
|
+
bootstrapTeamOneName: null,
|
|
25
|
+
bootstrapTeamTwoName: null,
|
|
26
|
+
bootstrapProfileId: null,
|
|
27
|
+
bootstrapMultiplayer: null,
|
|
35
28
|
bootstrapReceived: false,
|
|
36
29
|
isInitialized: false,
|
|
37
30
|
isAutoInitializing: false,
|
|
@@ -39,19 +32,7 @@ export const state = {
|
|
|
39
32
|
bootstrapRequestPromise: null,
|
|
40
33
|
parentOrigin: null,
|
|
41
34
|
sessionStartPromise: null,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
mpSocket: null,
|
|
45
|
-
mpReconnectTimer: null,
|
|
46
|
-
mpReconnectAttempts: 0,
|
|
47
|
-
mpExpectedClose: false,
|
|
48
|
-
mpRoom: null,
|
|
49
|
-
mpLastJoinRequest: null,
|
|
50
|
-
mpPeers: new Map(),
|
|
51
|
-
mpHandlers: new Map(),
|
|
52
|
-
mpLastSeqByPeer: new Map(),
|
|
53
|
-
mpViewerOverride: false,
|
|
54
|
-
mpServerOffsetMs: 0,
|
|
55
|
-
mpServerOffsetSamples: 0,
|
|
35
|
+
matchContext: null,
|
|
36
|
+
matchContextPromise: null,
|
|
56
37
|
};
|
|
57
38
|
//# sourceMappingURL=state.js.map
|
package/dist/src/state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAuDH,MAAM,CAAC,MAAM,KAAK,GAAa;IAC7B,SAAS,EAAE,EAAE;IACb,aAAa,EAAE,EAAE;IACjB,eAAe,EAAE,EAAE;IACnB,OAAO,EAAE,EAAE;IAEX,QAAQ,EAAE,IAAI;IACd,YAAY,EAAE,IAAI;IAClB,SAAS,EAAE,IAAI;IACf,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,IAAI;IACZ,OAAO,EAAE,IAAI;IAEb,aAAa,EAAE,IAAI;IACnB,mBAAmB,EAAE,IAAI;IACzB,oBAAoB,EAAE,IAAI;IAC1B,oBAAoB,EAAE,IAAI;IAC1B,oBAAoB,EAAE,IAAI;IAC1B,kBAAkB,EAAE,IAAI;IAExB,oBAAoB,EAAE,IAAI;IAC1B,iBAAiB,EAAE,KAAK;IAExB,aAAa,EAAE,KAAK;IACpB,kBAAkB,EAAE,KAAK;IACzB,eAAe,EAAE,IAAI;IACrB,uBAAuB,EAAE,IAAI;IAC7B,YAAY,EAAE,IAAI;IAClB,mBAAmB,EAAE,IAAI;IAEzB,YAAY,EAAE,IAAI;IAClB,mBAAmB,EAAE,IAAI;CAC1B,CAAC"}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -12,25 +12,14 @@ export declare function isBrowser(): boolean;
|
|
|
12
12
|
export declare function warn(message: string, ...rest: any[]): void;
|
|
13
13
|
export declare function error(message: string, ...rest: any[]): void;
|
|
14
14
|
/**
|
|
15
|
-
* Flattens the standard `{ success, data }` envelope returned by
|
|
16
|
-
* down to the inner `data` payload
|
|
17
|
-
*
|
|
15
|
+
* Flattens the standard `{ success, data }` envelope returned by the
|
|
16
|
+
* GameHub REST API down to the inner `data` payload. Returns the raw
|
|
17
|
+
* response when the envelope shape doesn't apply.
|
|
18
18
|
*/
|
|
19
19
|
export declare function unwrapResult(result: ApiResponse | null | undefined): any;
|
|
20
|
-
/**
|
|
21
|
-
* Extracts a share ID from either:
|
|
22
|
-
* - a full multiplayer URL (`/join?mp=<shareId>`), or
|
|
23
|
-
* - a short path where the last segment is the share ID itself.
|
|
24
|
-
* Returns null if the link can't be parsed.
|
|
25
|
-
*/
|
|
26
|
-
export declare function extractShareIdFromLink(link: string): string | null;
|
|
27
20
|
/**
|
|
28
21
|
* Safely read a query-string parameter, falling back to a regex scan when
|
|
29
22
|
* URLSearchParams is unavailable (very old browsers / odd runtimes).
|
|
30
23
|
*/
|
|
31
24
|
export declare function readQueryParam(name: string): string | null;
|
|
32
|
-
/**
|
|
33
|
-
* Reads a CSV query parameter and returns the trimmed, non-empty values.
|
|
34
|
-
*/
|
|
35
|
-
export declare function readCsvQueryParam(name: string): string[];
|
|
36
25
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAE1D;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAE3D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG,GAAG,CAIxE;AAED
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAE1D;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAE3D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG,GAAG,CAIxE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAU1D"}
|
package/dist/src/utils.js
CHANGED
|
@@ -17,9 +17,9 @@ export function error(message, ...rest) {
|
|
|
17
17
|
console.error('[GameHubSDK] ' + message, ...rest);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* Flattens the standard `{ success, data }` envelope returned by
|
|
21
|
-
* down to the inner `data` payload
|
|
22
|
-
*
|
|
20
|
+
* Flattens the standard `{ success, data }` envelope returned by the
|
|
21
|
+
* GameHub REST API down to the inner `data` payload. Returns the raw
|
|
22
|
+
* response when the envelope shape doesn't apply.
|
|
23
23
|
*/
|
|
24
24
|
export function unwrapResult(result) {
|
|
25
25
|
if (!result)
|
|
@@ -28,24 +28,6 @@ export function unwrapResult(result) {
|
|
|
28
28
|
return result.data;
|
|
29
29
|
return result;
|
|
30
30
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Extracts a share ID from either:
|
|
33
|
-
* - a full multiplayer URL (`/join?mp=<shareId>`), or
|
|
34
|
-
* - a short path where the last segment is the share ID itself.
|
|
35
|
-
* Returns null if the link can't be parsed.
|
|
36
|
-
*/
|
|
37
|
-
export function extractShareIdFromLink(link) {
|
|
38
|
-
try {
|
|
39
|
-
const parsed = new URL(link, window.location.origin);
|
|
40
|
-
const mp = parsed.searchParams.get('mp');
|
|
41
|
-
if (mp)
|
|
42
|
-
return mp;
|
|
43
|
-
return parsed.pathname.split('/').pop() || null;
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
31
|
/**
|
|
50
32
|
* Safely read a query-string parameter, falling back to a regex scan when
|
|
51
33
|
* URLSearchParams is unavailable (very old browsers / odd runtimes).
|
|
@@ -60,14 +42,4 @@ export function readQueryParam(name) {
|
|
|
60
42
|
return match ? decodeURIComponent(match[1]) : null;
|
|
61
43
|
}
|
|
62
44
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Reads a CSV query parameter and returns the trimmed, non-empty values.
|
|
65
|
-
*/
|
|
66
|
-
export function readCsvQueryParam(name) {
|
|
67
|
-
const raw = readQueryParam(name) || '';
|
|
68
|
-
return raw
|
|
69
|
-
.split(',')
|
|
70
|
-
.map((value) => value.trim())
|
|
71
|
-
.filter(Boolean);
|
|
72
|
-
}
|
|
73
45
|
//# sourceMappingURL=utils.js.map
|
package/dist/src/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,QAAQ,KAAK,WAAW,CAAC;AAC1E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,IAAI,CAAC,OAAe,EAAE,GAAG,IAAW;IAClD,OAAO,CAAC,IAAI,CAAC,eAAe,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,OAAe,EAAE,GAAG,IAAW;IACnD,OAAO,C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C;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CACxC,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,GAAG,UAAU,CAAC,CACvC,CAAC;QACF,OAAO,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACrD,CAAC;AACH,CAAC"}
|
|
@@ -1,21 +1,42 @@
|
|
|
1
|
-
import type { MatchContext } from './match.js';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
2
|
+
* Seat reservation handed off from the GameHub host to the embedded game.
|
|
3
|
+
* Mirrors the flat `ISeatReservation` shape returned by Colyseus's
|
|
4
|
+
* matchmaker — redeclared here so this types package has no realtime-
|
|
5
|
+
* transport dependency.
|
|
6
|
+
*/
|
|
7
|
+
export interface SdkSeatReservation {
|
|
8
|
+
name: string;
|
|
9
|
+
sessionId: string;
|
|
10
|
+
roomId: string;
|
|
11
|
+
processId?: string;
|
|
12
|
+
publicAddress?: string;
|
|
13
|
+
reconnectionToken?: string;
|
|
14
|
+
devMode?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Multiplayer block in the bootstrap payload.
|
|
4
18
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
19
|
+
* Present iff the host launched the game inside a live multiplayer room.
|
|
20
|
+
* The SDK exposes this as-is on `sdk.getBootstrap().multiplayer`. Games
|
|
21
|
+
* that want a Colyseus connection consume the seat reservation as the
|
|
22
|
+
* blessed first-join path:
|
|
23
|
+
*
|
|
24
|
+
* const bs = sdk.getBootstrap();
|
|
25
|
+
* if (bs.multiplayer) {
|
|
26
|
+
* const client = new Client(bs.multiplayer.wsEndpoint);
|
|
27
|
+
* const room = await client.consumeSeatReservation(bs.multiplayer.reservation);
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* `reconnect(reconnectionToken)` is reserved for mid-match recovery
|
|
31
|
+
* (laptop lid / network blip) and uses `room.reconnectionToken` minted by
|
|
32
|
+
* the server after the initial join.
|
|
8
33
|
*/
|
|
9
|
-
export interface
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
maxPlayers: number | null;
|
|
13
|
-
role: string | null;
|
|
14
|
-
roomToken: string | null;
|
|
15
|
-
wsUrl: string | null;
|
|
34
|
+
export interface BootstrapMultiplayer {
|
|
35
|
+
reservation: SdkSeatReservation;
|
|
36
|
+
wsEndpoint: string;
|
|
16
37
|
}
|
|
17
38
|
/**
|
|
18
|
-
* The
|
|
39
|
+
* The bootstrap payload the host posts via `GAMEHUB_SDK_BOOTSTRAP`.
|
|
19
40
|
*/
|
|
20
41
|
export interface BootstrapConfig {
|
|
21
42
|
gameSlug?: string | null;
|
|
@@ -23,23 +44,25 @@ export interface BootstrapConfig {
|
|
|
23
44
|
leagueId?: string | null;
|
|
24
45
|
gameId?: string | null;
|
|
25
46
|
matchId?: string | null;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
participant1MemberIds?: string[];
|
|
29
|
-
participant2MemberIds?: string[];
|
|
47
|
+
/** Play mode tag, e.g. `'two_players_online'`. Free-form. */
|
|
48
|
+
mode?: string | null;
|
|
30
49
|
playerName?: string | null;
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
50
|
+
/** Free-form string for solo modes that present a player count to the user. */
|
|
51
|
+
playerCount?: string | null;
|
|
52
|
+
teamOneName?: string | null;
|
|
53
|
+
teamTwoName?: string | null;
|
|
54
|
+
/**
|
|
55
|
+
* Player's pre-start profile choice. The in-iframe SDK uses it as the default
|
|
56
|
+
* `profileId` for `getQuestions`, so a solo/iframe game fetches the same set
|
|
57
|
+
* the chosen profile selects. Omitted → resolver isDefault fallback.
|
|
58
|
+
*/
|
|
59
|
+
profileId?: string | null;
|
|
60
|
+
multiplayer?: BootstrapMultiplayer | null;
|
|
35
61
|
}
|
|
36
62
|
/**
|
|
37
|
-
* Snapshot
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* This snapshot contains only static session metadata. For the live room
|
|
41
|
-
* and peer state, use `multiplayer.getRoom()`, `multiplayer.getPeers()`,
|
|
42
|
-
* and the `room_joined` / `peer_joined` / `peer_left` events.
|
|
63
|
+
* Snapshot returned by `sdk.getBootstrap()`. Same shape as
|
|
64
|
+
* {@link BootstrapConfig} with concrete (non-optional) keys plus the
|
|
65
|
+
* `isBootstrapped` flag.
|
|
43
66
|
*/
|
|
44
67
|
export interface BootstrapData {
|
|
45
68
|
gameSlug: string | null;
|
|
@@ -47,16 +70,13 @@ export interface BootstrapData {
|
|
|
47
70
|
leagueId: string | null;
|
|
48
71
|
gameId: string | null;
|
|
49
72
|
matchId: string | null;
|
|
50
|
-
|
|
51
|
-
participant1Id: string | null;
|
|
52
|
-
participant2Id: string | null;
|
|
53
|
-
participant1MemberIds: string[];
|
|
54
|
-
participant2MemberIds: string[];
|
|
73
|
+
mode: string | null;
|
|
55
74
|
playerName: string | null;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
75
|
+
playerCount: string | null;
|
|
76
|
+
teamOneName: string | null;
|
|
77
|
+
teamTwoName: string | null;
|
|
78
|
+
profileId: string | null;
|
|
79
|
+
multiplayer: BootstrapMultiplayer | null;
|
|
60
80
|
isBootstrapped: boolean;
|
|
61
81
|
}
|
|
62
82
|
//# sourceMappingURL=bootstrap.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../types/bootstrap.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../types/bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IA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AC;IACvB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACzC,cAAc,EAAE,OAAO,CAAC;CACzB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical question shape used everywhere in the gamehub stack:
|
|
3
|
+
*
|
|
4
|
+
* - Browser-side: returned by `sdk.getQuestions()` (the SDK normalizes
|
|
5
|
+
* `answer` to a string at the API boundary so consumers never see a
|
|
6
|
+
* numeric value).
|
|
7
|
+
* - Server-side: passed into UGC bundles via `CreateOptions.questions`
|
|
8
|
+
* when a `questionPackId` was supplied at room creation.
|
|
9
|
+
* - Colyseus host loader: the shape `questionPack.ts` returns.
|
|
10
|
+
*
|
|
11
|
+
* Mirrors the gamehub Mongoose `Question` model
|
|
12
|
+
* (`packages/gamehub/src/models/Question.ts`), minus persistence-only
|
|
13
|
+
* fields (`_id`, `gameId`, `status`, timestamps).
|
|
14
|
+
*
|
|
15
|
+
* Single source of truth — older `QuestionData` (colyseus-schemas) and
|
|
16
|
+
* `ServerQuestion` (gamehub-sdk/server) types have been removed; any
|
|
17
|
+
* consumer that needs the shape imports `Question` from here (or from
|
|
18
|
+
* one of the re-exports under `@ksaa-nlp/gamehub-sdk` / `/server`).
|
|
19
|
+
*/
|
|
20
|
+
export type QuestionDifficulty = 'easy' | 'medium' | 'hard';
|
|
21
|
+
export interface Question {
|
|
22
|
+
id: string;
|
|
23
|
+
/** Free-form classification (e.g. 'mcq', 'true-false'). */
|
|
24
|
+
type?: string;
|
|
25
|
+
prompt: string;
|
|
26
|
+
choices: string[];
|
|
27
|
+
/** Always a string. The browser SDK coerces numeric API responses on
|
|
28
|
+
* receipt; server-side loaders do the same. */
|
|
29
|
+
answer: string;
|
|
30
|
+
explanation?: string;
|
|
31
|
+
difficulty?: QuestionDifficulty;
|
|
32
|
+
category?: string;
|
|
33
|
+
/** Defaults to 0 in scoring code when omitted. */
|
|
34
|
+
points?: number;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=question.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question.d.ts","sourceRoot":"","sources":["../../types/question.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE5D,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;oDACgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical question shape used everywhere in the gamehub stack:
|
|
3
|
+
*
|
|
4
|
+
* - Browser-side: returned by `sdk.getQuestions()` (the SDK normalizes
|
|
5
|
+
* `answer` to a string at the API boundary so consumers never see a
|
|
6
|
+
* numeric value).
|
|
7
|
+
* - Server-side: passed into UGC bundles via `CreateOptions.questions`
|
|
8
|
+
* when a `questionPackId` was supplied at room creation.
|
|
9
|
+
* - Colyseus host loader: the shape `questionPack.ts` returns.
|
|
10
|
+
*
|
|
11
|
+
* Mirrors the gamehub Mongoose `Question` model
|
|
12
|
+
* (`packages/gamehub/src/models/Question.ts`), minus persistence-only
|
|
13
|
+
* fields (`_id`, `gameId`, `status`, timestamps).
|
|
14
|
+
*
|
|
15
|
+
* Single source of truth — older `QuestionData` (colyseus-schemas) and
|
|
16
|
+
* `ServerQuestion` (gamehub-sdk/server) types have been removed; any
|
|
17
|
+
* consumer that needs the shape imports `Question` from here (or from
|
|
18
|
+
* one of the re-exports under `@ksaa-nlp/gamehub-sdk` / `/server`).
|
|
19
|
+
*/
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=question.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question.js","sourceRoot":"","sources":["../../types/question.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG"}
|