@powly/sdk 0.0.0-stage → 0.4.0
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 +55 -2
- package/dist/powly.d.ts +668 -0
- package/dist/powly.js +1376 -0
- package/dist/powly.mjs +1374 -0
- package/package.json +38 -3
package/README.md
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @powly/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The SDK for games on [Powly](https://powly.gg): the launch handshake with Powly, the player's
|
|
4
|
+
profile, session tokens and the platform services (saves, leaderboards, achievements, friends,
|
|
5
|
+
invites, multiplayer rooms, Twitch chat).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @powly/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Starting a new game? `npm create powly-game@latest my-game` sets up a React + Vite project with
|
|
14
|
+
the SDK.
|
|
15
|
+
|
|
16
|
+
## Use
|
|
17
|
+
|
|
18
|
+
Call `Powly.init()` as early as possible (before loading your game's assets): Powly expects the
|
|
19
|
+
handshake promptly, and it only succeeds when the game was launched from Powly.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import Powly from "@powly/sdk";
|
|
23
|
+
|
|
24
|
+
const powly = await Powly.init();
|
|
25
|
+
|
|
26
|
+
powly.profile.username;
|
|
27
|
+
const level = (await powly.saves.get<number>("level")) ?? 1;
|
|
28
|
+
await powly.leaderboards.submit("high-score", 1200);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Without a bundler, load the classic script instead; it defines `window.Powly`:
|
|
32
|
+
|
|
33
|
+
```html
|
|
34
|
+
<script src="https://cdn.jsdelivr.net/npm/@powly/sdk@0.4.0/dist/powly.js"></script>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Testing
|
|
38
|
+
|
|
39
|
+
Run your dev server and open it in **Studio → Developer mode** (for example
|
|
40
|
+
`http://localhost:5173`). Opened directly, `Powly.init()` rejects with "This game only runs when
|
|
41
|
+
launched from Powly."
|
|
42
|
+
|
|
43
|
+
## Self-hosted Powly
|
|
44
|
+
|
|
45
|
+
This package trusts `https://powly.gg` and `http://localhost:3000`. For another Powly
|
|
46
|
+
installation, pass its origin:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
await Powly.init({ powlyOrigin: "https://games.example.com" });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Security
|
|
53
|
+
|
|
54
|
+
The game runs in the player's browser, so nothing here is a security boundary. Saves and
|
|
55
|
+
leaderboard scores are written by your backend unless the studio allows browser writes for them;
|
|
56
|
+
your backend verifies session tokens or exchanges them for an access token.
|