playertwo-sdk 0.2.11 → 0.2.13

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 CHANGED
@@ -1,16 +1,16 @@
1
1
  # playertwo-sdk
2
2
 
3
- The game SDK for [PlayerTwo](https://playertwo.lol), with TypeScript types. Trophies, XP and levels, stats,
4
- leaderboards, cloud saves, presence, invites, add-ons, in-game purchases, donations to you, the player's avatar, travel
5
- between games, and multiplayer rooms with no server of your own (voice chat, worlds, replays and your own server code in `room.js`
3
+ The game SDK for [PlayerTwo](https://playertwo.plus), with TypeScript types. Trophies, XP and levels, stats,
4
+ leaderboards, cloud saves, presence, invites, add-ons, in-game purchases, donations to you, moments to share, the
5
+ player's avatar, travel between games, and multiplayer rooms with no server of your own (voice chat, worlds, replays and your own server code in `room.js`
6
6
  included).
7
7
 
8
8
  PlayerTwo is a game store and a launchpad. Games are sold (or free) to play in the browser or download, and raises
9
9
  let players back a game while it is being made, paid to its developer stage by stage as they post proof. A web game
10
10
  hosted on PlayerTwo gets its own address on `playertwo.cc` and every service below through one account per player.
11
11
 
12
- - Docs: https://playertwo.lol/docs/sdk
13
- - Everything a game gets, with a link to its part of the docs: https://playertwo.lol/llms.txt
12
+ - Docs: https://playertwo.plus/docs/sdk
13
+ - Everything a game gets, with a link to its part of the docs: https://playertwo.plus/llms.txt
14
14
  - Source of these packages, examples and Markdown docs: https://github.com/TheDudeCommits/playertwo-sdk
15
15
 
16
16
  ## Install
@@ -31,7 +31,7 @@ Or no install at all: the SDK itself is one script.
31
31
  ```
32
32
 
33
33
  On PlayerTwo the script is already in your game's page. `init()` from the npm package uses that copy, and loads
34
- `https://playertwo.lol/sdk/v1.js` only when the page doesn't have it (on localhost, say).
34
+ `https://playertwo.plus/sdk/v1.js` only when the page doesn't have it (on localhost, say).
35
35
 
36
36
  ## Quick start
37
37
 
@@ -61,58 +61,60 @@ sync.on("leave", (id) => removeMesh(id));
61
61
  ```
62
62
 
63
63
  Every call returns a promise. A refusal rejects with an `Error` that has a `code` and a `status` (the codes:
64
- https://playertwo.lol/docs/sdk#call-errors). Off PlayerTwo and off localhost, `init()` rejects after 1.5 seconds
64
+ https://playertwo.plus/docs/sdk#call-errors). Off PlayerTwo and off localhost, `init()` rejects after 1.5 seconds
65
65
  with code `not-on-player-two`; with `{ required: true }` the page says "Play this on PlayerTwo" and stops.
66
66
 
67
67
  ## What it gives your game
68
68
 
69
69
  | Feature | Calls | Docs |
70
70
  | --- | --- | --- |
71
- | Who is playing | `p2.player`, `p2.game`, `p2.me()` | [call-me](https://playertwo.lol/docs/sdk#call-me) |
72
- | Trophies, XP and levels | `p2.trophies.list()`, `p2.trophies.unlock(key)` | [call-trophies](https://playertwo.lol/docs/sdk#call-trophies) |
73
- | Leaderboards | `p2.scores.submit(board, value)`, `p2.scores.list(board, { around, friends, limit })` | [call-scores](https://playertwo.lol/docs/sdk#call-scores) |
74
- | Stats | `p2.stats.get()`, `.get(key)`, `.set(key, n)`, `.add(key, n?)` | [call-stats](https://playertwo.lol/docs/sdk#call-stats) |
75
- | Cloud saves (8 slots, 1 MB each) | `p2.saves.list()`, `.get(slot)`, `.put(slot, data, { version })`, `.delete(slot)` | [call-saves](https://playertwo.lol/docs/sdk#call-saves) |
76
- | Add-ons (sold on the game's page) | `p2.addons.list()`, `p2.addons.has(key)` | [addons](https://playertwo.lol/docs/sdk#addons) |
77
- | In-game purchases | `p2.store.list()`, `.owned()`, `.buy(key)`, `.pay(chargeId)` | [purchases](https://playertwo.lol/docs/sdk#purchases) |
78
- | Donations to you | `p2.donate.available()`, `.open()`, `.button({ corner, parent })` | [donate](https://playertwo.lol/docs/sdk#donate) |
79
- | Presence | `p2.presence.set(line, { join })` | [call-presence](https://playertwo.lol/docs/sdk#call-presence) |
80
- | Identity and invites | `p2.identity()`, `p2.invite(params)`, `p2.params` | [call-identity](https://playertwo.lol/docs/sdk#call-identity) |
81
- | Loading and play events | `p2.loading.done()`, `p2.gameplay.start()`, `.stop()` | [call-gameplay](https://playertwo.lol/docs/sdk#call-gameplay) |
82
- | Your game's own events, in your studio's analytics | `p2.track(name, data)` | [call-track](https://playertwo.lol/docs/sdk#call-track) |
83
- | Its errors, caught by themselves | `p2.errors.report(error, where)`, `p2.errors.off()` | [call-crashes](https://playertwo.lol/docs/sdk#call-crashes) |
84
- | Feeds: outside data PlayerTwo fetches for your game | `p2.feeds.get(name)` | [feeds](https://playertwo.lol/docs/sdk#feeds) |
85
- | The overlay, and closing | `p2.on("overlay", fn)`, `p2.on("flush", fn)` | [call-overlay](https://playertwo.lol/docs/sdk#call-overlay) |
86
- | On air in the Plaza | `p2.onAir` | [call-air](https://playertwo.lol/docs/sdk#call-air) |
87
- | Test mode and demos | `p2.test`, `p2.demo` | [test](https://playertwo.lol/docs/sdk#test) |
88
- | The player's avatar, 2D and 3D | `p2.avatar()`, `p2.items.list()` | [travel#avatar](https://playertwo.lol/docs/sdk/travel#avatar) |
89
- | Travel with the party | `p2.travel.to(slug, { params, place })`, `.home()`, `.links()` | [travel#travel](https://playertwo.lol/docs/sdk/travel#travel) |
71
+ | Who is playing | `p2.player`, `p2.game`, `p2.me()` | [call-me](https://playertwo.plus/docs/sdk#call-me) |
72
+ | Trophies, XP and levels | `p2.trophies.list()`, `p2.trophies.unlock(key)` | [call-trophies](https://playertwo.plus/docs/sdk#call-trophies) |
73
+ | Leaderboards | `p2.scores.submit(board, value)`, `p2.scores.list(board, { around, friends, limit })` | [call-scores](https://playertwo.plus/docs/sdk#call-scores) |
74
+ | Stats | `p2.stats.get()`, `.get(key)`, `.set(key, n)`, `.add(key, n?)` | [call-stats](https://playertwo.plus/docs/sdk#call-stats) |
75
+ | Cloud saves (8 slots, 1 MB each) | `p2.saves.list()`, `.get(slot)`, `.put(slot, data, { version })`, `.delete(slot)` | [call-saves](https://playertwo.plus/docs/sdk#call-saves) |
76
+ | Add-ons (sold on the game's page) | `p2.addons.list()`, `p2.addons.has(key)` | [addons](https://playertwo.plus/docs/sdk#addons) |
77
+ | In-game purchases | `p2.store.list({ coming })`, `.owned()`, `.access()`, `.sold(refs)`, `.buy(key)`, `.pay(chargeId)` | [purchases](https://playertwo.plus/docs/sdk#purchases) |
78
+ | Donations to you | `p2.donate.available()`, `.open()`, `.button({ corner, parent })` | [donate](https://playertwo.plus/docs/sdk#donate) |
79
+ | Moments to share, on your results screen | `p2.moments.offer()` | [moments](https://playertwo.plus/docs/sdk#moments) |
80
+ | Presence | `p2.presence.set(line, { join })` | [call-presence](https://playertwo.plus/docs/sdk#call-presence) |
81
+ | Identity and invites | `p2.identity()`, `p2.invite(params)`, `p2.params` | [call-identity](https://playertwo.plus/docs/sdk#call-identity) |
82
+ | Loading and play events | `p2.loading.done()`, `p2.gameplay.start()`, `.stop()` | [call-gameplay](https://playertwo.plus/docs/sdk#call-gameplay) |
83
+ | Your game's own events, in your studio's analytics | `p2.track(name, data)` | [call-track](https://playertwo.plus/docs/sdk#call-track) |
84
+ | Its errors, caught by themselves | `p2.errors.report(error, where)`, `p2.errors.off()` | [call-crashes](https://playertwo.plus/docs/sdk#call-crashes) |
85
+ | Feeds: outside data PlayerTwo fetches for your game | `p2.feeds.get(name)` | [feeds](https://playertwo.plus/docs/sdk#feeds) |
86
+ | The overlay, and closing | `p2.on("overlay", fn)`, `p2.on("flush", fn)` | [call-overlay](https://playertwo.plus/docs/sdk#call-overlay) |
87
+ | On air in the Plaza | `p2.onAir` | [call-air](https://playertwo.plus/docs/sdk#call-air) |
88
+ | Test mode and demos | `p2.test`, `p2.demo` | [test](https://playertwo.plus/docs/sdk#test) |
89
+ | The player's avatar, 2D and 3D | `p2.avatar()`, `p2.items.list()` | [travel#avatar](https://playertwo.plus/docs/sdk/travel#avatar) |
90
+ | Travel with the party | `p2.travel.to(slug, { params, place })`, `.home()`, `.links()` | [travel#travel](https://playertwo.plus/docs/sdk/travel#travel) |
90
91
 
91
92
  Multiplayer, through `p2.rooms`:
92
93
 
93
94
  | Feature | Calls | Docs |
94
95
  | --- | --- | --- |
95
- | Matches, private codes, parties | `p2.rooms.join({ mode, size, teams, skill, together, code, room })`, `.create()`, `.party()` | [rooms-join](https://playertwo.lol/docs/sdk#rooms-join) |
96
- | Messages and shared state | `room.send(type, data, { to, fast })`, `room.on("message:<type>")`, `room.set`, `room.get`, `room.state` | [rooms-talk](https://playertwo.lol/docs/sdk#rooms-talk) |
97
- | Smooth movement | `room.sync(object, options)` | [rooms-sync](https://playertwo.lol/docs/sdk#rooms-sync) |
98
- | Ping, stats, the room's clock | `room.ping()`, `room.stats()`, `room.now()` | [rooms-fast](https://playertwo.lol/docs/sdk#rooms-fast) |
99
- | Your server code (`room.js`) | see below | [rooms-scripted](https://playertwo.lol/docs/sdk#rooms-scripted) |
100
- | Input-run rooms (client prediction, corrected by the server's state) | `room.inputs({ state, input, step })` | [rooms-inputs](https://playertwo.lol/docs/sdk#rooms-inputs) |
101
- | Corrections and lag-compensated hits | `onSync`, `room.correct`, `room.past` (room.js); `sync.seen(id)` | [rooms-corrections](https://playertwo.lol/docs/sdk#rooms-corrections) |
102
- | Server-moved objects | `room.objects()` (page), `room.objects.set` (room.js) | [rooms-objects](https://playertwo.lol/docs/sdk#rooms-objects) |
103
- | Physics engines in WebAssembly | a `room/` folder | [rooms-engines](https://playertwo.lol/docs/sdk#rooms-engines) |
104
- | Outside data, checked (a feed's signed items, relayed by a page) | `checkFeedItem(key, item, sig)` (room.js) | [rooms-feeds](https://playertwo.lol/docs/sdk#rooms-feeds) |
105
- | Teams and party matches | `{ teams, together }`, `room.team(id, n)` | [rooms-teams](https://playertwo.lol/docs/sdk#rooms-teams) |
106
- | Matching by skill (Elo by mode) | `{ skill: true }`, `room.result(places)` | [rooms-matching](https://playertwo.lol/docs/sdk#rooms-matching) |
107
- | Ranked boards and server-given trophies | `room.score`, `room.trophy` (room.js) | [rooms-ranked](https://playertwo.lol/docs/sdk#rooms-ranked) |
108
- | Watching and replays | `p2.rooms.live()`, `.watch({ room })`, `.replays()`, `.replay(id)`, `room.record()` | [rooms-watch](https://playertwo.lol/docs/sdk#rooms-watch) |
109
- | Worlds of up to 256 an area | `p2.rooms.world(name, { area })` | [rooms-worlds](https://playertwo.lol/docs/sdk#rooms-worlds) |
110
- | Voice chat (24 a room) | `room.voice.join()`, `.leave()`, `.mute()`, `.volume(id, v)`, `.speaking(id)` | [rooms-voice](https://playertwo.lol/docs/sdk#rooms-voice) |
111
- | A bad connection, on purpose | `p2.rooms.simulate({ lag, jitter, loss })` or `?p2-net=150,30,0.02` | [rooms-simulate](https://playertwo.lol/docs/sdk#rooms-simulate) |
96
+ | Matches, private codes, parties | `p2.rooms.join({ mode, size, teams, skill, together, code, room })`, `.create()`, `.party()` | [rooms-join](https://playertwo.plus/docs/sdk#rooms-join) |
97
+ | Messages and shared state | `room.send(type, data, { to, fast })`, `room.on("message:<type>")`, `room.set`, `room.get`, `room.state` | [rooms-talk](https://playertwo.plus/docs/sdk#rooms-talk) |
98
+ | Smooth movement | `room.sync(object, options)` | [rooms-sync](https://playertwo.plus/docs/sdk#rooms-sync) |
99
+ | Ping, stats, the room's clock | `room.ping()`, `room.stats()`, `room.now()` | [rooms-fast](https://playertwo.plus/docs/sdk#rooms-fast) |
100
+ | Your server code (`room.js`) | see below | [rooms-scripted](https://playertwo.plus/docs/sdk#rooms-scripted) |
101
+ | What each player owns of your store, in `room.js` | `player.owned`, `room.owned(id)`, `room.owns(id, keyOrRef)`, `onOwned` | [rooms-scripted](https://playertwo.plus/docs/sdk#rooms-scripted) |
102
+ | Input-run rooms (client prediction, corrected by the server's state) | `room.inputs({ state, input, step })` | [rooms-inputs](https://playertwo.plus/docs/sdk#rooms-inputs) |
103
+ | Corrections and lag-compensated hits | `onSync`, `room.correct`, `room.past` (room.js); `sync.seen(id)` | [rooms-corrections](https://playertwo.plus/docs/sdk#rooms-corrections) |
104
+ | Server-moved objects | `room.objects()` (page), `room.objects.set` (room.js) | [rooms-objects](https://playertwo.plus/docs/sdk#rooms-objects) |
105
+ | Physics engines in WebAssembly | a `room/` folder | [rooms-engines](https://playertwo.plus/docs/sdk#rooms-engines) |
106
+ | Outside data, checked (a feed's signed items, relayed by a page) | `checkFeedItem(key, item, sig)` (room.js) | [rooms-feeds](https://playertwo.plus/docs/sdk#rooms-feeds) |
107
+ | Teams and party matches | `{ teams, together }`, `room.team(id, n)` | [rooms-teams](https://playertwo.plus/docs/sdk#rooms-teams) |
108
+ | Matching by skill (Elo by mode) | `{ skill: true }`, `room.result(places)` | [rooms-matching](https://playertwo.plus/docs/sdk#rooms-matching) |
109
+ | Ranked boards and server-given trophies | `room.score`, `room.trophy` (room.js) | [rooms-ranked](https://playertwo.plus/docs/sdk#rooms-ranked) |
110
+ | Watching and replays | `p2.rooms.live()`, `.watch({ room })`, `.replays()`, `.replay(id)`, `room.record()` | [rooms-watch](https://playertwo.plus/docs/sdk#rooms-watch) |
111
+ | Worlds of up to 256 an area | `p2.rooms.world(name, { area })` | [rooms-worlds](https://playertwo.plus/docs/sdk#rooms-worlds) |
112
+ | Voice chat (24 a room) | `room.voice.join()`, `.leave()`, `.mute()`, `.volume(id, v)`, `.speaking(id)` | [rooms-voice](https://playertwo.plus/docs/sdk#rooms-voice) |
113
+ | A bad connection, on purpose | `p2.rooms.simulate({ lag, jitter, loss })` or `?p2-net=150,30,0.02` | [rooms-simulate](https://playertwo.plus/docs/sdk#rooms-simulate) |
112
114
 
113
115
  Rooms are 1 to 64 players (256 in an area of a world) and are for games hosted on PlayerTwo (a build you push, or
114
- your own site served through PlayerTwo). A release never mixes versions in a room. All limits:
115
- https://playertwo.lol/docs/sdk#rooms-limits.
116
+ a game already played from its own site that PlayerTwo serves). A release never mixes versions in a room. All limits:
117
+ https://playertwo.plus/docs/sdk#rooms-limits.
116
118
 
117
119
  ## A room's server: `playertwo-sdk/room`
118
120
 
@@ -174,17 +176,17 @@ export function onMessage(room, player, type, data) {
174
176
 
175
177
  A feed is public (anyone can read `GET /api/v1/games/<slug>/feeds/<name>`); its secret, put into a header's
176
178
  `{{secret}}` as it is fetched, never leaves PlayerTwo. A game nobody opened in the last 24 hours has its feeds left
177
- alone until someone does. Every rule: https://playertwo.lol/docs/sdk#feeds-setup.
179
+ alone until someone does. Every rule: https://playertwo.plus/docs/sdk#feeds-setup.
178
180
 
179
181
  ## Building without PlayerTwo
180
182
 
181
183
  On localhost, a stand-in answers every call from memory, and two tabs are two players. If your dev server serves
182
184
  `/room.js`, the first tab runs it as the room's server. Give the stand-in your trophies, add-ons, products and params
183
185
  with `init({ local: { ... } })` (and what `p2.feeds.get` answers, `local.feeds`); `local: true` (or `{ force: true }`) uses it wherever the game runs. There, `p2.track` and errors are said in the console. Voice needs a
184
- room on PlayerTwo. Docs: https://playertwo.lol/docs/sdk#start-local.
186
+ room on PlayerTwo. Docs: https://playertwo.plus/docs/sdk#start-local.
185
187
 
186
188
  On PlayerTwo you, your team and your playtesters play in test mode (`p2.test` is true): every call works, nothing is
187
- paid, and what you earn is kept apart. Docs: https://playertwo.lol/docs/sdk#test.
189
+ paid, and what you earn is kept apart. Docs: https://playertwo.plus/docs/sdk#test.
188
190
 
189
191
  Using the script tag and only want the types of the global `PlayerTwo`? Add `"types": ["playertwo-sdk"]` to your
190
192
  `tsconfig.json`, or `/// <reference types="playertwo-sdk" />` at the top of a file.
@@ -193,11 +195,24 @@ Using the script tag and only want the types of the global `PlayerTwo`? Add `"ty
193
195
 
194
196
  Two ways, and a game can use both: products you make in your studio (`p2.store.buy(key)`), or charges your own server
195
197
  makes at its own prices with your game key (`p2.store.pay(chargeId)`). PlayerTwo's own card takes the player's yes
196
- and the payment from their PlayerTwo balance (USDC on Base). You get 80% of every in-game purchase, PlayerTwo keeps
198
+ and the payment from their PlayerTwo balance (one balance, added by card, PayPal or stablecoins), showing the piece's
199
+ picture big when you give one. You get 80% of every in-game purchase, PlayerTwo keeps
197
200
  20% (less your backers' share if your game raised with a share of its sales). Add-ons sold on the game's page are split
198
201
  as its sales are: PlayerTwo keeps 20%. Every purchase gives your game a signed receipt (a JWT typed `p2-buy`, RS256,
199
- keys at https://playertwo.lol/.well-known/p2-keys.json) and your studio's webhooks a `purchase` event. Docs:
200
- https://playertwo.lol/docs/sdk#purchases.
202
+ keys at https://playertwo.plus/.well-known/p2-keys.json) and your studio's webhooks a `purchase` event.
203
+
204
+ - **Who may buy:** `p2.store.access()` says where the player stands: `owned`, `free-game`, `free-period` (a paid game
205
+ played free for a while, with `until`), `test` or `none`. Every state but `none` may buy in the game, and what they
206
+ buy stays theirs.
207
+ - **Counts:** each product's `owners` ("Owned by N players"), and `p2.store.sold(refs)`: how many of your charges were
208
+ paid with each ref. A paid charge carries its `number` among them, for "#12 of Season 1".
209
+ - **Seasons:** a product's `onSaleFrom` and `onSaleUntil` take it on and off sale by themselves, and its owners keep it.
210
+ `p2.store.list({ coming: true })` lists the ones not on sale yet, `coming: true`, never buyable.
211
+ - **Packs:** a pack can be sold only to a player who owns none of its pieces (`noneOwned`).
212
+ - **In a room:** each player's `owned` arrives as they take their seat and again when they buy (`onOwned`);
213
+ `room.owns(id, keyOrRef)` refuses a look they don't own.
214
+
215
+ Docs: https://playertwo.plus/docs/sdk#purchases and https://playertwo.plus/docs/sdk#store-access.
201
216
 
202
217
  ## Donations
203
218
 
@@ -205,56 +220,62 @@ Players can donate to your studio for your game, even while it's free. Turn dona
205
220
  Donations) and pick their one place: your game's PlayerTwo page (PlayerTwo's card, in your words, colour and picture),
206
221
  or inside the game. Inside the game, your own button calls `p2.donate.open()` to open PlayerTwo's donation sheet, or
207
222
  `p2.donate.button()` puts PlayerTwo's pixel-heart "Support the dev" button in a corner (or inside an element of yours);
208
- `p2.donate.available()` says whether donations are on inside the game. The entire donation, minus the transaction fees,
223
+ `p2.donate.available()` says whether donations are on inside the game. A press of the player's opens the sheet at once,
224
+ however soon after the last (call `open()` within a second of it); asked without one, it opens at most once every two
225
+ minutes (`too-soon`). The entire donation, minus the transaction fees,
209
226
  goes to your studio: PlayerTwo takes no cut. A donation buys nothing in the game, and the game never learns who gave
210
- or how much, so it never belongs in your shop. Docs: https://playertwo.lol/docs/sdk#donate.
227
+ or how much, so it never belongs in your shop. Docs: https://playertwo.plus/docs/sdk#donate.
211
228
 
212
229
  ## Your game's own server
213
230
 
214
231
  A game key (`p2g_...`, made in your studio) lets your server check a session or a signed identity from
215
232
  `p2.identity()`, give server-only trophies, post to trusted leaderboards, read add-ons, make and check charges, use up
216
- consumables and report matches, under `https://playertwo.lol/api/v1/sdk/server/...`. Docs:
217
- https://playertwo.lol/docs/sdk#server and https://playertwo.lol/docs/sdk/connect (a game played on its own site).
233
+ consumables and report matches, under `https://playertwo.plus/api/v1/sdk/server/...`. Docs:
234
+ https://playertwo.plus/docs/sdk#server and https://playertwo.plus/docs/sdk/connect (a game already played on its own
235
+ site).
218
236
 
219
237
  ## Putting it on PlayerTwo
220
238
 
221
239
  A whole game to start from: `npm create playertwo-game@latest my-game` (a small multiplayer Three.js game with rooms
222
240
  and `room.js`, see [create-playertwo-game](https://www.npmjs.com/package/create-playertwo-game)).
223
241
 
224
- 1. Submit the game at https://playertwo.lol/submit (that gives it its address, `your-game`).
225
- 2. Make an agent key in your studio, under Agents.
242
+ 1. Submit the game at https://playertwo.plus/submit with its web build: a zip of its folder (up to 5 GB unpacked,
243
+ 20,000 files, 512 MB a file), sent from your browser a file at a time, or one .html page. That gives it its
244
+ address, `your-game`. Playing from your own site is closed to new games.
245
+ 2. Each update goes up the same way (a zip, from its page's editor in your studio), or pushed: make an agent key in your
246
+ studio, under Agents.
226
247
  3. Push the build:
227
248
 
228
249
  ```
229
- curl -fsSLO https://playertwo.lol/cli/p2.mjs
250
+ curl -fsSLO https://playertwo.plus/cli/p2.mjs
230
251
  P2_AGENT_KEY=p2_agent_... node p2.mjs push dist --game your-game --version 1.0.0
231
252
  ```
232
253
 
233
254
  It plays at `https://your-game.playertwo.cc/` in PlayerTwo's player, with no code changes. A pushed folder may be up to
234
- 5 GB and 20,000 files; only the files PlayerTwo doesn't have yet are sent. Docs: https://playertwo.lol/docs/hosting.
255
+ 5 GB and 20,000 files; only the files PlayerTwo doesn't have yet are sent. Docs: https://playertwo.plus/docs/hosting.
235
256
 
236
257
  ## For AI agents: MCP and the agent API
237
258
 
238
- PlayerTwo runs an MCP server (Streamable HTTP) at `https://playertwo.lol/api/mcp`:
259
+ PlayerTwo runs an MCP server (Streamable HTTP) at `https://playertwo.plus/api/mcp`:
239
260
 
240
261
  ```
241
- claude mcp add --transport http player-two https://playertwo.lol/api/mcp
242
- claude mcp add --transport http player-two https://playertwo.lol/api/mcp --header "Authorization: Bearer p2_agent_..."
262
+ claude mcp add --transport http player-two https://playertwo.plus/api/mcp
263
+ claude mcp add --transport http player-two https://playertwo.plus/api/mcp --header "Authorization: Bearer p2_agent_..."
243
264
  ```
244
265
 
245
266
  The first line is enough for the public tools, which need no key: `get_submission_guide` and `check_game`, and
246
267
  `search_games`, `list_games`, `get_game_facts`, `get_sdk_docs` and `where_to_publish`. Tools that change a game
247
268
  (submit it, edit its page, upload media and web builds, define trophies, leaderboards and products, roll back builds,
248
- post updates, read its rooms) need the player's agent key, made in their studio on playertwo.lol under Agents, or no
269
+ post updates, read its rooms) need the player's agent key, made in their studio on playertwo.plus under Agents, or no
249
270
  key at all in a client that signs in (Claude's and ChatGPT's connectors, Claude Code, Cursor): the first time it calls
250
- one, the player is asked to sign in to PlayerTwo and allow it (OAuth 2.1 with PKCE). Its MCP Registry name is
251
- `lol.playertwo/mcp`; its server card is at https://playertwo.lol/.well-known/mcp.json.
252
-
253
- - The agent API: `GET https://playertwo.lol/api/v1/agent/guide` explains every field; submit with
254
- `POST https://playertwo.lol/api/v1/agent/games` `{ "draft": { ... }, "publish": true }`.
255
- - OpenAPI 3.1 spec: https://playertwo.lol/openapi.json
256
- - For language models: https://playertwo.lol/llms.txt
257
- - Docs: https://playertwo.lol/docs#agents
271
+ one, the player is asked to sign in to PlayerTwo and allow it (OAuth 2.1 with PKCE). Its server card is at
272
+ https://playertwo.plus/.well-known/mcp.json.
273
+
274
+ - The agent API: `GET https://playertwo.plus/api/v1/agent/guide` explains every field; submit with
275
+ `POST https://playertwo.plus/api/v1/agent/games` `{ "draft": { ... }, "publish": true }`.
276
+ - OpenAPI 3.1 spec: https://playertwo.plus/openapi.json
277
+ - For language models: https://playertwo.plus/llms.txt
278
+ - Docs: https://playertwo.plus/docs#agents
258
279
 
259
280
  ## License
260
281
 
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Types for PlayerTwo's game SDK, https://playertwo.lol/sdk/v1.js (its source: public/sdk/v1.js in PlayerTwo's code;
3
- * keep these in step with its part 4, "the helpers the game uses", and part 4b, "rooms"). Docs: https://playertwo.lol/docs/sdk
2
+ * Types for PlayerTwo's game SDK, https://playertwo.plus/sdk/v1.js (its source: public/sdk/v1.js in PlayerTwo's code;
3
+ * keep these in step with its part 4, "the helpers the game uses", and part 4b, "rooms"). Docs: https://playertwo.plus/docs/sdk
4
4
  *
