@oasiz/sdk 1.0.1 → 1.0.2
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 +176 -33
- package/dist/index.cjs +89 -0
- package/dist/index.d.cts +17 -220
- package/dist/index.d.ts +17 -220
- package/dist/index.js +85 -0
- package/package.json +4 -8
- package/dist/index.global.js +0 -252
package/dist/index.d.cts
CHANGED
|
@@ -1,245 +1,39 @@
|
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
|
47
|
-
/**
|
|
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
|
|
65
|
-
*/
|
|
66
13
|
declare function shareRoomCode(roomCode: string | null): void;
|
|
67
|
-
/**
|
|
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
|
|
73
|
-
*/
|
|
74
14
|
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
15
|
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
16
|
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
17
|
declare function getPlayerAvatar(): string | undefined;
|
|
99
18
|
|
|
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
19
|
declare function submitScore(score: number): void;
|
|
20
|
+
declare function emitScoreConfig(config: ScoreConfig): void;
|
|
118
21
|
|
|
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
22
|
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
23
|
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
24
|
declare function flushGameState(): void;
|
|
175
25
|
|
|
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
26
|
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
27
|
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
28
|
declare function onResume(callback: () => void): Unsubscribe;
|
|
228
29
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
* @example
|
|
234
|
-
* ```ts
|
|
235
|
-
* import { oasiz } from "@oasiz/sdk";
|
|
236
|
-
*
|
|
237
|
-
* oasiz.triggerHaptic("medium");
|
|
238
|
-
* oasiz.submitScore(score);
|
|
239
|
-
* ```
|
|
240
|
-
*/
|
|
30
|
+
declare function onBackButton(callback: () => void): Unsubscribe;
|
|
31
|
+
declare function onLeaveGame(callback: () => void): Unsubscribe;
|
|
32
|
+
declare function leaveGame(): void;
|
|
33
|
+
|
|
241
34
|
declare const oasiz: {
|
|
242
35
|
submitScore: typeof submitScore;
|
|
36
|
+
emitScoreConfig: typeof emitScoreConfig;
|
|
243
37
|
triggerHaptic: typeof triggerHaptic;
|
|
244
38
|
loadGameState: typeof loadGameState;
|
|
245
39
|
saveGameState: typeof saveGameState;
|
|
@@ -247,10 +41,13 @@ declare const oasiz: {
|
|
|
247
41
|
shareRoomCode: typeof shareRoomCode;
|
|
248
42
|
onPause: typeof onPause;
|
|
249
43
|
onResume: typeof onResume;
|
|
44
|
+
onBackButton: typeof onBackButton;
|
|
45
|
+
onLeaveGame: typeof onLeaveGame;
|
|
46
|
+
leaveGame: typeof leaveGame;
|
|
250
47
|
readonly gameId: string | undefined;
|
|
251
48
|
readonly roomCode: string | undefined;
|
|
252
49
|
readonly playerName: string | undefined;
|
|
253
50
|
readonly playerAvatar: string | undefined;
|
|
254
51
|
};
|
|
255
52
|
|
|
256
|
-
export { type GameState, type HapticType, type Unsubscribe, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, loadGameState, oasiz, onPause, onResume, saveGameState, shareRoomCode, submitScore, triggerHaptic };
|
|
53
|
+
export { type GameState, type HapticType, type ScoreAnchor, type ScoreConfig, type Unsubscribe, emitScoreConfig, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, saveGameState, shareRoomCode, submitScore, triggerHaptic };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,245 +1,39 @@
|
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
|
47
|
-
/**
|
|
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
|
|
65
|
-
*/
|
|
66
13
|
declare function shareRoomCode(roomCode: string | null): void;
|
|
67
|
-
/**
|
|
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
|
|
73
|
-
*/
|
|
74
14
|
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
15
|
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
16
|
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
17
|
declare function getPlayerAvatar(): string | undefined;
|
|
99
18
|
|
|
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
19
|
declare function submitScore(score: number): void;
|
|
20
|
+
declare function emitScoreConfig(config: ScoreConfig): void;
|
|
118
21
|
|
|
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
22
|
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
23
|
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
24
|
declare function flushGameState(): void;
|
|
175
25
|
|
|
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
26
|
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
27
|
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
28
|
declare function onResume(callback: () => void): Unsubscribe;
|
|
228
29
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
* @example
|
|
234
|
-
* ```ts
|
|
235
|
-
* import { oasiz } from "@oasiz/sdk";
|
|
236
|
-
*
|
|
237
|
-
* oasiz.triggerHaptic("medium");
|
|
238
|
-
* oasiz.submitScore(score);
|
|
239
|
-
* ```
|
|
240
|
-
*/
|
|
30
|
+
declare function onBackButton(callback: () => void): Unsubscribe;
|
|
31
|
+
declare function onLeaveGame(callback: () => void): Unsubscribe;
|
|
32
|
+
declare function leaveGame(): void;
|
|
33
|
+
|
|
241
34
|
declare const oasiz: {
|
|
242
35
|
submitScore: typeof submitScore;
|
|
36
|
+
emitScoreConfig: typeof emitScoreConfig;
|
|
243
37
|
triggerHaptic: typeof triggerHaptic;
|
|
244
38
|
loadGameState: typeof loadGameState;
|
|
245
39
|
saveGameState: typeof saveGameState;
|
|
@@ -247,10 +41,13 @@ declare const oasiz: {
|
|
|
247
41
|
shareRoomCode: typeof shareRoomCode;
|
|
248
42
|
onPause: typeof onPause;
|
|
249
43
|
onResume: typeof onResume;
|
|
44
|
+
onBackButton: typeof onBackButton;
|
|
45
|
+
onLeaveGame: typeof onLeaveGame;
|
|
46
|
+
leaveGame: typeof leaveGame;
|
|
250
47
|
readonly gameId: string | undefined;
|
|
251
48
|
readonly roomCode: string | undefined;
|
|
252
49
|
readonly playerName: string | undefined;
|
|
253
50
|
readonly playerAvatar: string | undefined;
|
|
254
51
|
};
|
|
255
52
|
|
|
256
|
-
export { type GameState, type HapticType, type Unsubscribe, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, loadGameState, oasiz, onPause, onResume, saveGameState, shareRoomCode, submitScore, triggerHaptic };
|
|
53
|
+
export { type GameState, type HapticType, type ScoreAnchor, type ScoreConfig, type Unsubscribe, emitScoreConfig, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, saveGameState, shareRoomCode, submitScore, triggerHaptic };
|
package/dist/index.js
CHANGED
|
@@ -95,6 +95,14 @@ function submitScore(score) {
|
|
|
95
95
|
}
|
|
96
96
|
warnMissingBridge("submitScore");
|
|
97
97
|
}
|
|
98
|
+
function emitScoreConfig(config) {
|
|
99
|
+
const bridge = getBridgeWindow3();
|
|
100
|
+
if (typeof bridge?.emitScoreConfig === "function") {
|
|
101
|
+
bridge.emitScoreConfig(config);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
warnMissingBridge("emitScoreConfig");
|
|
105
|
+
}
|
|
98
106
|
|
|
99
107
|
// src/state.ts
|
|
100
108
|
function isDevelopment4() {
|
|
@@ -187,9 +195,79 @@ function onResume(callback) {
|
|
|
187
195
|
return addLifecycleListener("oasiz:resume", callback);
|
|
188
196
|
}
|
|
189
197
|
|
|
198
|
+
// src/navigation.ts
|
|
199
|
+
var activeBackListeners = 0;
|
|
200
|
+
function isDevelopment6() {
|
|
201
|
+
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
202
|
+
return nodeEnv !== "production";
|
|
203
|
+
}
|
|
204
|
+
function getBridgeWindow5() {
|
|
205
|
+
if (typeof window === "undefined") {
|
|
206
|
+
return void 0;
|
|
207
|
+
}
|
|
208
|
+
return window;
|
|
209
|
+
}
|
|
210
|
+
function warnMissingBridge3(methodName) {
|
|
211
|
+
if (isDevelopment6()) {
|
|
212
|
+
console.warn(
|
|
213
|
+
"[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function addNavigationListener(eventName, callback) {
|
|
218
|
+
if (typeof window === "undefined") {
|
|
219
|
+
if (isDevelopment6()) {
|
|
220
|
+
console.warn(
|
|
221
|
+
"[oasiz/sdk] " + eventName + " listener registered without a browser window. This is expected in local development."
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
return () => {
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
const handler = () => callback();
|
|
228
|
+
window.addEventListener(eventName, handler);
|
|
229
|
+
return () => window.removeEventListener(eventName, handler);
|
|
230
|
+
}
|
|
231
|
+
function onBackButton(callback) {
|
|
232
|
+
const off = addNavigationListener("oasiz:back", callback);
|
|
233
|
+
const bridge = getBridgeWindow5();
|
|
234
|
+
activeBackListeners += 1;
|
|
235
|
+
if (activeBackListeners === 1) {
|
|
236
|
+
if (typeof bridge?.__oasizSetBackOverride === "function") {
|
|
237
|
+
bridge.__oasizSetBackOverride(true);
|
|
238
|
+
} else {
|
|
239
|
+
warnMissingBridge3("__oasizSetBackOverride");
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return () => {
|
|
243
|
+
off();
|
|
244
|
+
activeBackListeners = Math.max(0, activeBackListeners - 1);
|
|
245
|
+
if (activeBackListeners === 0) {
|
|
246
|
+
const currentBridge = getBridgeWindow5();
|
|
247
|
+
if (typeof currentBridge?.__oasizSetBackOverride === "function") {
|
|
248
|
+
currentBridge.__oasizSetBackOverride(false);
|
|
249
|
+
} else {
|
|
250
|
+
warnMissingBridge3("__oasizSetBackOverride");
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function onLeaveGame(callback) {
|
|
256
|
+
return addNavigationListener("oasiz:leave", callback);
|
|
257
|
+
}
|
|
258
|
+
function leaveGame() {
|
|
259
|
+
const bridge = getBridgeWindow5();
|
|
260
|
+
if (typeof bridge?.__oasizLeaveGame === "function") {
|
|
261
|
+
bridge.__oasizLeaveGame();
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
warnMissingBridge3("__oasizLeaveGame");
|
|
265
|
+
}
|
|
266
|
+
|
|
190
267
|
// src/index.ts
|
|
191
268
|
var oasiz = {
|
|
192
269
|
submitScore,
|
|
270
|
+
emitScoreConfig,
|
|
193
271
|
triggerHaptic,
|
|
194
272
|
loadGameState,
|
|
195
273
|
saveGameState,
|
|
@@ -197,6 +275,9 @@ var oasiz = {
|
|
|
197
275
|
shareRoomCode,
|
|
198
276
|
onPause,
|
|
199
277
|
onResume,
|
|
278
|
+
onBackButton,
|
|
279
|
+
onLeaveGame,
|
|
280
|
+
leaveGame,
|
|
200
281
|
get gameId() {
|
|
201
282
|
return getGameId();
|
|
202
283
|
},
|
|
@@ -211,13 +292,17 @@ var oasiz = {
|
|
|
211
292
|
}
|
|
212
293
|
};
|
|
213
294
|
export {
|
|
295
|
+
emitScoreConfig,
|
|
214
296
|
flushGameState,
|
|
215
297
|
getGameId,
|
|
216
298
|
getPlayerAvatar,
|
|
217
299
|
getPlayerName,
|
|
218
300
|
getRoomCode,
|
|
301
|
+
leaveGame,
|
|
219
302
|
loadGameState,
|
|
220
303
|
oasiz,
|
|
304
|
+
onBackButton,
|
|
305
|
+
onLeaveGame,
|
|
221
306
|
onPause,
|
|
222
307
|
onResume,
|
|
223
308
|
saveGameState,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oasiz/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Typed SDK for Oasiz game platform bridge APIs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"import": "./dist/index.js",
|
|
13
|
-
"require": "./dist/index.cjs"
|
|
14
|
-
"script": "./dist/index.global.js"
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
15
14
|
}
|
|
16
15
|
},
|
|
17
16
|
"files": [
|
|
@@ -19,11 +18,9 @@
|
|
|
19
18
|
],
|
|
20
19
|
"sideEffects": false,
|
|
21
20
|
"scripts": {
|
|
22
|
-
"build": "tsup src/index.ts --format esm,cjs
|
|
21
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
23
22
|
"prepack": "bun run build",
|
|
24
|
-
"test": "node --experimental-strip-types --test ./tests/**/*.test.ts"
|
|
25
|
-
"docs": "typedoc",
|
|
26
|
-
"docs:watch": "typedoc --watch"
|
|
23
|
+
"test": "node --experimental-strip-types --test ./tests/**/*.test.ts"
|
|
27
24
|
},
|
|
28
25
|
"publishConfig": {
|
|
29
26
|
"access": "public"
|
|
@@ -50,7 +47,6 @@
|
|
|
50
47
|
"@types/node": "^25.3.0",
|
|
51
48
|
"semantic-release": "^25.0.3",
|
|
52
49
|
"tsup": "^8.5.1",
|
|
53
|
-
"typedoc": "^0.28.17",
|
|
54
50
|
"typescript": "^5.9.3"
|
|
55
51
|
}
|
|
56
52
|
}
|