@oasiz/sdk 1.0.1 → 1.1.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/dist/index.d.cts CHANGED
@@ -1,256 +1,68 @@
1
- /**
2
- * Intensity level for native haptic feedback.
3
- *
4
- * | Type | Use case |
5
- * |-------------|-------------------------------------------------|
6
- * | `"light"` | UI button taps, menu navigation, D-pad press |
7
- * | `"medium"` | Collecting items, standard collisions, scoring |
8
- * | `"heavy"` | Explosions, major impacts, screen shake |
9
- * | `"success"` | Level complete, achievement unlocked |
10
- * | `"error"` | Damage taken, game over, invalid action |
11
- *
12
- * @category Haptics
13
- */
14
1
  type HapticType = "light" | "medium" | "heavy" | "success" | "error";
15
- /**
16
- * A plain JSON-serializable object used for cross-session game state
17
- * persistence.
18
- *
19
- * @category State
20
- */
2
+ interface ScoreAnchor {
3
+ raw: number;
4
+ normalized: 100 | 300 | 600 | 950;
5
+ }
6
+ interface ScoreConfig {
7
+ anchors: [ScoreAnchor, ScoreAnchor, ScoreAnchor, ScoreAnchor];
8
+ }
21
9
  type GameState = Record<string, unknown>;
22
10
 
23
- /**
24
- * Trigger native haptic feedback on the player's device.
25
- *
26
- * Always guard calls with the user's haptics preference toggle.
27
- * The bridge is a no-op in local development (a console warning is logged).
28
- *
29
- * @param type - The haptic intensity level.
30
- *
31
- * @example
32
- * ```ts
33
- * // UI button tap
34
- * oasiz.triggerHaptic("light");
35
- *
36
- * // Tiered hit feedback
37
- * oasiz.triggerHaptic(isPerfectHit ? "success" : "medium");
38
- *
39
- * // Game over
40
- * oasiz.triggerHaptic("error");
41
- * ```
42
- *
43
- * @category Haptics
44
- */
45
11
  declare function triggerHaptic(type: HapticType): void;
46
12
 
13
+ interface ShareRoomCodeOptions {
14
+ inviteOverride?: boolean;
15
+ }
47
16
  /**
48
- * Notify the platform of the active multiplayer room so friends can join
49
- * via the invite system. Pass `null` when leaving a room.
50
- *
51
- * @param roomCode - The room code string, or `null` to clear.
52
- *
53
- * @example
54
- * ```ts
55
- * import { insertCoin, getRoomCode } from "playroomkit";
56
- *
57
- * await insertCoin({ skipLobby: true });
58
- * oasiz.shareRoomCode(getRoomCode());
59
- *
60
- * // On disconnect
61
- * oasiz.shareRoomCode(null);
62
- * ```
63
- *
64
- * @category Multiplayer
17
+ * Notify the platform of the active multiplayer room so friends can join.
18
+ * Pass `{ inviteOverride: true }` when the game wants to hide the platform
19
+ * invite pill and own the invite UI itself.
65
20
  */
66
- declare function shareRoomCode(roomCode: string | null): void;
21
+ declare function shareRoomCode(roomCode: string | null, options?: ShareRoomCodeOptions): void;
67
22
  /**
68
- * Get the platform's internal game ID, injected before the game loads.
69
- *
70
- * @returns The game ID string, or `undefined` if not yet injected.
71
- *
72
- * @category Multiplayer
23
+ * Ask the platform to open the invite-friends modal for the current game room.
24
+ * Only has effect when the platform has a room code (game has called shareRoomCode).
25
+ * No-op when the bridge is unavailable (e.g. local development).
73
26
  */
27
+ declare function openInviteModal(): void;
74
28
  declare function getGameId(): string | undefined;
75
- /**
76
- * Get the pre-filled room code for auto-joining a friend's multiplayer session.
77
- *
78
- * @returns The room code string, or `undefined` if not in a multiplayer context.
79
- *
80
- * @category Multiplayer
81
- */
82
29
  declare function getRoomCode(): string | undefined;
83
- /**
84
- * Get the current player's display name, injected by the platform.
85
- *
86
- * @returns The player name, or `undefined` if not available.
87
- *
88
- * @category Multiplayer
89
- */
90
30
  declare function getPlayerName(): string | undefined;
