skillprint-js-sdk 1.1.0-beta.1
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 +265 -0
- package/dist/index.cjs +1256 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +456 -0
- package/dist/index.d.ts +456 -0
- package/dist/index.global.js +1236 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +1211 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# Skillprint JavaScript & TypeScript SDK
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/skillprint-js-sdk)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
|
|
7
|
+
A professional JavaScript & TypeScript SDK for integrating Skillprint's real-time AI gameplay adjustment engine into web games. Compatible with popular game engines including **Phaser.js**, **Three.js**, **PixiJS**, **Babylon.js**, and **Generic HTML5 Canvas** applications.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Key Features
|
|
12
|
+
|
|
13
|
+
- โก **Dual JS & TS Support**: Native TypeScript types with `.d.ts` declarations, ESM (`.js`), CommonJS (`.cjs`), and Browser CDN (`.global.js`) builds.
|
|
14
|
+
- ๐ธ **Automated Screenshot Capture**: Asynchronous, throttled gameplay screenshot captures for Canvas and WebGL contexts without dropping game frame rates.
|
|
15
|
+
- ๐ **Real-Time Dynamic Parameters**: Receive, convert, clamp, and apply AI-driven parameter modifications seamlessly during active sessions.
|
|
16
|
+
- ๐ฎ **Built-In Engine Adapters**: Ready-to-use adapter wrappers for Phaser.js, Three.js, PixiJS, and Generic Canvas.
|
|
17
|
+
- ๐ **WebGL & URL Extraction**: Automatic query parameter extraction for web deployments (`mood`, `playerId`).
|
|
18
|
+
- ๐งช **100% Test Coverage Ready**: Fully tested with Vitest and jsdom.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
### NPM (Recommended for TypeScript & Bundlers)
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install skillprint-js-sdk
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Browser CDN (Vanilla JavaScript)
|
|
31
|
+
|
|
32
|
+
```html
|
|
33
|
+
<!-- ES Module Import -->
|
|
34
|
+
<script type="module">
|
|
35
|
+
import { SkillprintManager, SkillprintConfig, Mood } from 'https://cdn.jsdelivr.net/npm/skillprint-js-sdk/dist/index.js';
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<!-- Script Tag Global (UMD/IIFE) -->
|
|
39
|
+
<script src="https://cdn.jsdelivr.net/npm/skillprint-js-sdk/dist/index.global.js"></script>
|
|
40
|
+
<script>
|
|
41
|
+
const { SkillprintManager, SkillprintConfig, Mood } = window.SkillprintSDK;
|
|
42
|
+
</script>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
### TypeScript / ES Modules Usage
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import {
|
|
53
|
+
SkillprintConfig,
|
|
54
|
+
SkillprintManager,
|
|
55
|
+
ParameterDefinition,
|
|
56
|
+
ParameterType,
|
|
57
|
+
Mood
|
|
58
|
+
} from 'skillprint-js-sdk';
|
|
59
|
+
|
|
60
|
+
// 1. Configure the SDK
|
|
61
|
+
const config = new SkillprintConfig({
|
|
62
|
+
gameName: 'my-awesome-game',
|
|
63
|
+
targetEnvironment: 'production',
|
|
64
|
+
productionPartnerApiKey: 'YOUR_PARTNER_API_KEY',
|
|
65
|
+
enableDebugLogging: true,
|
|
66
|
+
gameParameters: [
|
|
67
|
+
new ParameterDefinition({
|
|
68
|
+
parameterName: 'difficulty',
|
|
69
|
+
description: 'Game difficulty factor',
|
|
70
|
+
type: ParameterType.FLOAT,
|
|
71
|
+
minValue: 0.5,
|
|
72
|
+
maxValue: 2.0,
|
|
73
|
+
defaultValue: 1.0
|
|
74
|
+
})
|
|
75
|
+
]
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// 2. Initialize Manager with canvas provider
|
|
79
|
+
const canvasProvider = () => document.getElementById('gameCanvas') as HTMLCanvasElement;
|
|
80
|
+
const manager = new SkillprintManager(config, canvasProvider);
|
|
81
|
+
|
|
82
|
+
// 3. Register parameter update handler
|
|
83
|
+
manager.registerParameterModifier('difficulty', (newValue) => {
|
|
84
|
+
console.log(`AI adjusted difficulty to: ${newValue}`);
|
|
85
|
+
// Apply newValue (typed as number | boolean | string) to your game engine
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// 4. Start AI session
|
|
89
|
+
manager.startGameSession(Mood.FOCUS, 'player_123');
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### CommonJS (Node / Older Bundlers)
|
|
93
|
+
|
|
94
|
+
```javascript
|
|
95
|
+
const { SkillprintConfig, SkillprintManager, Mood } = require('skillprint-js-sdk');
|
|
96
|
+
|
|
97
|
+
const config = new SkillprintConfig({
|
|
98
|
+
gameName: 'my-awesome-game',
|
|
99
|
+
productionPartnerApiKey: 'YOUR_PARTNER_API_KEY'
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const manager = new SkillprintManager(config, () => document.getElementById('gameCanvas'));
|
|
103
|
+
manager.startGameSession(Mood.RELAX);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Game Engine Integrations
|
|
109
|
+
|
|
110
|
+
### 1. Phaser.js
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { PhaserSkillprintAdapter, SkillprintConfig, Mood } from 'skillprint-js-sdk';
|
|
114
|
+
|
|
115
|
+
class MainScene extends Phaser.Scene {
|
|
116
|
+
private skillprint!: PhaserSkillprintAdapter;
|
|
117
|
+
private enemySpeed = 5;
|
|
118
|
+
|
|
119
|
+
create() {
|
|
120
|
+
const config = new SkillprintConfig({
|
|
121
|
+
gameName: 'phaser-space-shooter',
|
|
122
|
+
productionPartnerApiKey: 'YOUR_API_KEY'
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Pass Phaser scene context
|
|
126
|
+
this.skillprint = PhaserSkillprintAdapter.create(this, config);
|
|
127
|
+
|
|
128
|
+
// Register custom parameter update handler
|
|
129
|
+
this.skillprint.registerParameter('enemySpeed', (value) => {
|
|
130
|
+
this.enemySpeed = Number(value);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Start session
|
|
134
|
+
this.skillprint.startSession(Mood.FOCUS);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 2. Three.js
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { ThreeSkillprintAdapter, SkillprintConfig, Mood } from 'skillprint-js-sdk';
|
|
143
|
+
|
|
144
|
+
// Pass Three.js WebGLRenderer instance
|
|
145
|
+
const skillprint = ThreeSkillprintAdapter.create(renderer, config);
|
|
146
|
+
|
|
147
|
+
// Bind target object property directly
|
|
148
|
+
skillprint.registerObjectProperty('lightIntensity', directionalLight, 'intensity');
|
|
149
|
+
skillprint.registerObjectProperty('fogDensity', scene.fog, 'density');
|
|
150
|
+
|
|
151
|
+
skillprint.startSession(Mood.CREATIVITY);
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 3. PixiJS
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { PixiSkillprintAdapter, SkillprintConfig, Mood } from 'skillprint-js-sdk';
|
|
158
|
+
|
|
159
|
+
// Pass PixiJS Application instance
|
|
160
|
+
const skillprint = PixiSkillprintAdapter.create(app, config);
|
|
161
|
+
|
|
162
|
+
// Bind display object property
|
|
163
|
+
skillprint.registerDisplayObjectProperty('playerAlpha', playerSprite, 'alpha');
|
|
164
|
+
|
|
165
|
+
skillprint.startSession(Mood.JOY);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## WebGL & URL Parameter Handling
|
|
171
|
+
|
|
172
|
+
When deploying WebGL games, the SDK can extract initial session parameters directly from the browser URL:
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
// Example URL: https://yourgame.com/?mood=focus&playerId=user_999
|
|
176
|
+
|
|
177
|
+
// Automatically extract parameters or use fallbacks
|
|
178
|
+
manager.startGameSessionFromUrl(Mood.RELAX, 'default_player');
|
|
179
|
+
|
|
180
|
+
// Force overrides if necessary
|
|
181
|
+
manager.startGameSessionWithOverrides(
|
|
182
|
+
Mood.RELAX, // Fallback mood
|
|
183
|
+
'default_player', // Fallback player ID
|
|
184
|
+
Mood.FOCUS, // Forced mood override
|
|
185
|
+
'player_override' // Forced player ID override
|
|
186
|
+
);
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## API Reference
|
|
192
|
+
|
|
193
|
+
### Core Classes
|
|
194
|
+
|
|
195
|
+
#### `SkillprintConfig`
|
|
196
|
+
- `constructor(options?: SkillprintConfigOptions)`
|
|
197
|
+
- **Properties**: `gameName`, `targetEnvironment`, `productionPartnerApiKey`, `productionApiBaseUrl`, `stagingPartnerApiKey`, `stagingApiBaseUrl`, `screenshotIntervalSeconds`, `screenshotPostIntervalSeconds`, `pollResultsIntervalSeconds`, `enableDebugLogging`.
|
|
198
|
+
- **Getters**: `activePartnerApiKey`, `activeApiBaseUrl`.
|
|
199
|
+
|
|
200
|
+
#### `SkillprintManager` (Singleton)
|
|
201
|
+
- `constructor(config: SkillprintConfig, canvasProvider?: CanvasProvider)`
|
|
202
|
+
- `static getInstance(): SkillprintManager | null`
|
|
203
|
+
- `registerParameterModifier(parameterName: string, updateAction: ParameterModifierAction, expectedType?: string | null): void`
|
|
204
|
+
- `startGameSession(targetMood: Mood | string, customPlayerId?: string | null): Promise<void>`
|
|
205
|
+
- `stopGameSession(): void`
|
|
206
|
+
- `getCurrentSessionId(): string | null`
|
|
207
|
+
- `getConfig(): SkillprintConfig`
|
|
208
|
+
|
|
209
|
+
#### `ParameterDefinition`
|
|
210
|
+
- `constructor(options?: ParameterDefinitionOptions)`
|
|
211
|
+
- `isValid(value: unknown): boolean`
|
|
212
|
+
- `convertValue(rawValue: unknown): number | boolean | string | null`
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## Development & Testing
|
|
217
|
+
|
|
218
|
+
### Commands
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
# Install dependencies
|
|
222
|
+
npm install
|
|
223
|
+
|
|
224
|
+
# Run TypeScript type check
|
|
225
|
+
npm run typecheck
|
|
226
|
+
|
|
227
|
+
# Run Vitest unit test suite
|
|
228
|
+
npm run test
|
|
229
|
+
|
|
230
|
+
# Run test coverage report
|
|
231
|
+
npm run test:coverage
|
|
232
|
+
|
|
233
|
+
# Build ESM, CJS, IIFE & .d.ts outputs
|
|
234
|
+
npm run build
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Repository Structure
|
|
240
|
+
|
|
241
|
+
```
|
|
242
|
+
skillprint-js-sdk/
|
|
243
|
+
โโโ src/
|
|
244
|
+
โ โโโ index.ts # Main entrypoint re-exporting public API
|
|
245
|
+
โ โโโ types.ts # TypeScript interface definitions
|
|
246
|
+
โ โโโ constants.ts # Enums: ApiEnvironment, ParameterType, Mood, LogLevel
|
|
247
|
+
โ โโโ config.ts # SkillprintConfig class
|
|
248
|
+
โ โโโ parameter-definition.ts # ParameterDefinition class
|
|
249
|
+
โ โโโ api-models.ts # DTO models & value convertors
|
|
250
|
+
โ โโโ api-client.ts # SkillprintAPIClient HTTP implementation
|
|
251
|
+
โ โโโ screenshot-utility.ts # ScreenshotUtility for Canvas & WebGL
|
|
252
|
+
โ โโโ url-parameter-extractor.ts # WebGLUrlParameterExtractor & session helper
|
|
253
|
+
โ โโโ manager.ts # SkillprintManager core singleton
|
|
254
|
+
โ โโโ adapters/ # Game engine adapters (Phaser, Three, Pixi, Canvas)
|
|
255
|
+
โโโ tests/ # Vitest automated unit test suite
|
|
256
|
+
โโโ dist/ # Built ESM, CJS, IIFE & .d.ts files
|
|
257
|
+
โโโ tsup.config.ts # tsup build configuration
|
|
258
|
+
โโโ vitest.config.ts # Vitest test configuration
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## License
|
|
264
|
+
|
|
265
|
+
MIT ยฉ [Skillprint Inc.](https://skillprint.com)
|