Surn commited on
Commit
bba5ccc
·
1 Parent(s): 2b96dfe

Fix JavaScript input handling and update session state management in UI

Browse files
Files changed (4) hide show
  1. README.md +3 -0
  2. app.py +1 -1
  3. battlewords.egg-info/PKG-INFO +5 -5
  4. battlewords/ui.py +10 -3
README.md CHANGED
@@ -26,6 +26,9 @@ tags:
26
  Battlewords is a vocabulary learning game inspired by classic Battleship mechanics. The objective is to discover hidden words on a grid, earning points for strategic guessing before all letters are revealed.
27
 
28
  ## Recent Changes
 
 
 
29
 
30
  version 0.2.42 (basic)
31
  - Add Hall of Fantastics (weekly Fantastic runs saved and viewable at ?page=fantastic)
 
26
  Battlewords is a vocabulary learning game inspired by classic Battleship mechanics. The objective is to discover hidden words on a grid, earning points for strategic guessing before all letters are revealed.
27
 
28
  ## Recent Changes
29
+ version 0.2.43 (basic)
30
+ - Update streamlit to 1.56.0 for improved security
31
+ - Fix bug where Hall of Fantastics entries were not saving correctly due to missing `entry_type` in JSON schema
32
 
33
  version 0.2.42 (basic)
34
  - Add Hall of Fantastics (weekly Fantastic runs saved and viewable at ?page=fantastic)
app.py CHANGED
@@ -30,7 +30,7 @@ def main(opened=False):
30
  <!-- Google Tag Manager (noscript) -->
31
  <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-MKBM5JQ6"
32
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
33
- ''')
34
 
35
  st.markdown(
36
  """<style>
 
30
  <!-- Google Tag Manager (noscript) -->
31
  <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-MKBM5JQ6"
32
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
33
+ ''', unsafe_allow_javascript=True)
34
 
35
  st.markdown(
36
  """<style>
battlewords.egg-info/PKG-INFO CHANGED
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.43
2
  Name: battlewords
3
- Version: 0.2.43 BASIC
4
  Summary: Battlewords vocabulary game (basic branch)
5
  Requires-Python: <3.13,>=3.12
6
  Description-Content-Type: text/markdown
@@ -17,7 +17,7 @@ emoji: 🎲
17
  colorFrom: blue
18
  colorTo: indigo
19
  sdk: streamlit
20
- sdk_version: 1.52.1
21
  python_version: 3.12.8
22
  app_port: 8501
23
  app_file: app.py
@@ -32,9 +32,9 @@ tags:
32
 
33
  > **This project is used by [huggingface.co](https://huggingface.co/spaces/Surn/Battlewords) as a demonstration of interactive word games in Python.**
34
 
35
- **Current Version:** 0.2.42 BASIC
36
  **Branch:** `basic`
37
- **Last Updated:** 2026-04-01
38
 
39
  Battlewords is a vocabulary learning game inspired by classic Battleship mechanics. The objective is to discover hidden words on a grid, earning points for strategic guessing before all letters are revealed.
40
 
 
1
+ Metadata-Version: 2.4
2
  Name: battlewords
3
+ Version: 0.2.43
4
  Summary: Battlewords vocabulary game (basic branch)
5
  Requires-Python: <3.13,>=3.12
6
  Description-Content-Type: text/markdown
 
17
  colorFrom: blue
18
  colorTo: indigo
19
  sdk: streamlit
20
+ sdk_version: 1.56.0
21
  python_version: 3.12.8
22
  app_port: 8501
23
  app_file: app.py
 
32
 
33
  > **This project is used by [huggingface.co](https://huggingface.co/spaces/Surn/Battlewords) as a demonstration of interactive word games in Python.**
34
 
35
+ **Current Version:** 0.2.43 BASIC
36
  **Branch:** `basic`
37
+ **Last Updated:** 2026-04-16
38
 
39
  Battlewords is a vocabulary learning game inspired by classic Battleship mechanics. The objective is to discover hidden words on a grid, earning points for strategic guessing before all letters are revealed.
40
 
battlewords/ui.py CHANGED
@@ -543,7 +543,7 @@ def _render_grid(show_grid_ticks: bool = True):
543
  var KEY = '__bw_guess_focus_manager__';
544
 
545
  function getGuessInput() {
546
- return parentDoc.querySelector('.st-key-guess_input input');
547
  }
548
 
549
  function isTextEntryEl(el) {
@@ -551,6 +551,10 @@ def _render_grid(show_grid_ticks: bool = True):
551
  var tag = (el.tagName || '').toUpperCase();
552
  return tag === 'INPUT' || tag === 'TEXTAREA' || (el.isContentEditable);
553
  }
 
 
 
 
554
 
555
  function tryFocus() {
556
  var input = getGuessInput();
@@ -839,6 +843,9 @@ def _render_guess_form(state: GameState):
839
  """, unsafe_allow_html=True,
840
  )
841
 
 
 
 
842
  with st.form("guess_form", width="stretch", clear_on_submit=True):
843
  col1, col2, col3 = st.columns([0.40, 0.25, 0.35], vertical_alignment="bottom")
844
  with col1:
@@ -849,11 +856,11 @@ def _render_guess_form(state: GameState):
849
  width=230,
850
  key="guess_input",
851
  help=tooltip_text, # Use Streamlit's built-in help parameter for tooltip
852
- disabled=not state.can_guess,
853
  placeholder="Enter guess",
854
  )
855
  with col2:
856
- submitted = st.form_submit_button("OK", disabled=not state.can_guess, width=100, key="guess_submit")
857
  with col3:
858
  _render_correct_try_again(state)
859
 
 
543
  var KEY = '__bw_guess_focus_manager__';
544
 
545
  function getGuessInput() {
546
+ return parentDoc.querySelector('.st-key-guess_input input');
547
  }
548
 
549
  function isTextEntryEl(el) {
 
551
  var tag = (el.tagName || '').toUpperCase();
552
  return tag === 'INPUT' || tag === 'TEXTAREA' || (el.isContentEditable);
553
  }
554
+
555
+ function isTooltipEl(el) {
556
+ return !!(el && el.closest && el.closest('.st-key-guess_input .stTooltipIcon, .st-key-guess_input .stTooltipHoverTarget'));
557
+ }
558
 
559
  function tryFocus() {
560
  var input = getGuessInput();
 
843
  """, unsafe_allow_html=True,
844
  )
845
 
846
+ # Resolve the effective can_guess from session state (not the stale snapshot)
847
+ effective_can_guess = st.session_state.get("can_guess", False)
848
+
849
  with st.form("guess_form", width="stretch", clear_on_submit=True):
850
  col1, col2, col3 = st.columns([0.40, 0.25, 0.35], vertical_alignment="bottom")
851
  with col1:
 
856
  width=230,
857
  key="guess_input",
858
  help=tooltip_text, # Use Streamlit's built-in help parameter for tooltip
859
+ disabled=not effective_can_guess,
860
  placeholder="Enter guess",
861
  )
862
  with col2:
863
+ submitted = st.form_submit_button("OK", disabled=not effective_can_guess, width=100, key="guess_submit")
864
  with col3:
865
  _render_correct_try_again(state)
866