91
- /**
92
- * Get the current player's avatar URL, injected by the platform.
93
- *
94
- * @returns The avatar URL string, or `undefined` if not available.
95
- *
96
- * @category Multiplayer
97
- */
98
31
  declare function getPlayerAvatar(): string | undefined;
99
32
 
100
- /**
101
- * Submit the player's score.
102
- *
103
- * The platform handles leaderboard persistence — do not track high scores locally.
104
- *
105
- * - `score` must be a finite number. Floats are floored, negatives are clamped to 0.
106
- * - In development mode a console warning is logged when the bridge is unavailable.
107
- *
108
- * @param score - The player's score (non-negative integer).
109
- *
110
- * @example
111
- * ```ts
112
- * oasiz.submitScore(Math.floor(this.score));
113
- * ```
114
- *
115
- * @category Score
116
- */
117
33
  declare function submitScore(score: number): void;
34
+ declare function emitScoreConfig(config: ScoreConfig): void;
118
35
 
119
- /**
120
- * Load the player's persisted game state.
121
- *
122
- * Returns the saved state synchronously. Returns `{}` if no state has been
123
- * saved yet or if the bridge is unavailable. Always validate the shape of
124
- * the returned data — it may be empty on first play.
125
- *
126
- * Call once at the start of the game.
127
- *
128
- * @returns The player's saved {@link GameState}, or an empty object.
129
- *
130
- * @example
131
- * ```ts
132
- * const state = oasiz.loadGameState();
133
- * this.level = typeof state.level === "number" ? state.level : 1;
134
- * ```
135
- *
136
- * @category State
137
- */
138
36
  declare function loadGameState(): GameState;
139
- /**
140
- * Queue a debounced save of the player's game state.
141
- *
142
- * Saves are batched automatically — call freely at checkpoints without
143
- * worrying about request spam. State must be a plain JSON-serializable object.
144
- *
145
- * @param state - A plain object to persist. Do not pass arrays or primitives.
146
- *
147
- * @example
148
- * ```ts
149
- * oasiz.saveGameState({
150
- * level: this.level,
151
- * lifetimeHits: this.lifetimeHits,
152
- * unlockedSkins: this.unlockedSkins,
153
- * });
154
- * ```
155
- *
156
- * @category State
157
- */
158
37
  declare function saveGameState(state: GameState): void;
159
- /**
160
- * Force an immediate write of the pending game state, bypassing the debounce.
161
- *
162
- * Use at critical checkpoints like game over or before the page unloads
163
- * to ensure data is persisted.
164
- *
165
- * @example
166
- * ```ts
167
- * oasiz.saveGameState({ level: this.level });
168
- * oasiz.flushGameState(); // ensure it lands before the page closes
169
- * oasiz.submitScore(this.score);
170
- * ```
171
- *
172
- * @category State
173
- */
174
38
  declare function flushGameState(): void;
175
39
 
176
- /**
177
- * A function that removes an event listener when called.
178
- * Returned by {@link onPause} and {@link onResume}.
179
- *
180
- * @category Lifecycle
181
- */
182
40
  type Unsubscribe = () => void;
183
- /**
184
- * Register a callback that fires when the app goes to the background.
185
- *
186
- * Use this to pause game loops, audio, and animations so the game
187
- * doesn't continue running while the player is away.
188
- *
189
- * @param callback - Invoked when the platform dispatches `oasiz:pause`.
190
- * @returns An {@link Unsubscribe} function that removes the listener.
191
- *
192
- * @example
193
- * ```ts
194
- * const off = oasiz.onPause(() => {
195
- * this.gameLoop.stop();
196
- * this.bgMusic.pause();
197
- * });
198
- *
199
- * // Later, clean up:
200
- * off();
201
- * ```
202
- *
203
- * @category Lifecycle
204
- */
205
41
  declare function onPause(callback: () => void): Unsubscribe;
206
- /**
207
- * Register a callback that fires when the app returns to the foreground.
208
- *
209
- * Use this to resume game loops, audio, and animations after a pause.
210
- *
211
- * @param callback - Invoked when the platform dispatches `oasiz:resume`.
212
- * @returns An {@link Unsubscribe} function that removes the listener.
213
- *
214
- * @example
215
- * ```ts
216
- * const off = oasiz.onResume(() => {
217
- * this.gameLoop.start();
218
- * this.bgMusic.play();
219
- * });
220
- *
221
- * // Later, clean up:
222
- * off();
223
- * ```
224
- *
225
- * @category Lifecycle
226
- */
227
42
  declare function onResume(callback: () => void): Unsubscribe;
