feat!: balances and items replace the wallet in the player profile
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
# Player — `client.player`
|
||||
|
||||
`PlayerDomain` (source: `src/domains/PlayerDomain.ts`) — the observable player
|
||||
profile: player, linked identities, currency wallets and
|
||||
number counters. Synced under revision key `profile`.
|
||||
profile: player, linked identities, currency balances and inventory stacks.
|
||||
Synced under revision key `profile`.
|
||||
|
||||
There is no separate wallet service in this SDK. Wallet balances are read from
|
||||
the profile and are credited/debited server-side (admin wallet adjust, module
|
||||
functions).
|
||||
There is no separate ledger service in this SDK. Balances and items are read
|
||||
from the profile and are written server-side (admin adjust, module functions).
|
||||
|
||||
## Surface
|
||||
|
||||
@@ -24,10 +23,10 @@ await client.player.reload(); // force refetch
|
||||
|
||||
```ts
|
||||
interface PlayerProfile {
|
||||
counters?: { [slug: string]: number }; // client-visible number counters
|
||||
balances?: Balance[];
|
||||
identities?: PlayerProfileIdentity[];
|
||||
items?: InventoryStack[];
|
||||
player?: Player;
|
||||
wallets?: Wallet[];
|
||||
}
|
||||
|
||||
interface PlayerProfileIdentity {
|
||||
@@ -45,20 +44,25 @@ interface Player {
|
||||
region?: string;
|
||||
}
|
||||
|
||||
interface Wallet {
|
||||
interface Balance {
|
||||
balance?: number;
|
||||
currency?: string; // currency code configured in the dashboard
|
||||
currency?: string; // currency slug configured in the dashboard
|
||||
}
|
||||
|
||||
interface InventoryStack {
|
||||
item?: string; // item slug
|
||||
quantity?: number;
|
||||
}
|
||||
```
|
||||
|
||||
## Behavior notes
|
||||
|
||||
- `counters` holds the values of `number` counters whose definition is
|
||||
`client_visible`; hidden counters are left out. Currency counters are in
|
||||
`wallets`, not in `counters`. Counter changes bump the `profile` revision.
|
||||
- `balances` carries one entry per currency in the latest release, zero-filled
|
||||
for a player who never received it; `items` carries one entry per non-empty
|
||||
inventory stack. Both bump the `profile` revision when they change.
|
||||
- Warmed automatically at login (with catalog).
|
||||
- Kept fresh by the revision poll; call `reload()` after a module function
|
||||
that changes wallets or counters.
|
||||
that changes balances or items.
|
||||
- All fields are optional on the wire (`?`); code defensively.
|
||||
- React: `useSyncExternalStore` maps directly onto `onChange` (see the SDK
|
||||
README "React recipe").
|
||||
|
||||
Reference in New Issue
Block a user