@remix-gg/sdk 0.8.0 → 0.8.1
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/dist/index.d.mts +42 -58
- package/dist/index.d.ts +61 -3
- package/dist/index.js +260 -188
- package/dist/index.min.js +37 -2
- package/dist/index.min.js.map +3 -3
- package/dist/index.mjs +191 -112
- package/package.json +4 -2
- package/dist/index.js.map +0 -10
- package/dist/index.mjs.map +0 -10
package/dist/index.d.mts
CHANGED
|
@@ -42,15 +42,31 @@ type GameInfo = {
|
|
|
42
42
|
id: string;
|
|
43
43
|
gameState: GameState;
|
|
44
44
|
} | null;
|
|
45
|
+
/**
|
|
46
|
+
* Present only when the host has level progression enabled for this session.
|
|
47
|
+
* Games must key level mode off this block's presence, not their own level
|
|
48
|
+
* content — the platform can disable it (e.g. feature gating) at any time.
|
|
49
|
+
*/
|
|
45
50
|
levelBased?: {
|
|
51
|
+
/** Canonical level total configured on the platform at upload. */
|
|
46
52
|
levelCount: number;
|
|
47
|
-
/**
|
|
48
|
-
* Score-derived level progression for this player. Platform-owned and kept
|
|
49
|
-
* fully separate from `gameState` — never read progression out of gameState.
|
|
50
|
-
*/
|
|
53
|
+
/** Score-derived, platform-owned progression — never read from gameState. */
|
|
51
54
|
progress: LevelProgressState;
|
|
52
55
|
};
|
|
53
56
|
};
|
|
57
|
+
type LevelStars = 1 | 2 | 3;
|
|
58
|
+
/** Stars for one level attempt: 0 = failed, 1–3 = completed with that rating. */
|
|
59
|
+
type LevelAttemptStars = 0 | LevelStars;
|
|
60
|
+
/**
|
|
61
|
+
* One level attempt reported with game_over. Games report only what happened
|
|
62
|
+
* in the attempt; the host owns and derives all cumulative progression.
|
|
63
|
+
*/
|
|
64
|
+
type LevelAttempt = {
|
|
65
|
+
/** 1-based index of the level that was just played. */
|
|
66
|
+
levelIndex: number;
|
|
67
|
+
/** Stars earned this attempt; 0 means the level was failed. */
|
|
68
|
+
stars: LevelAttemptStars;
|
|
69
|
+
};
|
|
54
70
|
/** Score-derived, platform-owned progression for a level-based game. */
|
|
55
71
|
type LevelProgressState = {
|
|
56
72
|
currentLevelIndex: number;
|
|
@@ -59,9 +75,7 @@ type LevelProgressState = {
|
|
|
59
75
|
};
|
|
60
76
|
type ReadyEvent = {
|
|
61
77
|
type: 'ready';
|
|
62
|
-
data:
|
|
63
|
-
instanceId: string;
|
|
64
|
-
} | undefined;
|
|
78
|
+
data: undefined;
|
|
65
79
|
};
|
|
66
80
|
type PlayAgainEvent = {
|
|
67
81
|
type: 'play_again';
|
|
@@ -69,20 +83,6 @@ type PlayAgainEvent = {
|
|
|
69
83
|
levelIndex?: number;
|
|
70
84
|
};
|
|
71
85
|
};
|
|
72
|
-
type LevelStars = 1 | 2 | 3;
|
|
73
|
-
type LevelOutcome = 'level_complete' | 'level_failed' | 'all_complete';
|
|
74
|
-
/**
|
|
75
|
-
* One level attempt reported with game_over. Games report only what happened
|
|
76
|
-
* in the attempt; the host owns and derives all cumulative progression
|
|
77
|
-
* (star maps, unlock state) — see `LevelProgressState` for the host→game snapshot.
|
|
78
|
-
*/
|
|
79
|
-
type LevelAttempt = {
|
|
80
|
-
/** 1-based index of the level that was just played. */
|
|
81
|
-
levelIndex: number;
|
|
82
|
-
/** Stars earned this attempt. Omit for star-less games; a completion counts as 1. */
|
|
83
|
-
stars?: LevelStars;
|
|
84
|
-
outcome: LevelOutcome;
|
|
85
|
-
};
|
|
86
86
|
type SinglePlayerGameOverEvent = {
|
|
87
87
|
type: 'game_over';
|
|
88
88
|
data: {
|
|
@@ -120,7 +120,6 @@ type GameErrorEvent = {
|
|
|
120
120
|
lineno?: number;
|
|
121
121
|
colno?: number;
|
|
122
122
|
error?: Error;
|
|
123
|
-
stack?: string;
|
|
124
123
|
};
|
|
125
124
|
};
|
|
126
125
|
type GameInfoEvent = {
|
|
@@ -173,56 +172,41 @@ type GameEventMessage<T extends GameEvent['type']> = {
|
|
|
173
172
|
type: T;
|
|
174
173
|
}>;
|
|
175
174
|
};
|
|
176
|
-
/**
|
|
177
|
-
* Build a game_event envelope for sending over postMessage. Hosts and the SDK
|
|
178
|
-
* share this so the wire format is defined in one place.
|
|
179
|
-
*/
|
|
180
|
-
declare const createGameEventMessage: <T extends GameEvent["type"]>(type: T, data: Extract<GameEvent, {
|
|
181
|
-
type: T;
|
|
182
|
-
}>["data"]) => GameEventMessage<T>;
|
|
183
|
-
/**
|
|
184
|
-
* Parse an unknown postMessage payload into a GameEvent, or null when the
|
|
185
|
-
* payload is not a well-formed game_event envelope.
|
|
186
|
-
*/
|
|
187
|
-
declare const parseGameEventMessage: (value: unknown) => GameEvent | null;
|
|
188
175
|
/**
|
|
189
176
|
* Messages from the game host to the game client
|
|
190
177
|
*/
|
|
191
178
|
type IncomingGameEvent = GameEventMessage<'play_again' | 'toggle_mute' | 'game_info' | 'game_state_updated' | 'purchase_complete'>;
|
|
192
179
|
type OutgoingGameEvent = GameEventMessage<'game_over' | 'ready' | 'haptic_feedback' | 'error' | 'save_game_state' | 'refute_game_state' | 'multiplayer_game_over' | 'multiplayer_save_game_state' | 'purchase'>;
|
|
193
|
-
type
|
|
194
|
-
type IncomingGameEventData<T extends IncomingGameEventType> = Extract<GameEvent, {
|
|
195
|
-
type: T;
|
|
196
|
-
}>['data'];
|
|
180
|
+
type EventCallback = (data: unknown) => void;
|
|
197
181
|
declare class RemixSDK {
|
|
182
|
+
/**
|
|
183
|
+
* The published version of this bundle. The host compares it against the
|
|
184
|
+
* version it asked the browser to load, so a cached bundle from a previous
|
|
185
|
+
* release can be detected before any game code runs.
|
|
186
|
+
*/
|
|
187
|
+
readonly version: string;
|
|
198
188
|
private isClient;
|
|
199
189
|
private target;
|
|
200
190
|
private eventListeners;
|
|
201
|
-
private readyPromise;
|
|
202
191
|
private readyPromiseResolve;
|
|
203
|
-
private
|
|
204
|
-
private readyResendTimer;
|
|
205
|
-
private readonly instanceId;
|
|
192
|
+
private purchasePromiseResolve;
|
|
206
193
|
private _gameInfo?;
|
|
207
194
|
private _gameState?;
|
|
208
|
-
private _levelStars;
|
|
209
195
|
constructor();
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
on<T extends IncomingGameEventType>(eventType: T, callback: (data: IncomingGameEventData<T>) => void): () => void;
|
|
213
|
-
off<T extends IncomingGameEventType>(eventType: T, callback: (data: IncomingGameEventData<T>) => void): void;
|
|
196
|
+
on(eventType: IncomingGameEvent['event']['type'], callback: EventCallback): void;
|
|
197
|
+
off(eventType: IncomingGameEvent['event']['type'], callback: EventCallback): void;
|
|
214
198
|
/**
|
|
215
199
|
* Listen for the host starting play: a replay after game over, or — for level
|
|
216
|
-
* games — a host-directed level via `data.levelIndex`
|
|
217
|
-
*
|
|
200
|
+
* games — a host-directed level via `data.levelIndex`. `data` may be omitted
|
|
201
|
+
* for a plain restart.
|
|
218
202
|
*/
|
|
219
|
-
onPlay(callback: (data?: PlayAgainEvent['data']) => void):
|
|
220
|
-
/**
|
|
221
|
-
onPlayAgain(callback: (data?: PlayAgainEvent['data']) => void):
|
|
222
|
-
onToggleMute(callback: (data: ToggleMuteEvent['data']) => void):
|
|
223
|
-
onGameStateUpdated(callback: (data: GameStateUpdatedEvent['data']) => void):
|
|
224
|
-
onGameInfo(callback: (data: GameInfoEvent['data']) => void):
|
|
225
|
-
onPurchaseComplete(callback: (data: PurchaseCompleteEvent['data']) => void):
|
|
203
|
+
onPlay(callback: (data?: PlayAgainEvent['data']) => void): void;
|
|
204
|
+
/** Alias of {@link onPlay}. */
|
|
205
|
+
onPlayAgain(callback: (data?: PlayAgainEvent['data']) => void): void;
|
|
206
|
+
onToggleMute(callback: (data: ToggleMuteEvent['data']) => void): void;
|
|
207
|
+
onGameStateUpdated(callback: (data: GameStateUpdatedEvent['data']) => void): void;
|
|
208
|
+
onGameInfo(callback: (data: GameInfoEvent['data']) => void): void;
|
|
209
|
+
onPurchaseComplete(callback: (data: PurchaseCompleteEvent['data']) => void): void;
|
|
226
210
|
setTarget(target: Window): void;
|
|
227
211
|
get purchasedItems(): string[];
|
|
228
212
|
get inventory(): InventoryItem[];
|
|
@@ -238,7 +222,7 @@ declare class RemixSDK {
|
|
|
238
222
|
get levelCount(): number | undefined;
|
|
239
223
|
/** 1-based level index from score-derived progression, defaulting to 1. */
|
|
240
224
|
get currentLevelIndex(): number;
|
|
241
|
-
/** Best stars
|
|
225
|
+
/** Best stars per level from score-derived progression. Keys are 1-based level indices. */
|
|
242
226
|
get levelStars(): Record<string, LevelStars>;
|
|
243
227
|
/** Highest unlocked level from score-derived progression, defaulting to 1. */
|
|
244
228
|
get highestUnlockedLevel(): number;
|
|
@@ -281,4 +265,4 @@ declare class RemixSDK {
|
|
|
281
265
|
}
|
|
282
266
|
declare const sdk: RemixSDK;
|
|
283
267
|
|
|
284
|
-
export { type GameErrorEvent, type GameEvent, type GameEventMessage, type GameInfo, type GameInfoEvent, type GameState, type GameStateUpdatedEvent, type HapticFeedbackEvent, type HapticFeedbackType, type IncomingGameEvent, type
|
|
268
|
+
export { type GameErrorEvent, type GameEvent, type GameEventMessage, type GameInfo, type GameInfoEvent, type GameState, type GameStateUpdatedEvent, type HapticFeedbackEvent, type HapticFeedbackType, type IncomingGameEvent, type InventoryItem, type LevelAttempt, type LevelAttemptStars, type LevelProgressState, type LevelStars, type MultiplayerGameOverEvent, type MultiplayerSaveGameStateEvent, type OutgoingGameEvent, type PlayAgainEvent, type Player, type PurchaseCompleteEvent, type PurchaseEvent, type ReadyEvent, type RefuteGameStateEvent, RemixSDK, type SafeAreaInset, type SaveGameStateEvent, type ShopItem, type SinglePlayerGameOverEvent, type ToggleMuteEvent, type ViewContext, ZERO_SAFE_AREA_INSET, sdk };
|
package/dist/index.d.ts
CHANGED
|
@@ -42,6 +42,36 @@ type GameInfo = {
|
|
|
42
42
|
id: string;
|
|
43
43
|
gameState: GameState;
|
|
44
44
|
} | null;
|
|
45
|
+
/**
|
|
46
|
+
* Present only when the host has level progression enabled for this session.
|
|
47
|
+
* Games must key level mode off this block's presence, not their own level
|
|
48
|
+
* content — the platform can disable it (e.g. feature gating) at any time.
|
|
49
|
+
*/
|
|
50
|
+
levelBased?: {
|
|
51
|
+
/** Canonical level total configured on the platform at upload. */
|
|
52
|
+
levelCount: number;
|
|
53
|
+
/** Score-derived, platform-owned progression — never read from gameState. */
|
|
54
|
+
progress: LevelProgressState;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
type LevelStars = 1 | 2 | 3;
|
|
58
|
+
/** Stars for one level attempt: 0 = failed, 1–3 = completed with that rating. */
|
|
59
|
+
type LevelAttemptStars = 0 | LevelStars;
|
|
60
|
+
/**
|
|
61
|
+
* One level attempt reported with game_over. Games report only what happened
|
|
62
|
+
* in the attempt; the host owns and derives all cumulative progression.
|
|
63
|
+
*/
|
|
64
|
+
type LevelAttempt = {
|
|
65
|
+
/** 1-based index of the level that was just played. */
|
|
66
|
+
levelIndex: number;
|
|
67
|
+
/** Stars earned this attempt; 0 means the level was failed. */
|
|
68
|
+
stars: LevelAttemptStars;
|
|
69
|
+
};
|
|
70
|
+
/** Score-derived, platform-owned progression for a level-based game. */
|
|
71
|
+
type LevelProgressState = {
|
|
72
|
+
currentLevelIndex: number;
|
|
73
|
+
highestUnlockedLevel: number;
|
|
74
|
+
levelStars: Record<string, LevelStars>;
|
|
45
75
|
};
|
|
46
76
|
type ReadyEvent = {
|
|
47
77
|
type: 'ready';
|
|
@@ -49,12 +79,15 @@ type ReadyEvent = {
|
|
|
49
79
|
};
|
|
50
80
|
type PlayAgainEvent = {
|
|
51
81
|
type: 'play_again';
|
|
52
|
-
data
|
|
82
|
+
data?: {
|
|
83
|
+
levelIndex?: number;
|
|
84
|
+
};
|
|
53
85
|
};
|
|
54
86
|
type SinglePlayerGameOverEvent = {
|
|
55
87
|
type: 'game_over';
|
|
56
88
|
data: {
|
|
57
89
|
score: number;
|
|
90
|
+
levelAttempt?: LevelAttempt;
|
|
58
91
|
};
|
|
59
92
|
};
|
|
60
93
|
type MultiplayerGameOverEvent = {
|
|
@@ -146,6 +179,12 @@ type IncomingGameEvent = GameEventMessage<'play_again' | 'toggle_mute' | 'game_i
|
|
|
146
179
|
type OutgoingGameEvent = GameEventMessage<'game_over' | 'ready' | 'haptic_feedback' | 'error' | 'save_game_state' | 'refute_game_state' | 'multiplayer_game_over' | 'multiplayer_save_game_state' | 'purchase'>;
|
|
147
180
|
type EventCallback = (data: unknown) => void;
|
|
148
181
|
declare class RemixSDK {
|
|
182
|
+
/**
|
|
183
|
+
* The published version of this bundle. The host compares it against the
|
|
184
|
+
* version it asked the browser to load, so a cached bundle from a previous
|
|
185
|
+
* release can be detected before any game code runs.
|
|
186
|
+
*/
|
|
187
|
+
readonly version: string;
|
|
149
188
|
private isClient;
|
|
150
189
|
private target;
|
|
151
190
|
private eventListeners;
|
|
@@ -156,7 +195,14 @@ declare class RemixSDK {
|
|
|
156
195
|
constructor();
|
|
157
196
|
on(eventType: IncomingGameEvent['event']['type'], callback: EventCallback): void;
|
|
158
197
|
off(eventType: IncomingGameEvent['event']['type'], callback: EventCallback): void;
|
|
159
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Listen for the host starting play: a replay after game over, or — for level
|
|
200
|
+
* games — a host-directed level via `data.levelIndex`. `data` may be omitted
|
|
201
|
+
* for a plain restart.
|
|
202
|
+
*/
|
|
203
|
+
onPlay(callback: (data?: PlayAgainEvent['data']) => void): void;
|
|
204
|
+
/** Alias of {@link onPlay}. */
|
|
205
|
+
onPlayAgain(callback: (data?: PlayAgainEvent['data']) => void): void;
|
|
160
206
|
onToggleMute(callback: (data: ToggleMuteEvent['data']) => void): void;
|
|
161
207
|
onGameStateUpdated(callback: (data: GameStateUpdatedEvent['data']) => void): void;
|
|
162
208
|
onGameInfo(callback: (data: GameInfoEvent['data']) => void): void;
|
|
@@ -170,6 +216,18 @@ declare class RemixSDK {
|
|
|
170
216
|
get players(): Player[] | undefined;
|
|
171
217
|
get player(): Player | undefined;
|
|
172
218
|
get isReady(): boolean;
|
|
219
|
+
/** True when the host configured this game with a fixed level count. */
|
|
220
|
+
get isLevelBased(): boolean;
|
|
221
|
+
/** Total levels for level-based games (from host metadata). */
|
|
222
|
+
get levelCount(): number | undefined;
|
|
223
|
+
/** 1-based level index from score-derived progression, defaulting to 1. */
|
|
224
|
+
get currentLevelIndex(): number;
|
|
225
|
+
/** Best stars per level from score-derived progression. Keys are 1-based level indices. */
|
|
226
|
+
get levelStars(): Record<string, LevelStars>;
|
|
227
|
+
/** Highest unlocked level from score-derived progression, defaulting to 1. */
|
|
228
|
+
get highestUnlockedLevel(): number;
|
|
229
|
+
/** Sum of best stars across all completed levels. */
|
|
230
|
+
get totalStars(): number;
|
|
173
231
|
ready: () => Promise<GameInfo>;
|
|
174
232
|
purchase: (data: PurchaseEvent["data"]) => Promise<PurchaseCompleteEvent["data"]>;
|
|
175
233
|
reportError: (data: GameErrorEvent["data"]) => void;
|
|
@@ -207,4 +265,4 @@ declare class RemixSDK {
|
|
|
207
265
|
}
|
|
208
266
|
declare const sdk: RemixSDK;
|
|
209
267
|
|
|
210
|
-
export { type GameErrorEvent, type GameEvent, type GameEventMessage, type GameInfo, type GameInfoEvent, type GameState, type GameStateUpdatedEvent, type HapticFeedbackEvent, type HapticFeedbackType, type IncomingGameEvent, type InventoryItem, type MultiplayerGameOverEvent, type MultiplayerSaveGameStateEvent, type OutgoingGameEvent, type PlayAgainEvent, type Player, type PurchaseCompleteEvent, type PurchaseEvent, type ReadyEvent, type RefuteGameStateEvent, RemixSDK, type SafeAreaInset, type SaveGameStateEvent, type ShopItem, type SinglePlayerGameOverEvent, type ToggleMuteEvent, type ViewContext, ZERO_SAFE_AREA_INSET, sdk };
|
|
268
|
+
export { type GameErrorEvent, type GameEvent, type GameEventMessage, type GameInfo, type GameInfoEvent, type GameState, type GameStateUpdatedEvent, type HapticFeedbackEvent, type HapticFeedbackType, type IncomingGameEvent, type InventoryItem, type LevelAttempt, type LevelAttemptStars, type LevelProgressState, type LevelStars, type MultiplayerGameOverEvent, type MultiplayerSaveGameStateEvent, type OutgoingGameEvent, type PlayAgainEvent, type Player, type PurchaseCompleteEvent, type PurchaseEvent, type ReadyEvent, type RefuteGameStateEvent, RemixSDK, type SafeAreaInset, type SaveGameStateEvent, type ShopItem, type SinglePlayerGameOverEvent, type ToggleMuteEvent, type ViewContext, ZERO_SAFE_AREA_INSET, sdk };
|