@playcademy/sdk 0.0.1-beta.28 → 0.0.1-beta.29

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.
@@ -1,4 +1,4 @@
1
- import type { MapElementWithGame } from '@playcademy/data/types';
1
+ import type { CreateMapObjectData, MapData, MapElementWithGame, MapObjectWithItem } from '@playcademy/data/types';
2
2
  import type { PlaycademyClient } from '../../types';
3
3
  /**
4
4
  * Creates the maps namespace for the PlaycademyClient.
@@ -8,6 +8,19 @@ import type { PlaycademyClient } from '../../types';
8
8
  * @returns Maps namespace with element retrieval methods
9
9
  */
10
10
  export declare function createMapsNamespace(client: PlaycademyClient): {
11
+ /**
12
+ * Gets details for a specific map by its string identifier.
13
+ *
14
+ * @param identifier - The string identifier of the map
15
+ * @returns Promise resolving to map data
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const map = await client.maps.get('world-1-level-1')
20
+ * console.log('Map name:', map.name)
21
+ * ```
22
+ */
23
+ get: (identifier: string) => Promise<MapData>;
11
24
  /**
12
25
  * Retrieves all elements for a specific map.
13
26
  *
@@ -23,4 +36,58 @@ export declare function createMapsNamespace(client: PlaycademyClient): {
23
36
  * ```
24
37
  */
25
38
  elements: (mapId: string) => Promise<MapElementWithGame[]>;
39
+ /**
40
+ * Map objects sub-namespace for managing placed objects on maps
41
+ */
42
+ objects: {
43
+ /**
44
+ * Lists all placed objects for a specific map.
45
+ *
46
+ * @param mapId - The ID of the map to get objects for
47
+ * @returns Promise resolving to array of map objects
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const objects = await client.maps.objects.list('map-123')
52
+ * objects.forEach(obj => {
53
+ * console.log(`Object at (${obj.worldX}, ${obj.worldY})`)
54
+ * })
55
+ * ```
56
+ */
57
+ list: (mapId: string) => Promise<MapObjectWithItem[]>;
58
+ /**
59
+ * Creates a new placed object on a map.
60
+ *
61
+ * @param mapId - The ID of the map to place the object on
62
+ * @param objectData - The object placement data
63
+ * @returns Promise resolving to the created map object
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const newObject = await client.maps.objects.create('map-123', {
68
+ * worldX: 100,
69
+ * worldY: 200,
70
+ * width: 32,
71
+ * height: 32,
72
+ * metadata: { type: 'treasure_chest' }
73
+ * })
74
+ * console.log('Object created:', newObject.id)
75
+ * ```
76
+ */
77
+ create: (mapId: string, objectData: CreateMapObjectData) => Promise<MapObjectWithItem>;
78
+ /**
79
+ * Deletes a placed object from a map.
80
+ *
81
+ * @param mapId - The ID of the map containing the object
82
+ * @param objectId - The ID of the object to delete
83
+ * @returns Promise that resolves when object is deleted
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * await client.maps.objects.delete('map-123', 'object-456')
88
+ * console.log('Object deleted')
89
+ * ```
90
+ */
91
+ delete: (mapId: string, objectId: string) => Promise<void>;
92
+ };
26
93
  };
