Return to repo list

heart-of-gold

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

commit ff1497f79f3a7b59d1b5549cf11117c51795201c
parent 5d338784416de295f706106f4776916e147bbfc8
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sat, 24 Oct 2020 16:45:24 -0500

Effectuality implemented for managers

Diffstat:
Msrc/manager.py | 14++++++++------
Msrc/menu.py | 20+++++---------------
Msrc/scene.py | 18++++--------------
3 files changed, 17 insertions(+), 35 deletions(-)

diff --git a/src/manager.py b/src/manager.py @@ -1,5 +1,6 @@ import pygame from . import subsystem +from .constants import * ############## # manager.py # @@ -69,7 +70,7 @@ class Manager(subsystem.GameSubsystem): # Property defaults self._activated = True - self._effectual = True + self._effectual = False # Other methods def trigger_effects(self, effect_list): @@ -80,11 +81,12 @@ class Manager(subsystem.GameSubsystem): effects. """ # effect_list is ALWAYS a LIST of DICTS - for ef in effect_list: - if ef["call"] == "ef_quit": - self.game.quit_game() - elif ef["call"] == "ef_switch_mode": - self.game.switch_mode(STATE_MODES[ef["data"]]) + if self.activated and self.effectual: + for ef in effect_list: + if ef["call"] == "ef_quit": + self.game.quit_game() + elif ef["call"] == "ef_switch_mode": + self.game.switch_mode(STATE_MODES[ef["data"]]) def update_managed(self, surface): """ diff --git a/src/menu.py b/src/menu.py @@ -28,7 +28,10 @@ class MenuManager(manager.Manager): super().__init__(game, bus) - # MenuManager values + # Fix properties + self.effectual = True + + # Important values self.current_menu = None self.loaded_menus = {} @@ -46,19 +49,6 @@ class MenuManager(manager.Manager): if menuname in self.loaded_menus.keys(): self.current_menu = self.loaded_menus[menuname] - def activate_menu_effects(self, effects): - """ - Activate one or more events in Menu mode. This is - a BIG method that accounts for almost everything - you can do in menus. - """ - # TODO: Regularize this with the similar event in SceneManager - for e in effects: - if e["call"] == "ef_quit": # Quit the game - self.game.quit_game() - elif e["call"] == "ef_switch_mode": # Switch to another game mode - self.game.switch_mode(STATE_MODES[e["data"]]) - def trigger_button_at_pos(self, pos): """ Trigger a button if pos is within that button's @@ -67,7 +57,7 @@ class MenuManager(manager.Manager): if self.current_menu != None: for b in self.current_menu.button_group: if b.rect.collidepoint(pos): - self.activate_menu_effects(b.effects) + self.trigger_effects(b.effects) def update_current_menu(self, surface = None): """ diff --git a/src/scene.py b/src/scene.py @@ -27,6 +27,9 @@ class SceneManager(manager.Manager): # Parent initialization super().__init__(game, bus) + # Fix properties + self.effectual = True + # Important values self.current_scene = None @@ -36,19 +39,6 @@ class SceneManager(manager.Manager): """ self.current_scene = StillScene(self, scenefile) - def handle_scene_effects(self, effects): - """ - Handle script effects. This method is a large - branching decision tree that has a condition entry - for each possible scene effect. - """ - # TODO: Regularize this with the similar event in MenuManager - for ef in effects: - if ef["call"] == "ef_quit": - self.game.quit_game() - elif ef["call"] == "ef_switch_mode": - self.game.switch_mode(STATE_MODES[ef["data"]]) - def update_scene(self, surface = None): """ Update and draw the current scene. Behaves differently @@ -175,7 +165,7 @@ class StillScene(object): self.rendered_name_topleft = (self.name_box_pos[0] + ((self.name_box.image.get_width() / 2) - (self.rendered_name.get_width() / 2)), self.name_box_pos[1] + ((self.name_box.image.get_height() / 2) - (self.rendered_name.get_height() / 2))) # Handle effects - self.manager.handle_scene_effects(self.script[self.script_index]["effects"]) + self.manager.trigger_effects(self.script[self.script_index]["effects"]) def write_text(self): """