22import random
33import datetime
44import logging
5+ import asyncio
56
67# Set up logging
78logging .basicConfig (level = logging .DEBUG , format = '%(asctime)s - %(levelname)s - %(message)s' )
2223# Track clicked tiles and store chip references
2324clicked_tiles = set ()
2425tile_buttons = {} # {(row, col): chip}
26+ tile_icons = {} # {(row, col): icon reference}
2527
2628def split_phrase_into_lines (phrase : str ) -> list :
2729 """
@@ -44,27 +46,28 @@ def create_bingo_board():
4446 logging .info ("Creating Bingo board" )
4547
4648 with ui .element ("div" ).classes ("flex justify-center items-center w-full" ):
47- with ui .grid (columns = 5 ).classes ("gap-2 mt-4" ):
48- for row_idx , row in enumerate (board ):
49- for col_idx , phrase in enumerate (row ):
50- # Create a clickable card for this cell with reduced padding and centered content.
51- card = ui .card ().classes ("p-2 bg-yellow-500 hover:bg-yellow-400 rounded-lg w-full flex items-center justify-center" ).style ("cursor: pointer; aspect-ratio: 1;" )
52- with card :
53- with ui .column ().classes ("flex flex-col items-center justify-center gap-0 w-full" ):
54- # Set text color: free meat gets #FF7f33, others black
55- default_text_color = "#FF7f33" if phrase .upper () == "FREE MEAT" else "black"
56- # Split the phrase into balanced lines.
57- for line in split_phrase_into_lines (phrase ):
58- tile = ui .label (line ).classes ("fit-text text-center" )
59- tile .style (f"font-family: 'Super Carnival', sans-serif; padding: 0; margin: 0; color: { default_text_color } ;" )
60- # Save the card reference.
61- tile_buttons [(row_idx , col_idx )] = card
62- if phrase .upper () == "FREE MEAT" :
63- clicked_tiles .add ((row_idx , col_idx ))
64- # Set the free meat cell's style: text color, background, etc.
65- card .style ("color: #FF7f33; background: #facc15; border: none;" )
66- else :
67- card .on ("click" , lambda e , r = row_idx , c = col_idx : toggle_tile (r , c ))
49+ with ui .element ("div" ).classes ("w-full max-w-3xl aspect-square" ):
50+ with ui .grid (columns = 5 ).classes ("gap-2 h-full grid-rows-5" ):
51+ for row_idx , row in enumerate (board ):
52+ for col_idx , phrase in enumerate (row ):
53+ # Create a clickable card for this cell with reduced padding and centered content. Added 'relative' class for icon overlay.
54+ card = ui .card ().classes ("relative p-2 bg-yellow-500 hover:bg-yellow-400 rounded-lg w-full h-full flex items-center justify-center" ).style ("cursor: pointer;" )
55+ with card :
56+ with ui .column ().classes ("flex flex-col items-center justify-center gap-0 w-full" ):
57+ # Set text color: free meat gets #FF7f33, others black
58+ default_text_color = "#FF7f33" if phrase .upper () == "FREE MEAT" else "black"
59+ for line in split_phrase_into_lines (phrase ):
60+ ui .label (line ).classes ("fit-text text-center select-none" ).style (f"font-family: 'Super Carnival', sans-serif; padding: 0; margin: 0; color: { default_text_color } ;" )
61+ # After the column, add a hidden check icon overlay
62+ icon = ui .icon ("check" ).classes ("absolute inset-0 m-auto text-3xl text-white" ).style ("display: none;" )
63+ tile_buttons [(row_idx , col_idx )] = card
64+ tile_icons [(row_idx , col_idx )] = icon
65+ if phrase .upper () == "FREE MEAT" :
66+ clicked_tiles .add ((row_idx , col_idx ))
67+ card .style ("color: #FF7f33; background: #facc15; border: none;" )
68+ icon .style ("display: block;" )
69+ else :
70+ card .on ("click" , lambda e , r = row_idx , c = col_idx : toggle_tile (r , c ))
6871
6972# Toggle tile click state (for example usage)
7073def toggle_tile (row , col ):
@@ -76,11 +79,12 @@ def toggle_tile(row, col):
7679 logging .debug (f"Tile at { key } unclicked" )
7780 clicked_tiles .remove (key )
7881 tile_buttons [key ].style ("background: #facc15; border: none; color: black;" )
82+ tile_icons [key ].style ("display: none;" )
7983 else :
8084 logging .debug (f"Tile at { key } clicked" )
8185 clicked_tiles .add (key )
82- tile_buttons [key ].style ("color : #22c55e; border: 15px solid #15803d ;" )
83-
86+ tile_buttons [key ].style ("background : #22c55e; color: white; border: none ;" )
87+ tile_icons [ key ]. style ( "display: block;" )
8488 check_winner ()
8589
8690# Check for Bingo win condition
@@ -105,5 +109,14 @@ def check_winner():
105109with ui .element ("div" ).classes ("w-full mt-4" ):
106110 ui .label (f"Seed: { today_seed } " ).classes ("text-md text-gray-300 text-center" )
107111
108- ui .timer (0.5 , lambda : ui .run_javascript ("fitty('.fit-text', { multiLine: true, maxSize: 100 }); fitty('.fit-header', { multiLine: true, maxSize: 200 });" ), once = True )
112+ ui .add_head_html ("""<script>
113+ document.addEventListener('DOMContentLoaded', () => {
114+ fitty('.fit-text', { multiLine: true, maxSize: 100 });
115+ fitty('.fit-header', { multiLine: true, maxSize: 200 });
116+ });
117+ window.addEventListener('resize', () => {
118+ fitty('.fit-text', { multiLine: true, maxSize: 100 });
119+ fitty('.fit-header', { multiLine: true, maxSize: 200 });
120+ });
121+ </script>""" )
109122ui .run (port = 8080 , title = "Commit Bingo" , dark = True )
0 commit comments