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