lizadaly/windrift

Re-think use of `presence` and context

lizadaly opened this issue · 2 comments

useContext will fire on any context change at all, so probably should use this only for unchanging values in multiplayer games, like the specific Player objects.

Conversely that information is currently in the Redux store, which it doesn't have to be.

  • Switch 'multiplayer init' to use context
  • Move Presence to Redux

Actually multiplayer init needs to be in the redux store so that the browser can auto rehydrate the instance and player ids, but everything else should spin up via the API.

This was swapped around and now is working much better:

MultiplayerContext contains the following:

export interface Multiplayer {
    identifier: string
    storyUrl: string
    instanceId: string
    ready: boolean // True when all the params have been initialized
    currentPlayer: Player
    otherPlayer: Player
}

but the redux store is now much smaller (just instance and current player id).