@@ -0,0 +1,40 @@
1
+ import type { PlaycademyClient } from '../../types';
2
+ /**
3
+ * Response type for the realtime token API
4
+ */
5
+ export interface RealtimeTokenResponse {
6
+ token: string;
7
+ }
8
+ /**
9
+ * Creates the realtime namespace for the PlaycademyClient.
10
+ * Provides methods for realtime connectivity and features.
11
+ *
12
+ * @param client - The PlaycademyClient instance
13
+ * @returns Realtime namespace with token-related methods
14
+ */
15
+ export declare function createRealtimeNamespace(client: PlaycademyClient): {
16
+ /**
17
+ * Token sub-namespace for realtime token management
18
+ */
19
+ token: {
20
+ /**
21
+ * Gets a realtime JWT token for establishing realtime connections.
22
+ * This token is typically used for WebSocket connections or MQTT clients.
23
+ *
24
+ * @returns Promise resolving to token response
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // Get a realtime token
29
+ * const response = await client.realtime.token.get()
30
+ * console.log('Realtime token:', response.token)
31
+ *
32
+ * // Use with a realtime client
33
+ * const realtimeClient = new RealtimeClient({
34
+ * token: response.token
35
+ * })
36
+ * ```
37
+ */
38
+ get: () => Promise<RealtimeTokenResponse>;
39
+ };
40
+ };
@@ -1,10 +1,18 @@
1
- import type { GameTokenResponse, PlaycademyClient } from '../../types';
1
+ import { MessageEvents } from '../../messaging';
2
+ import type { GameContextPayload, GameTokenResponse, PlaycademyClient } from '../../types';
3
+ /**
4
+ * Type for runtime event handlers - union of all possible handler signatures
5
+ */
6
+ type RuntimeEventHandler = ((context: GameContextPayload) => void) | ((data: {
7
+ token: string;
8
+ exp: number;
9
+ }) => void) | (() => void) | ((isVisible: boolean) => void);
2
10
  /**
3
11
  * Creates the runtime namespace for the PlaycademyClient.
4
12
  * Provides methods for managing game runtime operations and lifecycle.
5
13
  *
6
14
  * @param client - The PlaycademyClient instance
7
- * @returns Runtime namespace with game token and exit methods
15
+ * @returns Runtime namespace with comprehensive game lifecycle management methods
8
16
  */
9
17
  export declare function createRuntimeNamespace(client: PlaycademyClient): {
10
18
  /**
@@ -41,4 +49,174 @@ export declare function createRuntimeNamespace(client: PlaycademyClient): {
41
49
  * ```
42
50
  */
43
51
  exit: () => Promise<void>;
52
+ /**
53
+ * Listens for game initialization events from the parent.
54
+ * Called when the parent sends initial configuration and auth context.
55
+ *
56
+ * @param handler - Function to call when initialization occurs
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * client.runtime.onInit((context) => {
61
+ * console.log(`Game ${context.gameId} initialized`)
62
+ * console.log(`API base URL: ${context.baseUrl}`)
63
+ * })
64
+ * ```
65
+ */
66
+ onInit: (handler: (context: GameContextPayload) => void) => void;
67
+ /**
68
+ * Listens for token refresh events from the parent.
69
+ * Called when the parent updates the authentication token.
70
+ *
71
+ * @param handler - Function to call when token is refreshed
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * client.runtime.onTokenRefresh(({ token, exp }) => {
76
+ * console.log(`Token refreshed, expires at: ${new Date(exp)}`)
77
+ * // Token is automatically applied to the client
78
+ * })
79
+ * ```
80
+ */
81
+ onTokenRefresh: (handler: (data: {
82
+ token: string;
83
+ exp: number;
84
+ }) => void) => void;
85
+ /**
86
+ * Listens for pause events from the parent.
87
+ * Called when the game should pause execution (e.g., user switches tabs).
88
+ *
89
+ * @param handler - Function to call when game should pause
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * client.runtime.onPause(() => {
94
+ * game.pause()
95
+ * audioManager.pauseAll()
96
+ * })
97
+ * ```
98
+ */
99
+ onPause: (handler: () => void) => void;
100
+ /**
101
+ * Listens for resume events from the parent.
102
+ * Called when the game should resume execution after being paused.
103
+ *
104
+ * @param handler - Function to call when game should resume
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * client.runtime.onResume(() => {
109
+ * game.resume()
110
+ * audioManager.resumeAll()
111
+ * })
112
+ * ```
113
+ */
114
+ onResume: (handler: () => void) => void;
115
+ /**
116
+ * Listens for force exit events from the parent.
117
+ * Called when the game must terminate immediately (emergency exit).
118
+ *
119
+ * @param handler - Function to call when game must force exit
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * client.runtime.onForceExit(() => {
124
+ * game.emergencyCleanup()
125
+ * // Game should exit immediately after cleanup
126
+ * })
127
+ * ```
128
+ */
129
+ onForceExit: (handler: () => void) => void;
130
+ /**
131
+ * Listens for overlay visibility events from the parent.
132
+ * Called when UI overlays are shown/hidden over the game.
133
+ *
134
+ * @param handler - Function to call when overlay state changes
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * client.runtime.onOverlay((isVisible) => {
139
+ * if (isVisible) {
140
+ * game.showOverlayMode()
141
+ * } else {
142
+ * game.hideOverlayMode()
143
+ * }
144
+ * })
145
+ * ```
146
+ */
147
+ onOverlay: (handler: (isVisible: boolean) => void) => void;
148
+ /**
149
+ * Signals that the game has finished loading and is ready to receive messages.
150
+ * Should be called once after game initialization is complete.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * // After game has loaded
155
+ * await client.runtime.ready()
156
+ * ```
157
+ */
158
+ ready: () => void;
159
+ /**
160
+ * Sends performance telemetry data to the parent.
161
+ * Used for monitoring game performance and analytics.
162
+ *
163
+ * @param data - Performance metrics data
164
+ * @param data.fps - Current frames per second
165
+ * @param data.mem - Current memory usage in MB
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * // Send current performance metrics
170
+ * client.runtime.sendTelemetry({
171
+ * fps: game.getCurrentFPS(),
172
+ * mem: performance.memory ? performance.memory.usedJSHeapSize / 1024 / 1024 : 0
173
+ * })
174
+ * ```
175
+ */
176
+ sendTelemetry: (data: {
177
+ fps: number;
178
+ mem: number;
179
+ }) => void;
180
+ /**
181
+ * Removes a specific event listener.
182
+ * Use this to stop listening for specific events.
183
+ *
184
+ * @param eventType - The message event type to stop listening for
185
+ * @param handler - The exact handler function that was registered
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * const pauseHandler = () => game.pause()
190
+ * client.runtime.onPause(pauseHandler)
191
+ *
192
+ * // Later, remove the specific handler
193
+ * client.runtime.removeListener(MessageEvents.PAUSE, pauseHandler)
194
+ * ```
195
+ */
196
+ removeListener: (eventType: MessageEvents, handler: RuntimeEventHandler) => void;
197
+ /**
198
+ * Removes all runtime event listeners.
199
+ * Use this for cleanup when the game is shutting down.
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * // Clean up all runtime listeners before exit
204
+ * client.runtime.removeAllListeners()
205
+ * await client.runtime.exit()
206
+ * ```
207
+ */
208
+ removeAllListeners: () => void;
209
+ /**
210
+ * Gets the count of active listeners for debugging purposes.
211
+ *
212
+ * @returns Object with listener counts by event type
213
+ *
214
+ * @example
215
+ * ```typescript
216
+ * const counts = client.runtime.getListenerCounts()
217
+ * console.log(`Active listeners:`, counts)
218
+ * ```
219
+ */
220
+ getListenerCounts: () => Record<string, number>;
44
221
  };
