From 773d48b7324dd6b794891402cbdb0a25f16282a2 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 00:08:32 -0500 Subject: [PATCH] Handler can now log critical room load errors, --- Adventure Game/adventure_game/Handler.py | 10 +++++++++- .../adventure_game/gamedata/world/blank_room.yaml | 4 ++++ .../playerdata/defaults/default_player.yaml | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 Adventure Game/adventure_game/gamedata/world/blank_room.yaml diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 10cad2b..00ac1a2 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -43,7 +43,15 @@ class Handler(npyscreen.ButtonPress): # Localize the player player = self.parent.parentApp.player roomlocation = player.playerData['player']['location'] + '.yaml' - room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation) + try: + room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation) + + # If the file could not be found + except FileNotFoundError: + # Log a critical error! + self.parent.parentApp.log.critical('Handler could not load the current room! Is the player file corrupt or was there a typo? Path was {0}'.format(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)) + # Put the player in a blank room i forgot to finish + room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml') self.parent.update_log('You are in {0}.'.format(room)) # Log the command that we parsed diff --git a/Adventure Game/adventure_game/gamedata/world/blank_room.yaml b/Adventure Game/adventure_game/gamedata/world/blank_room.yaml new file mode 100644 index 0000000..5302880 --- /dev/null +++ b/Adventure Game/adventure_game/gamedata/world/blank_room.yaml @@ -0,0 +1,4 @@ +blank_room: + grid: [-1, -1] + upon_enter: "You're in a blank room. It looks unfinished, like joe forgot to put something here" + look_around: "There is nothing to look at, you should tell joe you're here." \ No newline at end of file diff --git a/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml index 811f696..57088df 100644 --- a/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml +++ b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml @@ -1,4 +1,4 @@ player: name: 'Default' - location: 'office' + location: 'officee' inventory: ['test', 'test2'] \ No newline at end of file