Add display abstraction

In case we want to run this on something that isn't an ANSI terminal, we
have the option to implement it however we want.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2021-11-20 19:38:06 -08:00
parent 4cf3608f71
commit e868d0e14f
8 changed files with 202 additions and 35 deletions

View File

@@ -3,6 +3,8 @@ import importlib.util
from pathlib import Path
import sys
from agame.color import colorize
from agame.display import ANSIDisplay
from agame.game import Game
# Parse args
@@ -19,25 +21,36 @@ package = args.PACKAGE
# Load game module
game_module = importlib.import_module(package)
game = game_module.game # type: ignore
database = game_module.database # type: ignore
start_room = game_module.start_room # type: ignore
# Run
game.say("=" * 70)
game.say("Type ((help)) for help, or ((quit)) to exit.")
game.say("=" * 70)
game.say()
# Build the game state
game = Game(
display=ANSIDisplay(),
database=database,
room=database.rooms["prelude"],
)
game.do_teleport_actions()
while True:
try:
try:
# Run
game.say("=" * 70)
game.say("Type ((help)) for help, or ((quit)) to exit.")
game.say("=" * 70)
game.say()
game.do_teleport_actions()
while True:
game.say()
line = input(colorize("{{>}} "))
line = game.display.input()
if line.lower() == "quit":
break
game.say()
game.run_command(line)
except (KeyboardInterrupt, EOFError):
break
except (KeyboardInterrupt, EOFError):
# no-op, these are expected events
pass
finally:
game.display.finish()
game.say()
game.say("Bye.")