222
+ export {};
@@ -0,0 +1,55 @@
1
+ import type { UserScore } from '@playcademy/data/types';
2
+ import type { PlaycademyClient } from '../../types';
3
+ export interface ScoreSubmission {
4
+ id: string;
5
+ score: number;
6
+ achievedAt: Date;
7
+ }
8
+ /**
9
+ * Creates the scores namespace for the PlaycademyClient.
10
+ * Provides methods for managing scores across the platform.
11
+ *
12
+ * @param client - The PlaycademyClient instance
13
+ * @returns Scores namespace with submit and retrieval methods
14
+ */
15
+ export declare function createScoresNamespace(client: PlaycademyClient): {
16
+ /**
17
+ * Submits a score for a specific game.
18
+ * Note: This still requires a gameId as scores must be associated with a game.
19
+ *
20
+ * @param gameId - The game ID to submit the score for
21
+ * @param score - The score value to submit
22
+ * @param metadata - Optional metadata about the score
23
+ * @returns Promise resolving to the created score record
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * const scoreRecord = await client.scores.submit('game-123', 1250, {
28
+ * level: 5,
29
+ * difficulty: 'hard'
30
+ * })
31
+ * console.log('Score submitted:', scoreRecord.id)
32
+ * ```
33
+ */
34
+ submit: (gameId: string, score: number, metadata?: Record<string, unknown>) => Promise<ScoreSubmission>;
35
+ /**
36
+ * Gets all scores for a specific user within a specific game.
37
+ *
38
+ * @param gameId - The game ID to get scores for
39
+ * @param userId - The user ID to get scores for
40
+ * @param options - Optional filtering options
41
+ * @param options.limit - Maximum number of scores to return
42
+ * @returns Promise resolving to array of user scores for the game
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const gameScores = await client.scores.getByUser('game-123', 'user-456', {
47
+ * limit: 10
48
+ * })
49
+ * console.log(`User has ${gameScores.length} scores in this game`)
50
+ * ```
51
+ */
52
+ getByUser: (gameId: string, userId: string, options?: {
53
+ limit?: number;
54
+ }) => Promise<UserScore[]>;
55
+ };
@@ -0,0 +1,32 @@
1
+ import type { SpriteTemplateData } from '@playcademy/data/types';
2
+ import type { PlaycademyClient } from '../../types';
3
+ /**
4
+ * Creates the sprites namespace for the PlaycademyClient.
5
+ * Provides methods for managing sprite templates and related data.
6
+ *
7
+ * @param client - The PlaycademyClient instance
8
+ * @returns Sprites namespace with template methods
9
+ */
10
+ export declare function createSpritesNamespace(client: PlaycademyClient): {
11
+ /**
12
+ * Sprite templates sub-namespace
13
+ */
14
+ templates: {
15
+ /**
16
+ * Gets a sprite template by its slug.
17
+ * This fetches the template metadata from the database and then loads
18
+ * the actual template JSON data from the CDN/S3.
19
+ *
20
+ * @param slug - The template slug to fetch
21
+ * @returns Promise resolving to the sprite template data
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const template = await client.sprites.templates.get('hero-idle')
26
+ * console.log('Template frames:', template.frames?.length || 0)
27
+ * console.log('Template animations:', Object.keys(template.animations || {}))
28
+ * ```
29
+ */
30
+ get: (slug: string) => Promise<SpriteTemplateData>;
31
+ };
32
+ };
@@ -1,5 +1,14 @@
1
1
  import type { InventoryItemWithItem } from '@playcademy/data/types';