5
5
  * import { init } from "playertwo-sdk"; // or the global PlayerTwo, from the script tag
6
6
  * const p2 = await init();
@@ -209,7 +209,7 @@ export interface Product {
209
209
  name: string;
210
210
  about: string;
211
211
  /** Its picture, when its studio gave it one: an https address in PlayerTwo's file store. PlayerTwo's card shows it
212
- beside the name; use it in your own shop too. */
212
+ big, over the name; use it in your own shop too. */
213
213
  picture?: string;
214
214
  /** In US dollars. */
215
215
  price: number;
@@ -220,6 +220,31 @@ export interface Product {
220
220
  owned: boolean;
221
221
  /** A consumable's: how many the player has. */
222
222
  count?: number;
223
+ /** How many players own it ("Owned by N players"): tests not counted; a pack's buyers; a consumable's, everyone who
224
+ ever bought it. Up to 30 seconds behind. */
225
+ owners: number;
226
+ /** Its on-sale dates (ms), or null: outside them it's off sale by itself (its owners keep it). Read your season clock
227
+ from these. */
228
+ onSaleFrom: number | null;
229
+ onSaleUntil: number | null;
230
+ /** Listed by list({ coming: true }) before its on-sale date: never buyable (buy rejects "not-yet"). */
231
+ coming?: boolean;
232
+ /** A pack's: sold only to a player who owns none of its pieces (buy rejects "owns-piece"). */
233
+ noneOwned?: boolean;
234
+ }
235
+
236
+ /** Where the player stands with the game (p2.store.access; docs: /docs/sdk#store-access). Every state but "none" may
237
+ buy in the game, and what they buy stays theirs. */
238
+ export interface Access {
239
+ /** owned: they own it. free-game: it costs nothing. free-period: a paid game played free for a while (never owning
240
+ it). test: its team and testers. none: no-game. */
241
+ state: "owned" | "free-game" | "free-period" | "test" | "none";
242
+ /** A free period by sale: when it ends (ms). */
243
+ until: number | null;
244
+ /** A free period by trial: seconds of play left. */
245
+ left?: number;
246
+ /** What the free period is: the game's free-to-play sale, or the player's own free trial. */
247
+ via?: "sale" | "trial";
223
248
  }
224
249
 
225
250
  /** What the player has of the game's products (a consumable: how many). */
@@ -243,8 +268,9 @@ export type Bought =
243
268
  export type Paid =
244
269
  | {
245
270
  ok: true;
246
- /** `ref`: your own reference for it, as your server gave it. */
247
- charge: { id: string; name: string; ref: string | null };
271
+ /** `ref`: your own reference for it, as your server gave it. `number`: its place among the charges paid with
272
+ that ref (1 for the first; null for a test, or with no ref), for "#12 of Season 1". */
273
+ charge: { id: string; name: string; ref: string | null; number: number | null };
248
274
  /** What was paid, in US dollars (0 for a test). */
249
275
  amount: number;
250
276
  /** A JWT typed "p2-buy" (kind "charge", key the charge's id), RS256 with PlayerTwo's keys, for your own server: an hour. */
@@ -259,14 +285,22 @@ export type Paid =
259
285
  export type SignUpAnswer = { ok: true; card?: true; local?: true } | { ok: false; reason: "cancelled" };
260
286
 
261
287
  export interface Store {
262
- /** Each product on sale, with what the player has of it. */
263
- list(): Promise<Product[]>;
288
+ /** Each product on sale, with what the player has of it; { coming: true } lists those whose on-sale date is ahead
289
+ too, each coming: true and never buyable. */
290
+ list(options?: { coming?: boolean }): Promise<Product[]>;
264
291
  /** What the player has. */
265
292
  owned(): Promise<Holding[]>;
293
+ /** Where the player stands with the game: owned, a free game, a free period (with its end), a test, or none. */
294
+ access(): Promise<Access>;
295
+ /** How many of your charges were paid with each ref (a ref ending in * counts every ref starting so): { [ref]: n }.
296
+ Tests not counted. */
297
+ sold(refs: string[] | string): Promise<Record<string, number>>;
266
298
  /** Asks PlayerTwo to sell one: its own step, outside the game's frame, where the player says yes. Rejects with code
267
299
  "no-store" where it can't (outside PlayerTwo's player on the web), "busy" (its sheet is open already),
268
- "unknown-product", "owned" (a skin, item or mod they have), "no-game" (they don't have the game yet), "guest" or
269
- "offline". */
300
+ "unknown-product" (nothing on sale by that key: retired, or past its on-sale end), "not-yet" (before its on-sale
301
+ start; from: when, ms), "owned" (a skin, item or mod they have), "pack-owned" (a pack whose pieces are all theirs),
302
+ "owns-piece" (a pack sold to players who own none of it; owned: the keys), "no-game" (they may not buy in it: see
303
+ access()), "guest" or "offline". */
270
304
  buy(key: string): Promise<Bought>;
271
305
  /** Asks the player to pay a charge your server made (POST /api/v1/sdk/server/store/charges, your game's key): its
272
306
  name and price on PlayerTwo's card, paid once; one paid already answers its receipt again. Rejects with code
@@ -278,15 +312,28 @@ export interface Store {
278
312
  /** What p2.donate.open() answers: the sheet was shown (never how much, nor whether anything was given), or why not. */
279
313
  export type DonateShown = { shown: true; local?: true } | { shown: false; reason: "off" | "placement" | "too-soon" };
280
314
 
315
+ /** Moments to share (p2.moments; docs: /docs/sdk#moments): the player's best moment of this session, which PlayerTwo
316
+ picks from what the game already sent it (a new best, a rare trophy, a level, the hours), offered on the game's own
317
+ results screen. */
318
+ export interface Moments {
319
+ /** Call it once your results screen is showing, never during play. When the session did something worth sharing,
320
+ PlayerTwo's share sheet opens over the game and this resolves once it closes ({ offered: true, shared }); otherwise
321
+ (nothing worth it, offers turned off, a guest, a test, outside PlayerTwo's player, a second ask this session) it
322
+ resolves { offered: false, shared: false } at once. Never rejects. One ask a session: offered here, closing the game
323
+ asks nothing more. */
324
+ offer(): Promise<{ offered: boolean; shared: boolean }>;
325
+ }
326
+
281
327
  /** Donations to the game's developer (p2.donate; docs: /docs/sdk#donate), when its studio put them inside the game (its
282
328
  one place: the game or its PlayerTwo page). The entire donation, minus the transaction fees, goes to the studio; PlayerTwo takes
283
329
  nothing. A donation buys nothing in the game, and the game never learns of one. */
284
330
  export interface Donate {
285
331
  /** Whether the game takes donations inside itself now. */
286
332
  available(): Promise<boolean>;
287
- /** Opens PlayerTwo's donation sheet over the game (from the player's press on your own button). At most once every
288
- two minutes. Rejects with code "no-donate" outside PlayerTwo's player on the web, "busy" while another of its
289
- sheets is open. */
333
+ /** Opens PlayerTwo's donation sheet over the game (from the player's press on your own button). A press opens it at
334
+ once, however soon after the last (call it within a second of the press: the browser's navigator.userActivation is
335
+ sent with it); without one, at most once every two minutes ("too-soon"). Rejects with code "no-donate" outside
336
+ PlayerTwo's player on the web, "busy" while another of its sheets is open. */
290
337
  open(): Promise<DonateShown>;
291
338
  /** PlayerTwo's own Donate button (a pixel heart, "Support the dev"), for a game that draws none: in a corner of the
292
339
  page, or inside an element of yours. Shown only while the game takes donations inside itself; null otherwise. */
@@ -728,9 +775,10 @@ export interface Avatar {
728
775
  export interface Item {
729
776
  key: string;
730
777
  name: string;
731
- kind: "skin" | "avatar" | "wear" | "emote" | "effect";
778
+ kind: "skin" | "avatar" | "wear" | "emote" | "effect" | "frame";
732
779
  tier: "common" | "rare" | "epic" | "legendary" | "mythic" | "divine";
733
- /** Where it goes: head, face, neck or back for a wearable; skin, avatar or effect; none for an emote. */
780
+ /** Where it goes: head, face, neck or back for a wearable; skin, avatar, effect or frame (what the moments a player
781
+ shares on PlayerTwo wear, earned, never sold: "crew-frame"); none for an emote. */
734
782
  slot: string | null;
735
783
  /** Whether the player has it on. */
736
784
  worn: boolean;
@@ -762,7 +810,7 @@ export interface Door {
762
810
  /** Travel to other games on PlayerTwo, with the player's party. In PlayerTwo's player on the web; elsewhere each
763
811
  rejects with code "no-travel". */
764
812
  export interface Travel {
765
- /** To another game, by its address (playertwo.lol/game/<slug>): it is given p2.params (yours, then `from`, this
813
+ /** To another game, by its address (playertwo.plus/game/<slug>): it is given p2.params (yours, then `from`, this
766
814
  game's address, and `place`). Resolves as the player goes; this page is closed after. */
767
815
  to(slug: string, options?: { params?: Record<string, string>; place?: string }): Promise<{ to: { slug: string; title: string }; params: Record<string, string> }>;
768
816
  /** Back to the Plaza, where every game on PlayerTwo has its screen. */
@@ -843,6 +891,7 @@ export interface P2 {
843
891
  store: Store;
844
892
  /** Donations to the game's developer, when its studio put them inside the game. */
845
893
  donate: Donate;
894
+ moments: Moments;
846
895
  stats: Stats;
847
896
  scores: Scores;
848
897
  saves: Saves;
@@ -900,13 +949,13 @@ export interface PlayerTwoGlobal {
900
949
  }
901
950
 
902
951
  declare global {
903
- /** PlayerTwo's SDK, from https://playertwo.lol/sdk/v1.js (on PlayerTwo, already in the page). */
952
+ /** PlayerTwo's SDK, from https://playertwo.plus/sdk/v1.js (on PlayerTwo, already in the page). */
904
953
  var PlayerTwo: PlayerTwoGlobal;
905
954
  }
906
955
 
907
956
  /** Where the SDK is loaded from when the page doesn't have it. */
908
957
  export const SDK_URL: string;
909
- /** Where it is looked for, in turn: SDK_URL (playertwo.lol), then playertwo.plus. */
958
+ /** Where it is looked for, in turn: SDK_URL (playertwo.plus). */
910
959
  export const SDK_URLS: readonly string[];
911
960
 
912
961
  /** window.PlayerTwo, loading the script from `src`, else from each of SDK_URLS in turn, if the page doesn't have it. */
package/index.mjs CHANGED
@@ -1,15 +1,14 @@
1
1
  // playertwo-sdk: PlayerTwo's game SDK for code that is bundled (Vite, webpack, esbuild). The SDK itself is one
2
- // script, https://playertwo.lol/sdk/v1.js, which PlayerTwo's games host puts in a hosted game's page; this uses that
2
+ // script, https://playertwo.plus/sdk/v1.js, which PlayerTwo's games host puts in a hosted game's page; this uses that
3
3
  // copy when the page has it, and otherwise loads the script and waits for it. Types: index.d.ts. Docs:
4
- // https://playertwo.lol/docs/sdk
4
+ // https://playertwo.plus/docs/sdk
5
5
  //
6
6
  // import { init } from "playertwo-sdk";
7
7
  // const p2 = await init(); // the same as PlayerTwo.init(), with the same options
8
8
 
9
- export const SDK_URL = "https://playertwo.lol/sdk/v1.js";
10
- /** Where the script is looked for, in turn: playertwo.lol, then playertwo.plus (which stood in for it while it was held
11
- by its registry, 2026-11-09, and still serves the same SDK). */
12
- export const SDK_URLS = [SDK_URL, "https://playertwo.plus/sdk/v1.js"];
9
+ export const SDK_URL = "https://playertwo.plus/sdk/v1.js";
10
+ /** Where the script is looked for, in turn: PlayerTwo's address, playertwo.plus. */
11
+ export const SDK_URLS = [SDK_URL];
13
12
 
14
13
  let loading = null;
15
14
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "playertwo-sdk",
3
- "version": "0.2.11",
4
- "description": "SDK for HTML5 and browser games on PlayerTwo (playertwo.lol): trophies, leaderboards, stats, cloud saves, in-game purchases, donations to the developer, your own events and errors in your analytics, feeds of outside data, voice chat and multiplayer rooms with server-side room code.",
3
+ "version": "0.2.13",
4
+ "description": "SDK for HTML5 and browser games on PlayerTwo (playertwo.plus): trophies, leaderboards, stats, cloud saves, in-game purchases, donations to the developer, your own events and errors in your analytics, feeds of outside data, voice chat and multiplayer rooms with server-side room code.",
5
5
  "keywords": [
6
6
  "playertwo",
7
7
  "player-two",
@@ -24,7 +24,7 @@
24
24
  "typescript",
25
25
  "threejs"
26
26
  ],
27
- "homepage": "https://playertwo.lol/docs/sdk",
27
+ "homepage": "https://playertwo.plus/docs/sdk",
28
28
  "bugs": {
29
29
  "url": "https://github.com/TheDudeCommits/playertwo-sdk/issues"
30
30
  },
@@ -34,7 +34,7 @@
34
34
  "directory": "packages/sdk"
35
35
  },
36
36
  "license": "MIT",
37
- "author": "PlayerTwo <hello@playertwo.lol>",
37
+ "author": "PlayerTwo <hello@playertwo.plus>",
38
38
  "type": "module",
39
39
  "main": "./index.mjs",
40
40
  "module": "./index.mjs",
package/room.d.ts CHANGED
@@ -42,8 +42,15 @@ export interface Player {
42
42
  ping: number | null;
43
43
  /** How much their round trip varies, in ms (null until known). */
44
44
  jitter: number | null;
45
+ /** (r29) What they own of the game's store, read from PlayerTwo as they take their seat in a room of a game that
46
+ sells, and again when they buy in the room (onOwned); null when the game sells nothing or it couldn't be read. */
47
+ owned: Owned | null;
45
48
  }
46
49
 
50
+ /** What a player owns of the game's store (r29): the keys of the products they own (a consumable while they have
51
+ some), a consumable's count by key, and the refs of the charges they paid. */
52
+ export interface Owned { products: string[]; counts: Record<string, number>; refs: string[] }
53
+
47
54
  /** What room.js is handed: the room it runs for. `D` is what you keep in room.data. */
48
55
  /** A physics body room.objects.set takes as it is: Rapier's (translation() and rotation()), or one with a position and
49
56
  a quaternion. */
@@ -57,6 +64,10 @@ export interface Room<D extends object = Record<string, any>> {
57
64
  readonly id: string;
58
65
  /** Who is here. */
59
66
  readonly players: readonly Player[];
67
+ /** (r29) What a player owns of the game's store (player.owned), or null. */
68
+ owned(id: string): Owned | null;
69
+ /** (r29) Whether a player owns a product (by its key) or paid a charge with that ref: refuse a look they don't own. */
70
+ owns(id: string, keyOrRef: string): boolean;
60
71
  /** One of them, or null. */
61
72
  player(id: string): Player | null;
62
73
  /** A message to every page in the room, or to `to` (an id, or a list). Pages hear it with room.on("message:<type>"). */
@@ -167,6 +178,8 @@ export interface RoomScript<D extends object = Record<string, any>> {
167
178
  /** `inputs`: in an input-run room (its pages send room.inputs), each player's input for this step, by id (none when
168
179
  theirs didn't come in time); dt is then always 1 / tickRate, the steps kept to real time. */
169
180
  onTick?(room: Room<D>, dt: number, inputs: Record<string, any>): void;
181
+ /** (r29) What a player owns changed while they're here: they bought something in the game. */
182
+ onOwned?(room: Room<D>, player: Player, owned: Owned | null): void;
170
183
  }
171
184
 
172
185
  /** Types every hook at once: answers `script` as it is. */