mirror of
https://github.com/Textualize/textual-web.git
synced 2025-10-17 02:36:40 +03:00
Add merlin game
This commit is contained in:
@@ -40,6 +40,8 @@ TOGGLES: dict[int, tuple[int, ...]] = {
|
||||
|
||||
|
||||
class LabelSwitch(Widget):
|
||||
"""Switch with a numeric label."""
|
||||
|
||||
DEFAULT_CSS = """
|
||||
LabelSwitch Label {
|
||||
text-align: center;
|
||||
@@ -59,15 +61,15 @@ class LabelSwitch(Widget):
|
||||
|
||||
|
||||
class MerlinApp(App):
|
||||
CSS = """
|
||||
"""A simple reproduction of one game on the Merlin hand held console."""
|
||||
|
||||
CSS = """
|
||||
Screen {
|
||||
align: center middle;
|
||||
background: transparent;
|
||||
align: center middle;
|
||||
}
|
||||
|
||||
Screen.-win {
|
||||
background: $success;
|
||||
Screen.-win {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
Grid {
|
||||
@@ -81,7 +83,6 @@ class MerlinApp(App):
|
||||
grid-gutter: 1 1;
|
||||
background: $surface;
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
def render(self) -> LinearGradient:
|
||||
@@ -93,13 +94,15 @@ class MerlinApp(App):
|
||||
for switch in (7, 8, 9, 4, 5, 6, 1, 2, 3):
|
||||
yield LabelSwitch(switch)
|
||||
|
||||
def on_mount(self) -> ComposeResult:
|
||||
def on_mount(self) -> None:
|
||||
for switch_no in range(1, 10):
|
||||
if random.randint(0, 1):
|
||||
self.query_one(f"#switch-{switch_no}").toggle()
|
||||
self.query_one(f"#switch-{switch_no}", Switch).toggle()
|
||||
|
||||
def check_win(self) -> bool:
|
||||
on_switches = {switch.name for switch in self.query(Switch) if switch.value}
|
||||
on_switches = {
|
||||
int(switch.name or "0") for switch in self.query(Switch) if switch.value
|
||||
}
|
||||
return on_switches == {1, 2, 3, 4, 6, 7, 8, 9}
|
||||
|
||||
def on_switch_changed(self, event: Switch.Changed) -> None:
|
||||
|
||||
@@ -62,33 +62,41 @@ def print_disclaimer() -> None:
|
||||
|
||||
@click.command()
|
||||
@click.version_option(version("textual-web"))
|
||||
@click.option("-c", "--config", help="Location of config file", metavar="PATH")
|
||||
@click.option("-c", "--config", help="Location of TOML config file.", metavar="PATH")
|
||||
@click.option(
|
||||
"-e",
|
||||
"--environment",
|
||||
help="Environment (prod, dev, or local)",
|
||||
help="Environment switch.",
|
||||
type=click.Choice(list(ENVIRONMENTS)),
|
||||
default=constants.ENVIRONMENT,
|
||||
)
|
||||
@click.option("-a", "--api-key", help="API key", default=constants.API_KEY)
|
||||
@click.option("-r", "--run", help="Command to run a Textual app", multiple=True, metavar="COMMAND")
|
||||
@click.option(
|
||||
"--devtools", is_flag=True, help="Enable devtools in Textual apps", default=False
|
||||
"-r",
|
||||
"--run",
|
||||
help="Command to run a Textual app.",
|
||||
multiple=True,
|
||||
metavar="COMMAND",
|
||||
)
|
||||
@click.option(
|
||||
"-t", "--terminal", is_flag=True, help="Publish a remote terminal on a random URL"
|
||||
"--dev", is_flag=True, help="Enable devtools in Textual apps.", default=False
|
||||
)
|
||||
@click.option("-s", "--signup", is_flag=True, help="Create a textual-web account")
|
||||
@click.option("--welcome", is_flag=True, help="Launch an example app")
|
||||
@click.option(
|
||||
"-t", "--terminal", is_flag=True, help="Publish a remote terminal on a random URL."
|
||||
)
|
||||
@click.option("-s", "--signup", is_flag=True, help="Create a textual-web account.")
|
||||
@click.option("--welcome", is_flag=True, help="Launch an example app.")
|
||||
@click.option("--merlin", is_flag=True, help="Launch Merlin game.")
|
||||
def app(
|
||||
config: str | None,
|
||||
environment: str,
|
||||
run: list[str],
|
||||
devtools: bool,
|
||||
dev: bool,
|
||||
terminal: bool,
|
||||
api_key: str,
|
||||
signup: bool,
|
||||
welcome: bool,
|
||||
merlin: bool,
|
||||
) -> None:
|
||||
"""Main entry point for the CLI.
|
||||
|
||||
@@ -98,6 +106,9 @@ def app(
|
||||
devtools: Enable devtools.
|
||||
terminal: Enable a terminal.
|
||||
api_key: API key.
|
||||
signup: Signup dialog.
|
||||
welcome: Welcome app.
|
||||
merlin: Merlin app.
|
||||
"""
|
||||
|
||||
error_console = Console(stderr=True)
|
||||
@@ -118,6 +129,12 @@ def app(
|
||||
WelcomeApp().run()
|
||||
return
|
||||
|
||||
if merlin:
|
||||
from .apps.merlin import MerlinApp
|
||||
|
||||
MerlinApp().run()
|
||||
return
|
||||
|
||||
VERSION = version("textual-web")
|
||||
|
||||
print_disclaimer()
|
||||
@@ -150,7 +167,7 @@ def app(
|
||||
|
||||
print(_config)
|
||||
|
||||
if devtools:
|
||||
if dev:
|
||||
log.info("Devtools enabled in Textual apps (run textual console)")
|
||||
|
||||
ganglion_client = GanglionClient(
|
||||
@@ -158,11 +175,11 @@ def app(
|
||||
_config,
|
||||
_environment,
|
||||
api_key=api_key or None,
|
||||
devtools=devtools,
|
||||
devtools=dev,
|
||||
)
|
||||
|
||||
for app_command in run:
|
||||
ganglion_client.add_app("", app_command, "")
|
||||
ganglion_client.add_app(app_command, app_command, "")
|
||||
|
||||
if terminal:
|
||||
ganglion_client.add_terminal(
|
||||
@@ -173,6 +190,7 @@ def app(
|
||||
|
||||
if not ganglion_client.app_count:
|
||||
ganglion_client.add_app("Welcome", "textual-web --welcome", "welcome")
|
||||
ganglion_client.add_app("Merlin Tribute", "textual-web --merlin", "merlin")
|
||||
|
||||
if WINDOWS:
|
||||
asyncio.run(ganglion_client.run())
|
||||
|
||||
Reference in New Issue
Block a user