228
43
 
229
- /**
230
- * The main SDK namespace object. Provides convenient access to all
231
- * platform bridge APIs as a single import.
232
- *
233
- * @example
234
- * ```ts
235
- * import { oasiz } from "@oasiz/sdk";
236
- *
237
- * oasiz.triggerHaptic("medium");
238
- * oasiz.submitScore(score);
239
- * ```
240
- */
44
+ declare function onBackButton(callback: () => void): Unsubscribe;
45
+ declare function onLeaveGame(callback: () => void): Unsubscribe;
46
+ declare function leaveGame(): void;
47
+
241
48
  declare const oasiz: {
242
49
  submitScore: typeof submitScore;
50
+ emitScoreConfig: typeof emitScoreConfig;
243
51
  triggerHaptic: typeof triggerHaptic;
244
52
  loadGameState: typeof loadGameState;
245
53
  saveGameState: typeof saveGameState;
246
54
  flushGameState: typeof flushGameState;
247
55
  shareRoomCode: typeof shareRoomCode;
56
+ openInviteModal: typeof openInviteModal;
248
57
  onPause: typeof onPause;
249
58
  onResume: typeof onResume;
59
+ onBackButton: typeof onBackButton;
60
+ onLeaveGame: typeof onLeaveGame;
61
+ leaveGame: typeof leaveGame;
250
62
  readonly gameId: string | undefined;
251
63
  readonly roomCode: string | undefined;
252
64
  readonly playerName: string | undefined;
253
65
  readonly playerAvatar: string | undefined;
254
66
  };
255
67
 
256
- export { type GameState, type HapticType, type Unsubscribe, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, loadGameState, oasiz, onPause, onResume, saveGameState, shareRoomCode, submitScore, triggerHaptic };
68
+ export { type GameState, type HapticType, type ScoreAnchor, type ScoreConfig, type ShareRoomCodeOptions, type Unsubscribe, emitScoreConfig, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, openInviteModal, saveGameState, shareRoomCode, submitScore, triggerHaptic };
package/dist/index.d.ts CHANGED
@@ -1,256 +1,68 @@
1
- /**
2
- * Intensity level for native haptic feedback.
3
- *
4
- * | Type | Use case |
5
- * |-------------|-------------------------------------------------|
6
- * | `"light"` | UI button taps, menu navigation, D-pad press |
7
- * | `"medium"` | Collecting items, standard collisions, scoring |
8
- * | `"heavy"` | Explosions, major impacts, screen shake |
9
- * | `"success"` | Level complete, achievement unlocked |
10
- * | `"error"` | Damage taken, game over, invalid action |
11
- *
12
- * @category Haptics
13
- */
14
1
  type HapticType = "light" | "medium" | "heavy" | "success" | "error";
15
- /**
16
- * A plain JSON-serializable object used for cross-session game state
17
- * persistence.
18
- *
19
- * @category State
20
- */
2
+ interface ScoreAnchor {
3
+ raw: number;
4
+ normalized: 100 | 300 | 600 | 950;
5
+ }
6
+ interface ScoreConfig {
7
+ anchors: [ScoreAnchor, ScoreAnchor, ScoreAnchor, ScoreAnchor];
8
+ }
21
9
  type GameState = Record<string, unknown>;
22
10
 
23
- /**
24
- * Trigger native haptic feedback on the player's device.
25
- *
26
- * Always guard calls with the user's haptics preference toggle.
27
- * The bridge is a no-op in local development (a console warning is logged).
28
- *
29
- * @param type - The haptic intensity level.
30
- *
31
- * @example
32
- * ```ts
33
- * // UI button tap
34
- * oasiz.triggerHaptic("light");
35
- *
36
- * // Tiered hit feedback
37
- * oasiz.triggerHaptic(isPerfectHit ? "success" : "medium");
38
- *
39
- * // Game over
40
- * oasiz.triggerHaptic("error");
41
- * ```
42
- *
43
- * @category Haptics
44
- */
45
11
  declare function triggerHaptic(type: HapticType): void;
46
12
 
