All command examples are from the repo root
- Install postgresql locally
- Create a database called "tattleviralspiral"
- You can do this by running
psql -U postgres
and thencreate databaset tattleviralspiral
- You can do this by running
- Install python3 and create a virtualenv using pipenv
pipenv shell
- Activate the environment
pipenv shell
source ./activate_env.sh
- Install dependencies
pipenv sync
- Initialize the db
python setup.py
- Run the startup script
bash start.sh
- Make sure you see no errors on the console
- Open your browser to
localhost:5000
- Fill up the create_game form. You should see "created game " in the console tab
- For each player, you'll need a separate tab with
localhost:5000
open. You can reuse this tab for the first player - For each player, join the game
- Rest of it should be intuitive.
All communication happens with sockets, using the socket.io framework. The flow is as follows:
We don't use any namespaces as of now. CORS might not be enabled on the server yet - so if you can use some broser plugin to disable cors (not tested yet) that will be great. I will look into enabling cors. The socket.io path is the default path (basically for initialization, I didn't provide any path. You can check out main_loop/templates/index.html for reference).
Actions (outgoing events):
- Create a game (needs to be done only once. All game names are unique):
- Event name: "create_game"
- Example -
main_loop/index.html:95
- Join a game (needs to be done every time you re-load the socket):
- Once you join a game, your client's session ID is stored in the backend
- So if this client ID changes (might happen on a page refresh), you need to join the game again
- Event name: "join_game"
- Example:
main_loop/index.html:143
- Player action - this event is triggered whenever the player performs a card
action
- Action can be to keep a card or pass a card (more details in the examples)
- TODO add more actions like initiate cancel player, vote cancel player,
make fake news, etc -- actions for each of the special powers
- Viral spiral action is a part of pass card
- All these actions will be a part of this same event as of now.
- Example:
main_loop/index.html:220
- To see the different types of actions, you can analyse the
data
variable in that command - and see how it changes when you fill out a form and select perform action
- To see the different types of actions, you can analyse the
- About game - returns information about this game
- To be used to get the game state
- Example:
main_loop/index.html:311
- Ping
- Sample request that sends "my_ping" and the server returns "my_pong". Can be used to check the connection to the server
- get queued card - get the card queued for the current player
- Not being used in the frontend as of now since the play_card action gives this information
- Python code:
main_loop/websocket.py:265
Events (incoming events):
- "connect" - Triggered on successful connection.
main_loop/index.html:258
- "play_card" - Reminder to play the card.
main_loop/index.html:266
- "about": Response to the "about game" action:
main_loop/index.html:288
- "whos_turn" - Triggered whenever a round starts - returns the data about
who's turn it is.
main_loop/index.html:295
- "endgame" - Triggered when the game ends.
main_loop/index.html:301
- "text_response" - This is a generic event triggered. All data coming here
goes into the
console
tab of the demo UI.main_loop/index.html:261
- TODO create better specific events instead of using text_response
- Following server events trigger this "text_response" event:
- heartbeat every 10 seconds
- Response to a
create_game
request - Response to a
load_game
request -- this action is not being used in the frontend. If you trigger ajoin_game
it will automatically load the game. - Response to a
player_action
request - Response to a disconnect request
- Response to a connect request
- When a round finishes
- Response to joining a game
docker-compose up
docker ps //to confirm if the services are running
docker exec -it api /bin/sh
pipenv shell
python setup.py // one time thing to run database database migrations
./start.sh
If you are on windows and are running into the source: not found
error while running the ./start.sh
command, then instead of it try running python main_loop/websocket.py
These instructions are useful when you are running the server inside a docker container and using VS code as your IDE. We'll use debugpy
as the debugger.
- Run
pip install debugpy
inside your container. - Run
pipenv shell
- Run
python -m debugpy --listen 0.0.0.0:5678 --wait-for-client main_loop/websocket.py
- Open VS code and go to the Run and Debug screen. Click on the play button and choose "debugpy" to connect to the server.
You should be able to set breakpoints now. Configuration for connecting to the remote host can be seen in .vscode/launch.json
python -m unittest -v
todo : add commands to run individual test cases
- Round : A card's lifecyle, starts from the card being drawn and continues till the card has been passed to every player or has been kept or discarded by a player.
- Full Round : A turn cycle, includes every player finishing their round once