Hi all/Endel,
I'm experimenting with Colyseus to recreate a boardgame to play with my mother who's in isolation now (to learn and do something useful at the same time).
For convenience, I'm tracking stacks of Card
objects (subclasses of Schema
) in 3 seperate ArraySchema<Card>
s representing card stacks within my state (which I use to track the order of the cards, and to be able to shuffle them), and I have the same Card objects (all of them) in a MapSchema<Card>
. Note: This is all for convenience to represent the real world version of the boardgame and not optimized for performance or minimal overhead etc.
When I move the top Card from one ArraySchema to another using
ArraySchema_1.push(ArraySchema_2.pop())
, the client gets an OnRemove
for ArraySchema_2 with a proper reference to the Card
I removed. However the OnAdd
for ArraySchema_1, while also triggered in the same update, seems to have an 'empty' Card
reference, i.e. as if I executed ArraySchema_1.push(new Card())
.
When I manipulate the Card
my MapSchema<Card>
does not trigger an OnChange
in the client.
In pseudo-code (not a working example):
/**
* Handles an incoming cardClick event, where I pass the name of the card clicked from the received Message.
*/
public handleCardClick(name: string) : void {
const card: Card = allCards_MapSchema[name]; //Gets the card that the user clicked on - this should be the top card from a stack, and it is when I check on the server.
const topCard = Stack_1_ArraySchema.pop(); // onRemove triggered as expected Client side
// The next test returns true in my case, I've tested this on the server: the MapSchema and Arrayschema thus contain a reference to the same object
// or at least equal-enough to be considered '==='.
if (card === topCard)
{
card.name = 'new Name'; // Should trigger onChange on the MapSchema, but does not
Stack_2_ArraySchema.push(topCard); // should trigger onAdd with the Card on the ArraySchema, but effect is more as if Stack_2_ArraySchema.push(new Card()); was executed, but actually (topCard !== new Card()).
}
}
In short: On the server I do see that the Card
is moved as expected from one Array to the other, but it's not being sent to the clients.
Does this sound as known/expected behavior? I can try to make an example after work today.
Cheers!