@oasiz/sdk 1.5.3 → 1.5.4

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
@@ -25,6 +25,107 @@ interface ShareRequest {
25
25
  score?: number;
26
26
  text?: string;
27
27
  }
28
+ /**
29
+ * One frame in a texture atlas. Coordinates are in pixels, top-left origin
30
+ * (matches HTML canvas / WebGL texture coordinates after Y-flip).
31
+ */
32
+ interface TextureAtlasFrame {
33
+ name: string;
34
+ x: number;
35
+ y: number;
36
+ width: number;
37
+ height: number;
38
+ }
39
+ /**
40
+ * Per-direction frame indexes inside an animation. `left` is either an
41
+ * integer index or the literal string `"mirror"`, indicating the renderer
42
+ * should mirror the right-facing frame instead of using a dedicated one.
43
+ */
44
+ interface FacingFrameMap {
45
+ front: number;
46
+ back: number;
47
+ right: number;
48
+ left: number | "mirror";
49
+ }
50
+ /**
51
+ * One named animation in a texture atlas. `frames` is the playback-ordered
52
+ * list of frame names; resolve each name against the parent atlas's
53
+ * `frames` array to get pixel coordinates.
54
+ */
55
+ interface TextureAtlasAnimation {
56
+ animationId: string;
57
+ role: string | null;
58
+ group: string | null;
59
+ direction: string | null;
60
+ frameRate: number;
61
+ frames: string[];
62
+ facingFrameMap: FacingFrameMap | null;
63
+ }
64
+ /**
65
+ * TexturePacker / Phaser-style texture atlas describing a baked sprite
66
+ * image. Drop-in compatible with Phaser via `addAtlas(key, img, atlas)`
67
+ * after a tiny shape transform; usable directly in custom GL renderers.
68
+ */
69
+ interface TextureAtlas {
70
+ imageUrl: string;
71
+ imageWidth: number;
72
+ imageHeight: number;
73
+ frames: TextureAtlasFrame[];
74
+ animations: TextureAtlasAnimation[];
75
+ }
76
+ /**
77
+ * The authenticated player's character, returned by `getPlayerCharacter()`.
78
+ * `editorTextureAtlas` is the higher-detail variant intended for character
79
+ * previews / customizer UI and may be `null`.
80
+ */
81
+ interface PlayerCharacter {
82
+ characterName: string | null;
83
+ baseCharacterId: string;
84
+ compositionCode: string;
85
+ textureAtlas: TextureAtlas;
86
+ editorTextureAtlas: TextureAtlas | null;
87
+ }
88
+ /**
89
+ * Result of `addScore(delta)` / `setScore(score)`. Returns `null` when the
90
+ * host bridge is unavailable (e.g. local development) or when the backend
91
+ * refused the request; production code should treat `null` as "no change
92
+ * was persisted, do not update local UI".
93
+ */
94
+ interface ScoreEditResult {
95
+ playerId: string;
96
+ previousScore: number;
97
+ newScore: number;
98
+ previousWeeklyScore: number;
99
+ newWeeklyScore: number;
100
+ normalizedScore: number | null;
101
+ }
102
+
103
+ /**
104
+ * Fetch the authenticated player's character, including a TexturePacker /
105
+ * Phaser-style texture atlas describing the baked sprite image.
106
+ *
107
+ * Returns:
108
+ * - `null` when the user has no character composition yet, OR
109
+ * - `null` when the host bridge is unavailable (local dev / unauthenticated)
110
+ *
111
+ * The host transparently caches and proxies to `GET /api/sdk/me/character`,
112
+ * so calling this multiple times in a session is cheap. The returned
113
+ * `imageUrl` is content-addressed (R2 key derives from the composition
114
+ * hash), so games can safely cache the downloaded texture by `compositionCode`.
115
+ *
116
+ * Example (Phaser):
117
+ *
118
+ * const character = await oasiz.getPlayerCharacter();
119
+ * if (!character) return;
120
+ * const atlas = character.textureAtlas;
121
+ * scene.load.image("player-tex", atlas.imageUrl);
122
+ * scene.load.atlas("player", atlas.imageUrl, {
123
+ * frames: Object.fromEntries(
124
+ * atlas.frames.map((f) => [f.name, { frame: { x: f.x, y: f.y, w: f.width, h: f.height } }]),
125
+ * ),
126
+ * });
127
+ */
128
+ declare function getPlayerCharacter(): Promise<PlayerCharacter | null>;
28
129
 
