colyseus / colyseus-haxe

⚔ Colyseus Multiplayer SDK for Haxe
https://docs.colyseus.io/getting-started/haxe-client/
MIT License
75 stars 16 forks source link

ArraySchema provides incomplete data on change #25

Closed serjek closed 4 years ago

serjek commented 4 years ago

It seem that ArraySchema provides only diffing value on change: update 1

{
    field : turns, 
    value : [34], 
    previousValue : ArraySchema(1) { 34 } 
}

update 2

{
    field : turns, 
    value : [33], 
    previousValue : ArraySchema(2) { 34, 33 } 
}
serjek commented 4 years ago

Unfortunately I didn't find the root of the problem yet and switched to MapSchema instead 😅

endel commented 4 years ago

Hi @serjek, I'm checking this, wouldn't these callbacks help you achieve your goal?

state.array.onAdd +=
state.array.onRemove +=
state.array.onChange +=

Indeed the current value (value) during the root onChange callback only has additions in all decoders. It would be more intuitive to have the entire array as current value.

The previousValue had a bug on colyseus-hx - it seemed to be a reference to the actual current value, instead of the previous one - which I've fixed here https://github.com/colyseus/colyseus-hx/pull/26

I'm going to update that PR soon fixing the value as well.

serjek commented 4 years ago

Thanks for clarifications! I guess it's ok to close the ticket once PR is merged.