13
+ interface ShareRoomCodeOptions {
14
+ inviteOverride?: boolean;
15
+ }
47
16
  /**
48
- * Notify the platform of the active multiplayer room so friends can join
49
- * via the invite system. Pass `null` when leaving a room.
50
- *
51
- * @param roomCode - The room code string, or `null` to clear.
52
- *
53
- * @example
54
- * ```ts
55
- * import { insertCoin, getRoomCode } from "playroomkit";
56
- *
57
- * await insertCoin({ skipLobby: true });
58
- * oasiz.shareRoomCode(getRoomCode());
59
- *
60
- * // On disconnect
61
- * oasiz.shareRoomCode(null);
62
- * ```
63
- *
64
- * @category Multiplayer
17
+ * Notify the platform of the active multiplayer room so friends can join.
18
+ * Pass `{ inviteOverride: true }` when the game wants to hide the platform
19
+ * invite pill and own the invite UI itself.
65
20
  */
66
- declare function shareRoomCode(roomCode: string | null): void;
21
+ declare function shareRoomCode(roomCode: string | null, options?: ShareRoomCodeOptions): void;
67
22
  /**
68
- * Get the platform's internal game ID, injected before the game loads.
69
- *
70
- * @returns The game ID string, or `undefined` if not yet injected.
71
- *
72
- * @category Multiplayer
23
+ * Ask the platform to open the invite-friends modal for the current game room.
24
+ * Only has effect when the platform has a room code (game has called shareRoomCode).
25
+ * No-op when the bridge is unavailable (e.g. local development).
73
26
  */
27
+ declare function openInviteModal(): void;
74
28
  declare function getGameId(): string | undefined;
75
- /**
76
- * Get the pre-filled room code for auto-joining a friend's multiplayer session.
77
- *
78
- * @returns The room code string, or `undefined` if not in a multiplayer context.
79
- *
80
- * @category Multiplayer
81
- */
82
29
  declare function getRoomCode(): string | undefined;
83
- /**
84
- * Get the current player's display name, injected by the platform.
85
- *
86
- * @returns The player name, or `undefined` if not available.
87
- *
88
- * @category Multiplayer
89
- */
90
30
  declare function getPlayerName(): string | undefined;
91
- /**
92
- * Get the current player's avatar URL, injected by the platform.
93
- *
94
- * @returns The avatar URL string, or `undefined` if not available.
95
- *
96
- * @category Multiplayer
97
- */
98
31
  declare function getPlayerAvatar(): string | undefined;
99
32
 
100
- /**
101
- * Submit the player's score.
102
- *
103
- * The platform handles leaderboard persistence — do not track high scores locally.
104
- *
105
- * - `score` must be a finite number. Floats are floored, negatives are clamped to 0.
106
- * - In development mode a console warning is logged when the bridge is unavailable.
107
- *
108
- * @param score - The player's score (non-negative integer).
109
- *
110
- * @example
111
- * ```ts
112
- * oasiz.submitScore(Math.floor(this.score));
113
- * ```
114
- *
115
- * @category Score
116
- */
117
33
  declare function submitScore(score: number): void;
34
+ declare function emitScoreConfig(config: ScoreConfig): void;
118
35
 
119
- /**
120
- * Load the player's persisted game state.
121
- *
122
- * Returns the saved state synchronously. Returns `{}` if no state has been
123
- * saved yet or if the bridge is unavailable. Always validate the shape of
124
- * the returned data — it may be empty on first play.
125
- *
126
- * Call once at the start of the game.
127
- *
128
- * @returns The player's saved {@link GameState}, or an empty object.
129
- *
130
- * @example
131
- * ```ts
132
- * const state = oasiz.loadGameState();
133
- * this.level = typeof state.level === "number" ? state.level : 1;
134
- * ```
135
- *
136
- * @category State
137
- */
138
36
  declare function loadGameState(): GameState;
139
- /**
140
- * Queue a debounced save of the player's game state.
141
- *
142
- * Saves are batched automatically — call freely at checkpoints without
143
- * worrying about request spam. State must be a plain JSON-serializable object.
144
- *
145
- * @param state - A plain object to persist. Do not pass arrays or primitives.
146
- *
147
- * @example
148
- * ```ts
149
- * oasiz.saveGameState({
150
- * level: this.level,
151
- * lifetimeHits: this.lifetimeHits,
152
- * unlockedSkins: this.unlockedSkins,
153
- * });
154
- * ```
155
- *
156
- * @category State
157
- */
158
37
  declare function saveGameState(state: GameState): void;
