virtualcommons / port-of-mars

Port of Mars is an online, game-based, social science experiment set on the first human community on the Red Planet. We are now in an open beta where anyone aged 18 and over can participate.
https://portofmars.asu.edu
GNU Affero General Public License v3.0
10 stars 16 forks source link

refactor client-server sync data structures #708

Open alee opened 3 years ago

alee commented 3 years ago

Colyseus 0.14+ changed the way that data is automatically synced between the server and client. Our code would be much simpler if we flattened our data structures from nested class hierarchies to so we would have something like this instead:

Collection<Player>
Map<Player, Inventory>
Map<Player, ResourceCosts>
...

or something along these lines so colyseus can do more of the heavy lifting synchronizing the smaller scalar values

https://docs.colyseus.io/colyseus/migrating/0.14/#onchange-on-schema-references

cpritcha commented 3 years ago

maybe organize the functionality around ECS (using existing role / session ids)

https://en.wikipedia.org/wiki/Entity_component_system

alee commented 3 years ago

Using colyseus's schema codegen we should have a cleaner codebase and avoid manually picking apart the schema changes to rich objects so we can issue the appropriate vuex store mutations (e.g., no more onAdd/onRemove/onChange for every ArraySchema property in an object).

Creating proper classes with annotations and running the codegen should get us started but we will punt on this and refactor after the September tournament.

https://github.com/colyseus/schema