@playcademy/sdk 0.0.1-beta.20 → 0.0.1-beta.22
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 +7 -0
- package/dist/core/client.d.ts +15 -0
- package/dist/core/namespaces/index.d.ts +1 -0
- package/dist/core/namespaces/levels.d.ts +93 -0
- package/dist/index.js +42 -4
- package/dist/messaging.d.ts +3 -4
- package/dist/types.d.ts +12 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -162,6 +162,13 @@ All methods returning data are strongly typed.
|
|
|
162
162
|
- **`admin.shopListings`**: CRUD operations for shop listings.
|
|
163
163
|
- **`shop`**: Player-facing shop operations.
|
|
164
164
|
- `view()`: Get shop items and currency information.
|
|
165
|
+
- **`levels`**: Player level and experience point management.
|
|
166
|
+
- `get()`: Get current user level information.
|
|
167
|
+
- `progress()`: Get level progress with XP to next level.
|
|
168
|
+
- `addXP(amount)`: Add XP to user.
|
|
169
|
+
- **`config`**:
|
|
170
|
+
- `list()`: Get all level configurations (full XP curve).
|
|
171
|
+
- `get(level)`: Get configuration for a specific level.
|
|
165
172
|
- **`telemetry`**: Push metrics.
|
|
166
173
|
|
|
167
174
|
## Contributing
|
package/dist/core/client.d.ts
CHANGED
|
@@ -311,6 +311,21 @@ export declare class PlaycademyClient {
|
|
|
311
311
|
shop: {
|
|
312
312
|
view: () => Promise<import("..").ShopViewResponse>;
|
|
313
313
|
};
|
|
314
|
+
/** Level methods (levels) */
|
|
315
|
+
levels: {
|
|
316
|
+
get: () => Promise<import("@playcademy/types").UserLevel>;
|
|
317
|
+
progress: () => Promise<{
|
|
318
|
+
level: number;
|
|
319
|
+
currentXp: number;
|
|
320
|
+
xpToNextLevel: number;
|
|
321
|
+
totalXpEarned: number;
|
|
322
|
+
}>;
|
|
323
|
+
addXP: (amount: number) => Promise<import("@playcademy/types").XPAddResult>;
|
|
324
|
+
config: {
|
|
325
|
+
list: () => Promise<import("@playcademy/types").LevelConfig[]>;
|
|
326
|
+
get: (level: number) => Promise<import("@playcademy/types").LevelConfig | null>;
|
|
327
|
+
};
|
|
328
|
+
};
|
|
314
329
|
/** Telemetry methods (pushMetrics) */
|
|
315
330
|
telemetry: {
|
|
316
331
|
pushMetrics: (metrics: Record<string, number>) => Promise<void>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { UserLevel, LevelConfig, XPAddResult } from '../../types';
|
|
2
|
+
import type { PlaycademyClient } from '../client';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the levels namespace for the PlaycademyClient.
|
|
5
|
+
* Provides methods for managing user levels and experience points.
|
|
6
|
+
*
|
|
7
|
+
* @param client - The PlaycademyClient instance
|
|
8
|
+
* @returns Levels namespace with level and XP methods
|
|
9
|
+
*/
|
|
10
|
+
export declare function createLevelsNamespace(client: PlaycademyClient): {
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves the current user's level information.
|
|
13
|
+
*
|
|
14
|
+
* @returns Promise resolving to user level data
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const userLevel = await client.levels.get()
|
|
19
|
+
* console.log('Current level:', userLevel.currentLevel)
|
|
20
|
+
* console.log('Current XP:', userLevel.currentXp)
|
|
21
|
+
* console.log('Total XP earned:', userLevel.totalXpEarned)
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
get: () => Promise<UserLevel>;
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the current user's level progress information.
|
|
27
|
+
*
|
|
28
|
+
* @returns Promise resolving to level progress data
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const progress = await client.levels.progress()
|
|
33
|
+
* console.log('Level:', progress.level)
|
|
34
|
+
* console.log('XP to next level:', progress.xpToNextLevel)
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
progress: () => Promise<{
|
|
38
|
+
level: number;
|
|
39
|
+
currentXp: number;
|
|
40
|
+
xpToNextLevel: number;
|
|
41
|
+
totalXpEarned: number;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Adds XP to the current user.
|
|
45
|
+
* Emits 'xpGained' and 'levelUp' events when successful.
|
|
46
|
+
*
|
|
47
|
+
* @param amount - The amount of XP to add (must be positive)
|
|
48
|
+
* @returns Promise resolving to XP addition result
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const result = await client.levels.addXP(100)
|
|
53
|
+
* console.log('New level:', result.newLevel)
|
|
54
|
+
* console.log('Leveled up:', result.leveledUp)
|
|
55
|
+
* console.log('Credits awarded:', result.creditsAwarded)
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
addXP: (amount: number) => Promise<XPAddResult>;
|
|
59
|
+
/**
|
|
60
|
+
* Configuration methods for level system.
|
|
61
|
+
*/
|
|
62
|
+
config: {
|
|
63
|
+
/**
|
|
64
|
+
* Retrieves all level configurations (full XP curve).
|
|
65
|
+
*
|
|
66
|
+
* @returns Promise resolving to array of level configurations
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const configs = await client.levels.config.list()
|
|
71
|
+
* configs.forEach(config => {
|
|
72
|
+
* console.log(`Level ${config.level}: ${config.xpRequired} XP, ${config.creditsReward} credits`)
|
|
73
|
+
* })
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
list: () => Promise<LevelConfig[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Retrieves configuration for a specific level.
|
|
79
|
+
*
|
|
80
|
+
* @param level - The level number to get configuration for
|
|
81
|
+
* @returns Promise resolving to level configuration or null if not found
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const config = await client.levels.config.get(10)
|
|
86
|
+
* if (config) {
|
|
87
|
+
* console.log(`Level 10 requires ${config.xpRequired} XP`)
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
get: (level: number) => Promise<LevelConfig | null>;
|
|
92
|
+
};
|
|
93
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -167,10 +167,8 @@ class PlaycademyMessaging {
|
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
169
|
sendViaPostMessage(type, payload, target = window.parent, origin = "*") {
|
|
170
|
-
|
|
171
|
-
if (payload !== undefined
|
|
172
|
-
messageData = { ...messageData, ...payload };
|
|
173
|
-
} else if (payload !== undefined) {
|
|
170
|
+
const messageData = { type };
|
|
171
|
+
if (payload !== undefined) {
|
|
174
172
|
messageData.payload = payload;
|
|
175
173
|
}
|
|
176
174
|
target.postMessage(messageData, origin);
|
|
@@ -370,6 +368,45 @@ function createTelemetryNamespace(client) {
|
|
|
370
368
|
};
|
|
371
369
|
}
|
|
372
370
|
|
|
371
|
+
// src/core/namespaces/levels.ts
|
|
372
|
+
function createLevelsNamespace(client) {
|
|
373
|
+
return {
|
|
374
|
+
get: async () => {
|
|
375
|
+
return client["request"]("/users/level", "GET");
|
|
376
|
+
},
|
|
377
|
+
progress: async () => {
|
|
378
|
+
return client["request"]("/users/level/progress", "GET");
|
|
379
|
+
},
|
|
380
|
+
addXP: async (amount) => {
|
|
381
|
+
const currentUserLevel = await client["request"]("/users/level", "GET");
|
|
382
|
+
const oldLevel = currentUserLevel.currentLevel;
|
|
383
|
+
const payload = { amount };
|
|
384
|
+
const result = await client["request"]("/users/xp/add", "POST", payload);
|
|
385
|
+
client["emit"]("xpGained", {
|
|
386
|
+
amount,
|
|
387
|
+
totalXpEarned: result.totalXpEarned,
|
|
388
|
+
leveledUp: result.leveledUp
|
|
389
|
+
});
|
|
390
|
+
if (result.leveledUp) {
|
|
391
|
+
client["emit"]("levelUp", {
|
|
392
|
+
oldLevel,
|
|
393
|
+
newLevel: result.newLevel,
|
|
394
|
+
creditsAwarded: result.creditsAwarded
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
return result;
|
|
398
|
+
},
|
|
399
|
+
config: {
|
|
400
|
+
list: async () => {
|
|
401
|
+
return client["request"]("/levels/config", "GET");
|
|
402
|
+
},
|
|
403
|
+
get: async (level) => {
|
|
404
|
+
return client["request"](`/levels/config/${level}`, "GET");
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
373
410
|
// src/core/namespaces/index.ts
|
|
374
411
|
var init_namespaces = __esm(() => {
|
|
375
412
|
init_runtime();
|
|
@@ -570,6 +607,7 @@ var init_client = __esm(() => {
|
|
|
570
607
|
maps = createMapsNamespace(this);
|
|
571
608
|
admin = createAdminNamespace(this);
|
|
572
609
|
shop = createShopNamespace(this);
|
|
610
|
+
levels = createLevelsNamespace(this);
|
|
573
611
|
telemetry = createTelemetryNamespace(this);
|
|
574
612
|
static init = init;
|
|
575
613
|
static login = login;
|
package/dist/messaging.d.ts
CHANGED
|
@@ -377,11 +377,10 @@ declare class PlaycademyMessaging {
|
|
|
377
377
|
* **Message Structure**:
|
|
378
378
|
* The method creates a message object with the following structure:
|
|
379
379
|
* - `type`: The message event type (e.g., 'PLAYCADEMY_READY')
|
|
380
|
-
* -
|
|
380
|
+
* - `payload`: The message data (if any)
|
|
381
381
|
*
|
|
382
382
|
* **Payload Handling**:
|
|
383
|
-
* - **
|
|
384
|
-
* - **Primitive payloads**: Wrapped in a `payload` property (e.g., { type, payload: true })
|
|
383
|
+
* - **All payloads**: Wrapped in a `payload` property for consistency (e.g., { type, payload: data })
|
|
385
384
|
* - **Undefined payloads**: Only the type is sent (e.g., { type })
|
|
386
385
|
*
|
|
387
386
|
* **Security**:
|
|
@@ -402,7 +401,7 @@ declare class PlaycademyMessaging {
|
|
|
402
401
|
*
|
|
403
402
|
* // Send telemetry data (object payload)
|
|
404
403
|
* sendViaPostMessage(MessageEvents.TELEMETRY, { fps: 60, mem: 128 })
|
|
405
|
-
* // Sends: { type: 'PLAYCADEMY_TELEMETRY', fps: 60, mem: 128 }
|
|
404
|
+
* // Sends: { type: 'PLAYCADEMY_TELEMETRY', payload: { fps: 60, mem: 128 } }
|
|
406
405
|
*
|
|
407
406
|
* // Send overlay state (primitive payload)
|
|
408
407
|
* sendViaPostMessage(MessageEvents.OVERLAY, true)
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { User, InventoryItemWithItem, Game, DeveloperKey, DeveloperStatusResponse, MapElement, Item, InsertItem, ManifestV1, UpdateItem, Currency, InsertCurrency, UpdateCurrency, ShopListing, InsertShopListing, UpdateShopListing } from '@playcademy/types';
|
|
1
|
+
import type { User, InventoryItemWithItem, Game, DeveloperKey, DeveloperStatusResponse, MapElement, Item, InsertItem, ManifestV1, UpdateItem, Currency, InsertCurrency, UpdateCurrency, ShopListing, InsertShopListing, UpdateShopListing, UserLevel, LevelConfig, XPAddResult, UserLevelWithConfig, XPActionInput } from '@playcademy/types';
|
|
2
2
|
export interface ClientConfig {
|
|
3
3
|
baseUrl: string;
|
|
4
4
|
token?: string;
|
|
@@ -13,6 +13,16 @@ export interface ClientEvents {
|
|
|
13
13
|
delta: number;
|
|
14
14
|
newTotal: number;
|
|
15
15
|
};
|
|
16
|
+
levelUp: {
|
|
17
|
+
oldLevel: number;
|
|
18
|
+
newLevel: number;
|
|
19
|
+
creditsAwarded: number;
|
|
20
|
+
};
|
|
21
|
+
xpGained: {
|
|
22
|
+
amount: number;
|
|
23
|
+
totalXpEarned: number;
|
|
24
|
+
leveledUp: boolean;
|
|
25
|
+
};
|
|
16
26
|
}
|
|
17
27
|
export type GameContextPayload = {
|
|
18
28
|
token: string;
|
|
@@ -68,4 +78,4 @@ export interface ShopViewResponse {
|
|
|
68
78
|
shopItems: ShopDisplayItem[];
|
|
69
79
|
currencies: CurrencyInfo[];
|
|
70
80
|
}
|
|
71
|
-
export type { User, InventoryItemWithItem, Game, ManifestV1, DeveloperKey, DeveloperStatusResponse, MapElement, Item, InsertItem, UpdateItem, Currency, InsertCurrency, UpdateCurrency, ShopListing, InsertShopListing, UpdateShopListing, };
|
|
81
|
+
export type { User, InventoryItemWithItem, Game, ManifestV1, DeveloperKey, DeveloperStatusResponse, MapElement, Item, InsertItem, UpdateItem, Currency, InsertCurrency, UpdateCurrency, ShopListing, InsertShopListing, UpdateShopListing, UserLevel, LevelConfig, XPAddResult, UserLevelWithConfig, XPActionInput, };
|