159
- /**
160
- * Force an immediate write of the pending game state, bypassing the debounce.
161
- *
162
- * Use at critical checkpoints like game over or before the page unloads
163
- * to ensure data is persisted.
164
- *
165
- * @example
166
- * ```ts
167
- * oasiz.saveGameState({ level: this.level });
168
- * oasiz.flushGameState(); // ensure it lands before the page closes
169
- * oasiz.submitScore(this.score);
170
- * ```
171
- *
172
- * @category State
173
- */
174
38
  declare function flushGameState(): void;
175
39
 
176
- /**
177
- * A function that removes an event listener when called.
178
- * Returned by {@link onPause} and {@link onResume}.
179
- *
180
- * @category Lifecycle
181
- */
182
40
  type Unsubscribe = () => void;
183
- /**
184
- * Register a callback that fires when the app goes to the background.
185
- *
186
- * Use this to pause game loops, audio, and animations so the game
187
- * doesn't continue running while the player is away.
188
- *
189
- * @param callback - Invoked when the platform dispatches `oasiz:pause`.
190
- * @returns An {@link Unsubscribe} function that removes the listener.
191
- *
192
- * @example
193
- * ```ts
194
- * const off = oasiz.onPause(() => {
195
- * this.gameLoop.stop();
196
- * this.bgMusic.pause();
197
- * });
198
- *
199
- * // Later, clean up:
200
- * off();
201
- * ```
202
- *
203
- * @category Lifecycle
204
- */
205
41
  declare function onPause(callback: () => void): Unsubscribe;
206
- /**
207
- * Register a callback that fires when the app returns to the foreground.
208
- *
209
- * Use this to resume game loops, audio, and animations after a pause.
210
- *
211
- * @param callback - Invoked when the platform dispatches `oasiz:resume`.
212
- * @returns An {@link Unsubscribe} function that removes the listener.
213
- *
214
- * @example
215
- * ```ts
216
- * const off = oasiz.onResume(() => {
217
- * this.gameLoop.start();
218
- * this.bgMusic.play();
219
- * });
220
- *
221
- * // Later, clean up:
222
- * off();
223
- * ```
224
- *
225
- * @category Lifecycle
226
- */
227
42
  declare function onResume(callback: () => void): Unsubscribe;
228
43
 
229
- /**
230
- * The main SDK namespace object. Provides convenient access to all
231
- * platform bridge APIs as a single import.
232
- *
233
- * @example
234
- * ```ts
235
- * import { oasiz } from "@oasiz/sdk";
236
- *
237
- * oasiz.triggerHaptic("medium");
238
- * oasiz.submitScore(score);
239
- * ```
240
- */
44
+ declare function onBackButton(callback: () => void): Unsubscribe;
45
+ declare function onLeaveGame(callback: () => void): Unsubscribe;
46
+ declare function leaveGame(): void;
47
+
241
48
  declare const oasiz: {
242
49
  submitScore: typeof submitScore;
50
+ emitScoreConfig: typeof emitScoreConfig;
243
51
  triggerHaptic: typeof triggerHaptic;
244
52
  loadGameState: typeof loadGameState;
245
53
  saveGameState: typeof saveGameState;
246
54
  flushGameState: typeof flushGameState;
247
55
  shareRoomCode: typeof shareRoomCode;
56
+ openInviteModal: typeof openInviteModal;
248
57
  onPause: typeof onPause;
249
58
  onResume: typeof onResume;
59
+ onBackButton: typeof onBackButton;
60
+ onLeaveGame: typeof onLeaveGame;
61
+ leaveGame: typeof leaveGame;
250
62
  readonly gameId: string | undefined;
251
63
  readonly roomCode: string | undefined;
252
64
  readonly playerName: string | undefined;
253
65
  readonly playerAvatar: string | undefined;
254
66
  };
255
67
 
256
- export { type GameState, type HapticType, type Unsubscribe, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, loadGameState, oasiz, onPause, onResume, saveGameState, shareRoomCode, submitScore, triggerHaptic };
68
+ export { type GameState, type HapticType, type ScoreAnchor, type ScoreConfig, type ShareRoomCodeOptions, type Unsubscribe, emitScoreConfig, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, openInviteModal, saveGameState, shareRoomCode, submitScore, triggerHaptic };