2
2
  import type { InventoryMutationResponse, PlaycademyClient } from '../../types';
3
+ export interface UserScore {
4
+ id: string;
5
+ score: number;
6
+ achievedAt: Date;
7
+ metadata?: Record<string, unknown>;
8
+ gameId: string;
9
+ gameTitle: string;
10
+ gameSlug: string;
11
+ }
3
12
  /**
4
13
  * Creates the users namespace for the PlaycademyClient.
5
14
  * Provides methods for managing user data and inventory operations.
@@ -29,6 +38,7 @@ export declare function createUsersNamespace(client: PlaycademyClient): {
29
38
  image: string | null;
30
39
  role: "admin" | "player" | "developer";
31
40
  developerStatus: "none" | "pending" | "approved";
41
+ characterCreated: boolean;
32
42
  createdAt: Date;
33
43
  updatedAt: Date;
34
44
  }>;
@@ -128,4 +138,46 @@ export declare function createUsersNamespace(client: PlaycademyClient): {
128
138
  */
129
139
  has: (identifier: string, minQuantity?: number) => Promise<boolean>;
130
140
  };
141
+ /**
142
+ * User scores management methods.
143
+ */
144
+ scores: {
145
+ /**
146
+ * Gets scores for a user across all games.
147
+ *
148
+ * @param userIdOrOptions - User ID or options object. If omitted, gets scores for the current user.
149
+ * @param options - Optional filtering options
150
+ * @param options.limit - Maximum number of scores to return
151
+ * @param options.gameId - Filter scores by specific game
152
+ * @returns Promise resolving to array of user scores
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * // Get all scores for current user
157
+ * const myScores = await client.users.scores.get()
158
+ *
159
+ * // Get scores for current user with options
160
+ * const myGameScores = await client.users.scores.get({
161
+ * gameId: 'game-456',
162
+ * limit: 20
163
+ * })
164
+ *
165
+ * // Get scores for a specific user
166
+ * const userScores = await client.users.scores.get('user-123')
167
+ *
168
+ * // Get scores for a specific user with options
169
+ * const userGameScores = await client.users.scores.get('user-123', {
170
+ * gameId: 'game-789',
171
+ * limit: 10
172
+ * })
173
+ * ```
174
+ */
175
+ get: (userIdOrOptions?: string | {
176
+ limit?: number;
177
+ gameId?: string;
178
+ }, options?: {
179
+ limit?: number;
180
+ gameId?: string;
181
+ }) => Promise<UserScore[]>;
182
+ };
131
183
  };