2021-11-20 19:38:06 -08:00
|
|
|
import platform
|
2021-11-28 17:27:05 -08:00
|
|
|
from typing import Optional, Sequence, Tuple
|
|
|
|
|
from agame.action import Action
|
|
|
|
|
from agame.dialog import DialogOption
|
2021-11-20 19:38:06 -08:00
|
|
|
from .display import Display
|
|
|
|
|
|
|
|
|
|
if platform.system() in ("Linux", "Darwin", "Unix"):
|
|
|
|
|
from .unix import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BasicDisplay(Display):
|
|
|
|
|
"""
|
|
|
|
|
A basic display that should be supported on all platforms. It just outputs
|
|
|
|
|
text with some color.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def line(self, line: str = ""):
|
|
|
|
|
print(line)
|
|
|
|
|
|
2021-11-28 17:27:05 -08:00
|
|
|
def input(self, prompt: Optional[str] = None) -> str:
|
|
|
|
|
if prompt is None:
|
|
|
|
|
prompt = "> "
|
|
|
|
|
return input(prompt)
|
|
|
|
|
|
|
|
|
|
def wait_for_ack(self, prompt: Optional[str] = "Press enter to continue..."):
|
|
|
|
|
input(prompt or "")
|
|
|
|
|
|
|
|
|
|
def dialog_options(self, options: Sequence[DialogOption]) -> DialogOption:
|
|
|
|
|
valid_opts = range(1, len(options) + 1)
|
|
|
|
|
|
|
|
|
|
def print_opts():
|
|
|
|
|
for i, opt in enumerate(options):
|
|
|
|
|
self.line(f"{i}. {opt.text}")
|
|
|
|
|
|
|
|
|
|
print_opts()
|
|
|
|
|
while True:
|
|
|
|
|
got = self.input("? ")
|
|
|
|
|
try:
|
|
|
|
|
choice = int(got)
|
|
|
|
|
except ValueError:
|
|
|
|
|
print_opts()
|
|
|
|
|
continue
|
|
|
|
|
if choice in valid_opts:
|
|
|
|
|
break
|
|
|
|
|
index = choice - 1
|
|
|
|
|
selection = options[index]
|
|
|
|
|
return selection
|