From 1999e8b8ecc69e5e61ff5718aaacf54ce2ea6cef Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 16 Feb 2021 20:23:26 -0500 Subject: [PATCH] Added in yaml This works, but has a few minor bugs. it lays the foundation though for more stuff to be added --- Adventure Game/adventure_game/gamedata/gamelib.yaml | 13 +++++++++++++ Adventure Game/adventure_game/main.py | 5 ++++- Adventure Game/adventure_game/yaml_parser.py | 12 ++++++++++++ Adventure Game/requirements.txt | 3 ++- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 Adventure Game/adventure_game/gamedata/gamelib.yaml create mode 100644 Adventure Game/adventure_game/yaml_parser.py diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml new file mode 100644 index 0000000..223c904 --- /dev/null +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -0,0 +1,13 @@ +menu: + graphics: + logo: | + __ __ __ ___ __ __ + / / / /___ ____ ____ _____ ___ ___ ____/ / / | ____/ / _____ ____ / /___ __________ + / / / / __ \/ __ \/ __ `/ __ `__ \/ _ \/ __ / / /| |/ __ / | / / _ \/ __ \/ __/ / / / ___/ _ \ + / /_/ / / / / / / / /_/ / / / / / / __/ /_/ / / ___ / /_/ /| |/ / __/ / / / /_/ /_/ / / / __/ + \____/_/ /_/_/ /_/\__,_/_/ /_/ /_/\___/\__,_/ /_/ |_\__,_/ |___/\___/_/ /_/\__/\__,_/_/ \___/ + _________ __ _________ + / ____/ | / |/ / ____/ + / / __/ /| | / /|_/ / __/ + / /_/ / ___ |/ / / / /___ + \____/_/ |_/_/ /_/_____/ \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 0005530..91a55c7 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,4 +1,5 @@ import npyscreen +from yaml_parser import parse_datafile as parse class GameNavigator(npyscreen.Form): @@ -20,7 +21,7 @@ class MainMenu(npyscreen.Form): def create(self): self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Filename:") - self.add(npyscreen.MultiLineEdit, value='Test', editable=False) + self.add(npyscreen.MultiLineEdit, value=self.parentApp.gamelib['menu']['graphics']['logo'], editable=False) class AlphaWarning(npyscreen.Popup): @@ -37,6 +38,8 @@ class AlphaWarning(npyscreen.Popup): class AdventureGame(npyscreen.NPSAppManaged): # Do on creation def onStart(self): + self.gamelib = parse('gamedata/gamelib.yaml') + # Intalize a game renderer for most game windows self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') diff --git a/Adventure Game/adventure_game/yaml_parser.py b/Adventure Game/adventure_game/yaml_parser.py new file mode 100644 index 0000000..0d41be6 --- /dev/null +++ b/Adventure Game/adventure_game/yaml_parser.py @@ -0,0 +1,12 @@ +import yaml + + +def parse_datafile(file): + # With the file open + with open(file, 'r') as stream: + # Try to read it and return it + try: + content = yaml.safe_load(stream) + return content + except yaml.YAMLError as exc: + return exc diff --git a/Adventure Game/requirements.txt b/Adventure Game/requirements.txt index 52c0eb3..ba33800 100644 --- a/Adventure Game/requirements.txt +++ b/Adventure Game/requirements.txt @@ -1 +1,2 @@ -npyscreen~=4.10.5 \ No newline at end of file +npyscreen~=4.10.5 +PyYAML~=5.1.2 \ No newline at end of file