awacke1 commited on
Commit
4e8388d
·
1 Parent(s): 4ac745d

Upload gamestate.py

Browse files
Files changed (1) hide show
  1. gamestate.py +13 -0
gamestate.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import TypeVar
2
+ import dataclasses
3
+
4
+ import streamlit as st
5
+
6
+ StateT = TypeVar('StateT')
7
+
8
+ def persistent_game_state(initial_state: StateT) -> StateT:
9
+ session_id = st.report_thread.get_report_ctx().session_id
10
+ session = st.server.server.Server.get_current()._get_session_info(session_id).session
11
+ if not hasattr(session, '_gamestate'):
12
+ setattr(session, '_gamestate', initial_state)
13
+ return session._gamestate