29
130
  declare function triggerHaptic(type: HapticType): void;
30
131
 
@@ -47,11 +148,44 @@ declare function shareRoomCode(roomCode: string | null, options?: ShareRoomCodeO
47
148
  declare function openInviteModal(): void;
48
149
  declare function getGameId(): string | undefined;
49
150
  declare function getRoomCode(): string | undefined;
151
+ /**
152
+ * Stable, unique, opaque identifier for the authenticated player, injected
153
+ * by the platform. Safe to use as a primary key for save slots, matchmaking,
154
+ * per-player analytics, or anywhere you need a reliable per-user key —
155
+ * unlike `getPlayerName()` (mutable, not unique).
156
+ *
157
+ * Mirrors the backend's `playerId` field returned by `GET /api/sdk/me`
158
+ * (= the Better Auth `user.id`). Returns `undefined` when the platform
159
+ * has not injected an identity (e.g. unauthenticated preview).
160
+ */
161
+ declare function getPlayerId(): string | undefined;
50
162
  declare function getPlayerName(): string | undefined;
51
163
  declare function getPlayerAvatar(): string | undefined;
52
164
 
53
165
  declare function submitScore(score: number): void;
54
166
 
167
+ /**
168
+ * Add (or subtract) `delta` from the player's current score for this game.
169
+ * The new score is clamped to >= 0 server-side.
170
+ *
171
+ * Unlike `submitScore()` (which is high-water and only ever raises the
172
+ * score), this endpoint always overwrites the row. Use it for game models
173
+ * where the leaderboard tracks an accumulator, balance, or persistent state
174
+ * instead of a single best-run value.
175
+ *
176
+ * Returns the resulting score values, or `null` when the bridge is
177
+ * unavailable. The integer must be a non-zero integer (positive or negative).
178
+ */
179
+ declare function addScore(delta: number): Promise<ScoreEditResult | null>;
180
+ /**
181
+ * Force the player's score to an absolute value (clamped to >= 0).
182
+ *
183
+ * Same overwrite semantics as `addScore`. Use when the game has computed
184
+ * the authoritative score locally (e.g. after offline play) and wants to
185
+ * sync it back to the leaderboard.
186
+ */
187
+ declare function setScore(score: number): Promise<ScoreEditResult | null>;
188
+
55
189
  declare function share(options: ShareRequest): Promise<void>;
56
190
 
57
191
  declare function loadGameState(): GameState;
@@ -77,6 +211,9 @@ declare function leaveGame(): void;
77
211
 
78
212
  declare const oasiz: {
79
213
  submitScore: typeof submitScore;
214
+ addScore: typeof addScore;
215
+ setScore: typeof setScore;
216
+ getPlayerCharacter: typeof getPlayerCharacter;
80
217
  share: typeof share;
81
218
  triggerHaptic: typeof triggerHaptic;
82
219
  enableLogOverlay: typeof enableLogOverlay;
@@ -94,9 +231,10 @@ declare const oasiz: {
94
231
  leaveGame: typeof leaveGame;
95
232
  readonly gameId: string | undefined;
96
233
  readonly roomCode: string | undefined;
234
+ readonly playerId: string | undefined;
97
235
  readonly playerName: string | undefined;
98
236
  readonly playerAvatar: string | undefined;
99
237
  readonly safeAreaTop: number;
100
238
  };
101
239
 
102
- export { type GameState, type HapticType, type LogOverlayEntry, type LogOverlayHandle, type LogOverlayLevel, type LogOverlayOptions, type ShareRequest, type ShareRoomCodeOptions, type Unsubscribe, enableLogOverlay, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, getSafeAreaTop, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, openInviteModal, saveGameState, setLeaderboardVisible, share, shareRoomCode, submitScore, triggerHaptic };
240
+ export { type FacingFrameMap, type GameState, type HapticType, type LogOverlayEntry, type LogOverlayHandle, type LogOverlayLevel, type LogOverlayOptions, type PlayerCharacter, type ScoreEditResult, type ShareRequest, type ShareRoomCodeOptions, type TextureAtlas, type TextureAtlasAnimation, type TextureAtlasFrame, type Unsubscribe, addScore, enableLogOverlay, flushGameState, getGameId, getPlayerAvatar, getPlayerCharacter, getPlayerId, getPlayerName, getRoomCode, getSafeAreaTop, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, openInviteModal, saveGameState, setLeaderboardVisible, setScore, share, shareRoomCode, submitScore, triggerHaptic };
package/dist/index.d.ts CHANGED
@@ -25,6 +25,107 @@ interface ShareRequest {
25
25
  score?: number;
26
26
  text?: string;
27
27
  }
28
+ /**
29
+ * One frame in a texture atlas. Coordinates are in pixels, top-left origin
30
+ * (matches HTML canvas / WebGL texture coordinates after Y-flip).
31
+ */
32
+ interface TextureAtlasFrame {
33
+ name: string;
34
+ x: number;
35
+ y: number;
36
+ width: number;
37
+ height: number;
38
+ }
39
+ /**
40
+ * Per-direction frame indexes inside an animation. `left` is either an
41
+ * integer index or the literal string `"mirror"`, indicating the renderer
42
+ * should mirror the right-facing frame instead of using a dedicated one.
43
+ */
44
+ interface FacingFrameMap {
45
+ front: number;
46
+ back: number;
47
+ right: number;
48
+ left: number | "mirror";
49
+ }
50
+ /**
51
+ * One named animation in a texture atlas. `frames` is the playback-ordered
52
+ * list of frame names; resolve each name against the parent atlas's
53
+ * `frames` array to get pixel coordinates.
54
+ */
55
+ interface TextureAtlasAnimation {
56
+ animationId: string;
57
+ role: string | null;
58
+ group: string | null;
59
+ direction: string | null;
60
+ frameRate: number;
61
+ frames: string[];
62
+ facingFrameMap: FacingFrameMap | null;
63
+ }
64
+ /**
65
+ * TexturePacker / Phaser-style texture atlas describing a baked sprite
66
+ * image. Drop-in compatible with Phaser via `addAtlas(key, img, atlas)`
67
+ * after a tiny shape transform; usable directly in custom GL renderers.
68
+ */
69
+ interface TextureAtlas {
70
+ imageUrl: string;
71
+ imageWidth: number;
72
+ imageHeight: number;
73
+ frames: TextureAtlasFrame[];
74
+ animations: TextureAtlasAnimation[];
75
+ }
76
+ /**
77
+ * The authenticated player's character, returned by `getPlayerCharacter()`.
78
+ * `editorTextureAtlas` is the higher-detail variant intended for character
79
+ * previews / customizer UI and may be `null`.
80
+ */
81
+ interface PlayerCharacter {
82
+ characterName: string | null;
83
+ baseCharacterId: string;
84
+ compositionCode: string;
85
+ textureAtlas: TextureAtlas;
86
+ editorTextureAtlas: TextureAtlas | null;
87
+ }
88
+ /**
89
+ * Result of `addScore(delta)` / `setScore(score)`. Returns `null` when the
90
+ * host bridge is unavailable (e.g. local development) or when the backend
91
+ * refused the request; production code should treat `null` as "no change
92
+ * was persisted, do not update local UI".
93
+ */
94
+ interface ScoreEditResult {
95
+ playerId: string;
96
+ previousScore: number;
97
+ newScore: number;
98
+ previousWeeklyScore: number;
99
+ newWeeklyScore: number;
100
+ normalizedScore: number | null;
101
+ }
102
+
103
+ /**
104
+ * Fetch the authenticated player's character, including a TexturePacker /
105
+ * Phaser-style texture atlas describing the baked sprite image.
106
+ *
107
+ * Returns:
108
+ * - `null` when the user has no character composition yet, OR
109
+ * - `null` when the host bridge is unavailable (local dev / unauthenticated)
110
+ *
111
+ * The host transparently caches and proxies to `GET /api/sdk/me/character`,
112
+ * so calling this multiple times in a session is cheap. The returned
113
+ * `imageUrl` is content-addressed (R2 key derives from the composition
114
+ * hash), so games can safely cache the downloaded texture by `compositionCode`.
115
+ *
116
+ * Example (Phaser):
117
+ *
118
+ * const character = await oasiz.getPlayerCharacter();
119
+ * if (!character) return;
120
+ * const atlas = character.textureAtlas;
121
+ * scene.load.image("player-tex", atlas.imageUrl);
122
+ * scene.load.atlas("player", atlas.imageUrl, {
123
+ * frames: Object.fromEntries(
124
+ * atlas.frames.map((f) => [f.name, { frame: { x: f.x, y: f.y, w: f.width, h: f.height } }]),
125
+ * ),
126
+ * });
127
+ */
128
+ declare function getPlayerCharacter(): Promise<PlayerCharacter | null>;
28
129
 
29
130
  declare function triggerHaptic(type: HapticType): void;
30
131
 
@@ -47,11 +148,44 @@ declare function shareRoomCode(roomCode: string | null, options?: ShareRoomCodeO
47
148
  declare function openInviteModal(): void;
48
149
  declare function getGameId(): string | undefined;
49
150
  declare function getRoomCode(): string | undefined;
151
+ /**
152
+ * Stable, unique, opaque identifier for the authenticated player, injected
153
+ * by the platform. Safe to use as a primary key for save slots, matchmaking,
154
+ * per-player analytics, or anywhere you need a reliable per-user key —
155
+ * unlike `getPlayerName()` (mutable, not unique).
156
+ *
157
+ * Mirrors the backend's `playerId` field returned by `GET /api/sdk/me`
158
+ * (= the Better Auth `user.id`). Returns `undefined` when the platform
159
+ * has not injected an identity (e.g. unauthenticated preview).
160
+ */
161
+ declare function getPlayerId(): string | undefined;
50
162
  declare function getPlayerName(): string | undefined;
51
163
  declare function getPlayerAvatar(): string | undefined;
52
164
 
53
165
  declare function submitScore(score: number): void;
54
166
 
167
+ /**
168
+ * Add (or subtract) `delta` from the player's current score for this game.
169
+ * The new score is clamped to >= 0 server-side.
170
+ *
171
+ * Unlike `submitScore()` (which is high-water and only ever raises the
172
+ * score), this endpoint always overwrites the row. Use it for game models
173
+ * where the leaderboard tracks an accumulator, balance, or persistent state
174
+ * instead of a single best-run value.
175
+ *
176
+ * Returns the resulting score values, or `null` when the bridge is
177
+ * unavailable. The integer must be a non-zero integer (positive or negative).
178
+ */
179
+ declare function addScore(delta: number): Promise<ScoreEditResult | null>;
180
+ /**
181
+ * Force the player's score to an absolute value (clamped to >= 0).
182
+ *
183
+ * Same overwrite semantics as `addScore`. Use when the game has computed
184
+ * the authoritative score locally (e.g. after offline play) and wants to
185
+ * sync it back to the leaderboard.
186
+ */
187
+ declare function setScore(score: number): Promise<ScoreEditResult | null>;
188
+
55
189
  declare function share(options: ShareRequest): Promise<void>;
56
190
 
57
191
  declare function loadGameState(): GameState;
@@ -77,6 +211,9 @@ declare function leaveGame(): void;
77
211
 
78
212
  declare const oasiz: {
79
213
  submitScore: typeof submitScore;
214
+ addScore: typeof addScore;
215
+ setScore: typeof setScore;
216
+ getPlayerCharacter: typeof getPlayerCharacter;
80
217
  share: typeof share;
81
218
  triggerHaptic: typeof triggerHaptic;
82
219
  enableLogOverlay: typeof enableLogOverlay;
@@ -94,9 +231,10 @@ declare const oasiz: {
94
231
  leaveGame: typeof leaveGame;
95
232
  readonly gameId: string | undefined;
96
233
  readonly roomCode: string | undefined;
234
+ readonly playerId: string | undefined;
97
235
  readonly playerName: string | undefined;
98
236
  readonly playerAvatar: string | undefined;
99
237
  readonly safeAreaTop: number;
100
238
  };
101
239
 
102
- export { type GameState, type HapticType, type LogOverlayEntry, type LogOverlayHandle, type LogOverlayLevel, type LogOverlayOptions, type ShareRequest, type ShareRoomCodeOptions, type Unsubscribe, enableLogOverlay, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, getSafeAreaTop, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, openInviteModal, saveGameState, setLeaderboardVisible, share, shareRoomCode, submitScore, triggerHaptic };
240
+ export { type FacingFrameMap, type GameState, type HapticType, type LogOverlayEntry, type LogOverlayHandle, type LogOverlayLevel, type LogOverlayOptions, type PlayerCharacter, type ScoreEditResult, type ShareRequest, type ShareRoomCodeOptions, type TextureAtlas, type TextureAtlasAnimation, type TextureAtlasFrame, type Unsubscribe, addScore, enableLogOverlay, flushGameState, getGameId, getPlayerAvatar, getPlayerCharacter, getPlayerId, getPlayerName, getRoomCode, getSafeAreaTop, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, openInviteModal, saveGameState, setLeaderboardVisible, setScore, share, shareRoomCode, submitScore, triggerHaptic };