-
I've implemented a player inventory system using @view() to reduce network traffic, but I'm encountering issues with client-side visibility of nested schema objects. //Player class with @view()-tagged inventory
class Player extends Schema {
// Other player properties...
@view() @type(Inventory)
inventory = new Inventory();
}
// Inventory contains a MapSchema of items
export class Inventory extends Schema {
@type({ map: InventoryItem })
slots = new MapSchema<InventoryItem>();
// Other inventory methods...
}
// Room setup
onJoin(client: any, options: any, auth: any): void {
const player = new Player(client.sessionId, ...);
this.state.players.set(client.sessionId, player);
client.view = new StateView();
client.view.add(player);
client.view.add(player.inventory);
client.view.add(player.inventory.slots);
// Items in inventory.slots aren't visible to the client
} The issue:
Any guidance would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Hi @AndadH, that's correct... When calling New items need to be added manually. So you would add the item to the state, and then to the const helmet = new Helmet();
player.inventory.slots.set("helmet", helmet);
view.add(helmet); // add this item to the user's state view Regarding removals - it should be enough to remove them from the state only - removing from the player.inventory.slots.delete("helmet"); The
I'm open to suggestions here. I think the current way using
The more data you put into I hope this helps! Let me know if this works for you 🙏 |
Beta Was this translation helpful? Give feedback.
I mean i cant say for sure. You would need to do some testing yourself, but i can say that i have ~3k objects synced through stateview and i dont see any noticable performance issues.