jtwedt / Climate-Conversations

an app to facilitate conversations about climate events
4 stars 2 forks source link

Store game state in session cookies #19

Closed dlundquist closed 7 years ago

dlundquist commented 7 years ago

This is a massive rewrite, I would have preferred to do this in a more incremental process.

Introduce EventStore class to handle loading events and questions from Excel and Google drive sources. Presently the inner Event class simply inherits from dict, but eventually a more structured Event class containing multiple questions would be desired. The two EventStore factory methods to load from Google drive and Excel files use a common _import_pandas_dataframe() helper, if we could move away from using Pandas it would reduce the server side dependencies. The EventStore is now a singleton stored in a single server side variable, this allows sharing between conversations.

Remove asked events logic from Player class and migrate it two a new style (inheriting from object) class. Also removed inadvertent class variables from Player class.

Rewrote Conversation class as new style class. Conversation class still holds core game state, but now assigns all questions to players in new_conversation() factory method. Class includes to_session_cookies(), session_cookie_keys() and load_from_session() methods to facilitate serializing in session cookies.

I didn't complete reimplementing all the game play logic. Specifically the events are selected randomly with no consideration of the player's age or if the event is duplicated. This should be trivial to reimplement, and I've tried to leave TODO comments and pass necessary information into methods.

Significantly refactored webapp route handlers. Setup handler now supports an arbitrary number of players! Much of the game logic has now been moved into the Conversation class. The game setup form now POSTs to /setup.