Return to repo list

heart-of-gold

Tactical RPG written in python, using pygame.
Return to HMagellan.com

commit 3ce61d56227ef240f824cd6142c872e75ceffc49
parent 09e95f907aa11b5b578cdf145d0a67857508c475
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Mon, 23 Nov 2020 22:24:55 -0600

Exceptions now properly occur in the manager bus

Diffstat:
Msrc/bus.py | 19++++++++-----------
Msrc/constants.py | 8++++++++
Msrc/piece.py | 13++++++++++---
Msrc/status.py | 2+-
4 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/src/bus.py b/src/bus.py @@ -9,11 +9,9 @@ from .constants import * # This file contains: # 1. The ManagerBus subsystem, which handles inter-manager/inter-managed communication -# TODO: Need to raise actual errors where the bus errors happen - -##################################### -# Section 1 - The ManagerBus object # -##################################### +#################################### +# Section 1 - The ManagerBus class # +#################################### class ManagerBus(subsystem.GameSubsystem): """ @@ -47,7 +45,7 @@ class ManagerBus(subsystem.GameSubsystem): if manager_name not in self.records.keys(): self.records[manager_name] = {} # Initial value is empty dict, replaced on first expose() else: - print("BUS ERROR: " + manager_name + " already in records!") + raise ManagerBusError("BUS SAYS: " + manager_name + " already in records!") def record(self, manager, data): """ @@ -58,10 +56,9 @@ class ManagerBus(subsystem.GameSubsystem): if type(data) == dict: self.records[manager] = data else: - print("BUS ERROR: Provided data from " + manager + " not dict type!") - print(">> data was: " + data) + raise ManagerBusError("BUS SAYS: Provided data: " + data + " from " + manager + " not dict type!") else: - print("BUS ERROR: " + manager + " not in records! Unable to record data!") + raise ManagerBusError("BUS SAYS: " + manager + " not in records! Unable to record data!") def fetch(self, manager, value): """ @@ -74,9 +71,9 @@ class ManagerBus(subsystem.GameSubsystem): if value in self.records[manager].keys(): return self.records[manager][value] else: - print("BUS ERROR: " + value + " not in " + manager + " data record!") + raise ManagerBusError("BUS SAYS: " + value + " not in " + manager + " data record!") else: - print("BUS ERROR: " + manager + " not in records! Unable to fetch data!") + raise ManagerBusError("BUS SAYS: " + manager + " not in records! Unable to fetch data!") # Checks: Computes & returns handled partially by Bus itself. # Checks are basically the halfway between fetches and performs, diff --git a/src/constants.py b/src/constants.py @@ -83,3 +83,11 @@ STATE_MODES = enum.Enum('STATE_MODES', 'Main_Menu_Mode Battle_Mode Still_Scene_M CTRL_MODES = enum.Enum('CTRL_MODES', 'No_Control Main_Menu_Normal Turn_Normal Turn_Select_Move Turn_Select_Attack Turn_Watch_Move Turn_Watch_Attack Turn_Display_Stats Still_Scene_Normal') FACE_DIR = enum.Enum('FACE_DIR', 'U D L R') GAME_EFFECTS = enum.Enum('GAME_EFFECTS', 'ef_game_quit ef_game_switch_mode') + +# Error types +class ManagerBusError(Exception): + """ + Raised when an error occurs as part of ManagerBus + operation. + """ + diff --git a/src/piece.py b/src/piece.py @@ -135,8 +135,12 @@ class PieceManager(manager.Manager): Load a TileCursor object to highlight selected tiles, and a plumb bob to hover over the acting piece. """ - sh = self.bus.fetch("sheet_manager", "sheets") - an = self.bus.fetch("sheet_manager", "animations") + try: + sh = self.bus.fetch("sheet_manager", "sheets") + an = self.bus.fetch("sheet_manager", "animations") + except ManagerBusError: + return + self.tile_cursor = TileCursor(sh["cursor1"], (0, 0), an["cursor1"]["pulse"], True) self.plumb_bob = entity.Entity(sh["plumb_bob_1"], (0, 0), an["plumb_bob_1"]["spin"], True) @@ -223,7 +227,10 @@ class PieceManager(manager.Manager): active piece. """ if self.plumb_bob != None: - ap = self.bus.fetch("turn_manager", "active_piece") + try: + ap = self.bus.fetch("turn_manager", "active_piece") + except ManagerBusError: + ap = None if ap != None: self.plumb_bob.set_center_position((ap.rect.center[0], ap.rect.center[1] - (3 * (TILE_HEIGHT // 4)))) diff --git a/src/status.py b/src/status.py @@ -39,7 +39,7 @@ class StatusDisplay(entity.Entity): self.level_surface = None self.level_surface_rect = None self.exp_surface = None - self.exp_surface_rec = None + self.exp_surface_rect = None self.stat_surfaces = { i: None for i in self.stat_def["normal_stats"].keys() } self.stat_surface_rects = { i: None for i in self.stat_def["normal_stats"].keys() } self.equipment_surfaces = { i: None for i in self.stat_def["equipment"].keys() }