Implement reroll
This commit is contained in:
parent
a90adbb165
commit
3cded45cfd
101
bingo.py
101
bingo.py
@ -2,10 +2,12 @@
|
||||
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Header, Footer, Input, Label, Static, Button
|
||||
from textual.widget import Widget
|
||||
from textual.message import Message
|
||||
from textual.color import Color
|
||||
from textual.containers import Horizontal
|
||||
from textual.validation import Number
|
||||
from textual.reactive import reactive
|
||||
|
||||
from asyncio import sleep
|
||||
|
||||
@ -16,6 +18,7 @@ class BingoField(Static):
|
||||
"""A Bingo field widget."""
|
||||
|
||||
cursor_x, cursor_y = 2, 2
|
||||
text = reactive("temp")
|
||||
|
||||
class Selected(Message):
|
||||
"""Send message to the board containing clicked field info"""
|
||||
@ -25,10 +28,10 @@ class BingoField(Static):
|
||||
super().__init__()
|
||||
|
||||
def __init__(self, num, text: str) -> None:
|
||||
self.text = text
|
||||
self.num = num
|
||||
self.selected = False
|
||||
super().__init__()
|
||||
self.text = text
|
||||
|
||||
def on_mount(self) -> None:
|
||||
self.styles.content_align = ("center", "middle")
|
||||
@ -72,59 +75,79 @@ class BingoDisplay(Static):
|
||||
"""Create child widgets for the app."""
|
||||
self.board = BingoBoard()
|
||||
yield self.board
|
||||
input_field = Input(
|
||||
self.input_field = Input(
|
||||
str(self.board.seed),
|
||||
type='integer',
|
||||
placeholder='UNIX timestamp',
|
||||
max_length=10,
|
||||
classes='seed_input',
|
||||
validators=[
|
||||
Number(minimum=1000000000, maximum = int(datetime.now().timestamp()))
|
||||
Number(minimum=1000000000, maximum = 2000000000)
|
||||
]
|
||||
)
|
||||
input_field.border_title = 'Seed'
|
||||
self.input_field.border_title = 'Seed'
|
||||
yield Horizontal(
|
||||
input_field,
|
||||
self.input_field,
|
||||
Button('re-roll', classes='roll_btn'),
|
||||
classes='bottom_line'
|
||||
)
|
||||
|
||||
class BingoBoard(Static):
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
""""""
|
||||
# reroll
|
||||
self.board.roll_board(int(datetime.now().timestamp()))
|
||||
self.input_field.value = str(self.board.seed)
|
||||
|
||||
fieldstate = [False for _ in range(25)]
|
||||
class BingoBoard(Widget):
|
||||
|
||||
fields = [
|
||||
'Datenelch',
|
||||
'6 Stunden Schlaf',
|
||||
'Tschunk getrunken',
|
||||
'Spaß gehabt',
|
||||
'Sticker getauscht',
|
||||
'DECT genutzt',
|
||||
'Hardware gehackt',
|
||||
'Kabel vergessen',
|
||||
'Halle gesucht',
|
||||
'$dinge gelötet',
|
||||
'an SoS teilgenommen',
|
||||
'Neue Leute kennengelernt',
|
||||
'Wasser getrunken',
|
||||
'Waffel gegessen',
|
||||
'Corona Test gemacht',
|
||||
'2 Mahlzeiten gegessen',
|
||||
'Fairydust bewundert',
|
||||
'Talk angeschaut',
|
||||
'CCC Merch getragen',
|
||||
'getrollt',
|
||||
'In der Lounge getanzt',
|
||||
'Etwas Neues ausprobiert',
|
||||
'Maske getragen',
|
||||
'geduscht',
|
||||
'Gulasch gegessen'
|
||||
]
|
||||
|
||||
# get rng seed from current time
|
||||
seed = int(datetime.now().timestamp())
|
||||
random.seed(seed)
|
||||
random.shuffle(fields)
|
||||
fields = reactive([], recompose = True)
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.fieldstate = [False for _ in range(25)]
|
||||
super().__init__()
|
||||
self.fields = [
|
||||
'Datenelch',
|
||||
'6 Stunden Schlaf',
|
||||
'Tschunk getrunken',
|
||||
'Spaß gehabt',
|
||||
'Sticker getauscht',
|
||||
'DECT genutzt',
|
||||
'Hardware gehackt',
|
||||
'Kabel vergessen',
|
||||
'Halle gesucht',
|
||||
'$dinge gelötet',
|
||||
'an SoS teilgenommen',
|
||||
'Neue Leute kennengelernt',
|
||||
'Wasser getrunken',
|
||||
'Waffel gegessen',
|
||||
'Corona Test gemacht',
|
||||
'2 Mahlzeiten gegessen',
|
||||
'Fairydust bewundert',
|
||||
'Talk angeschaut',
|
||||
'CCC Merch getragen',
|
||||
'getrollt',
|
||||
'In der Lounge getanzt',
|
||||
'Etwas Neues ausprobiert',
|
||||
'Maske getragen',
|
||||
'geduscht',
|
||||
'Gulasch gegessen'
|
||||
]
|
||||
|
||||
self.roll_board(int(datetime.now().timestamp()))
|
||||
|
||||
def roll_board(self, seed):
|
||||
print('rolling board.')
|
||||
self.seed = seed
|
||||
random.seed(seed)
|
||||
self.fields = random.sample(self.fields, len(self.fields))
|
||||
print('board after shuf:')
|
||||
print(self.fields)
|
||||
|
||||
def watch_fields(self, new_state) -> None:
|
||||
print('watch_fields: called')
|
||||
self.fieldstate = [False for _ in range(25)]
|
||||
for idx, field in enumerate(self.query(BingoField)):
|
||||
field.text = new_state[idx]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
"""Create child widgets for the app."""
|
||||
|
Loading…
Reference in New Issue
Block a user