jtruong04 / SchrodingerCheckers

PnP/Digital card game to simulate quantum computations
1 stars 0 forks source link

V2 Reduxify #44

Closed jtruong04 closed 4 years ago

jtruong04 commented 4 years ago

@MSchiavi I know you're basically done with this so feel free to not review the code. Although, you might find this part interesting.

Changed up the game state management system to Redux. This involves two major changes to the code.

  1. Redux itself. The game state before was saved in data objects. While it works it doesn't jive well with how React likes to do things. Secondly, the links data was stored as a Map of Sets. While this works beautifully, Maps and Sets are not serializable so converting them to JSON objects was clunky. Now, the data is just a plain old object of Arrays and Lodash is used to add and remove unique elements. All of this is saved as a single object stored inside the Redux store.

  2. The command manager is scrapped. It previously worked by changing the callback function attached to the tiles and links. Actions that required multiple inputs required a sequence of callbacks. While it worked, it was awkward and required a lot of code duplication. Now, we use an event driven system. Clicked tiles and links emit an event up the the Game component. The Game component then filters these events based on what action was selected by the Controller component, pushing passed inputs into an array. The controller then checks to see if the required number of inputs are there and if so, they fire an action to Redux. Think input sequences in fighting games.

Other changes:

  1. Added a really basic CardCarousel component to view player cards. Opacity is dropped when card is completed.
  2. Socket.io middleware is added. Actions will automatically be emitted. Full implementation (i.e. processing received actions) will come once the backend also implements socket.io.
Screen Shot 2020-07-10 at 12 59 28 AM
MSchiavi commented 4 years ago

Cool I will probably end up looking at this in more depth this weekend. Just gonna merge this in for your own sanity.