feat!: balances and items replace the wallet in the player profile
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# @rudder/sdk
|
||||
|
||||
Rudder client SDK for web games: device and social auth, player state
|
||||
(profile, wallets, counters), catalog currencies, player storage, and calls to
|
||||
(profile, balances, items), catalog currencies, player storage, and calls to
|
||||
installed modules through generated typed clients.
|
||||
|
||||
## Install
|
||||
@@ -34,8 +34,8 @@ const client = createClient({
|
||||
await client.auth.loginWithDevice();
|
||||
|
||||
const profile = client.player.value;
|
||||
const gold = profile?.wallets?.find((w) => w.currency === 'gold')?.balance;
|
||||
const wins = profile?.counters?.wins ?? 0;
|
||||
const gold = profile?.balances?.find((b) => b.currency === 'gold')?.balance;
|
||||
const swords = profile?.items?.find((i) => i.item === 'sword')?.quantity ?? 0;
|
||||
|
||||
await client.storage.save('progress', JSON.stringify({ level: 7 }));
|
||||
|
||||
@@ -90,13 +90,13 @@ can also call directly:
|
||||
| Area | Access |
|
||||
|---|---|
|
||||
| Auth | `client.auth.loginWithDevice()`, `loginWithGoogle({ idToken })`, `loginWithApple({ idToken })`, `loginWithCustom({ customData })`, `linkWithGoogle(idToken)`, `linkWithApple(idToken)`, `linkWithCustom({ customData })`, `unlinkIdentity(provider)`, `logout()`, `isAuthenticated`, `onAuthStateChange(cb)` |
|
||||
| Player | `client.player` state: `player`, `identities`, `wallets`, `counters` |
|
||||
| Player | `client.player` state: `player`, `identities`, `balances`, `items` |
|
||||
| Catalog currencies | `client.catalog` state (`Map<slug, CatalogCurrency>`) |
|
||||
| Storage | `client.storage` state + `.save(type, data)` / `.delete(type)` |
|
||||
| Modules | `client.modules.call<T>(module, fn, args?, { moduleVersion? })`, usually through a generated client |
|
||||
|
||||
`counters` holds the values of the project's client-visible number counters
|
||||
by slug; currency balances are in `wallets`.
|
||||
`balances` carries one entry per released currency and `items` one per
|
||||
inventory stack.
|
||||
|
||||
## Error handling
|
||||
|
||||
@@ -172,7 +172,7 @@ function useSynced<T>(state: { onChange(cb: () => void): () => void; value: T |
|
||||
|
||||
function Wallet() {
|
||||
const profile = useSynced(client.player);
|
||||
return <div>{profile?.wallets?.map((w) => `${w.currency}: ${w.balance}`).join(', ')}</div>;
|
||||
return <div>{profile?.balances?.map((b) => `${b.currency}: ${b.balance}`).join(', ')}</div>;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user