Return to repo list

heart-of-gold

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

commit 69c68b14de1a78b2c1056d2c9c173f9a1d56aed8
parent 9f62977576f42a6b356b79b0236bf24562bb1151
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Wed, 21 Oct 2020 20:10:12 -0500

SceneManager now processing effects

Diffstat:
Mdata/json/menus/mainmenu.json | 27++++++++++++++++-----------
Mdata/json/scenes/testscene.json | 4++++
Msrc/menu.py | 13+++++++------
Msrc/scene.py | 18+++++++++++++++++-
4 files changed, 44 insertions(+), 18 deletions(-)

diff --git a/data/json/menus/mainmenu.json b/data/json/menus/mainmenu.json @@ -8,31 +8,36 @@ "sprite" : [0, 0], "pos" : [100, 100], "intlayer" : 0, - "effects" : { - "me_switch_mode" : { - "mode" : "Battle_Mode" + "effects" : [ + { + "call" : "me_switch_mode", + "data" : "Battle_Mode" } - } + ] }, "LoadGame" : { "sheet" : "mainmenu_buttons_1", "sprite" : [0, 1], "pos" : [100, 200], "intlayer" : 0, - "effects" : { - "me_switch_mode" : { - "mode" : "Still_Scene_Mode" + "effects" : [ + { + "call" : "me_switch_mode", + "data" : "Still_Scene_Mode" } - } + ] }, "Options" : { "sheet" : "mainmenu_buttons_1", "sprite" : [0, 2], "pos" : [100, 300], "intlayer" : 0, - "effects" : { - "me_quit" : {} - } + "effects" : [ + { + "call" : "me_quit", + "data" : null + } + ] } }, "entities" : { }, diff --git a/data/json/scenes/testscene.json b/data/json/scenes/testscene.json @@ -40,6 +40,10 @@ } ], "effects" : [ + { + "call" : "se_switch_mode", + "data" : "Battle_Mode" + } ] } ] diff --git a/src/menu.py b/src/menu.py @@ -46,17 +46,18 @@ class MenuManager(manager.Manager): if menuname in self.loaded_menus.keys(): self.current_menu = self.loaded_menus[menuname] - def activate_menu_events(self, events): + 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. """ - for e in events: - if e == "me_quit": # Quit the game + # TODO: Regularize this with the similar event in SceneManager + for e in effects: + if e["call"] == "me_quit": # Quit the game self.game.quit_game() - elif e == "me_switch_mode": # Switch to another game mode - self.game.switch_mode(STATE_MODES[events[e]["mode"]]) + elif e["call"] == "me_switch_mode": # Switch to another game mode + self.game.switch_mode(STATE_MODES[e["data"]]) def trigger_button_at_pos(self, pos): """ @@ -66,7 +67,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_events(b.effects) + self.activate_menu_effects(b.effects) def update_current_menu(self, surface = None): """ diff --git a/src/scene.py b/src/scene.py @@ -1,6 +1,6 @@ import pygame, os, json from . import manager, vgo -from .constants import SCREEN_WIDTH, SCENE_JSON_PATH, FONT_PATH +from .constants import * ############ # scene.py # @@ -36,6 +36,19 @@ 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"] == "se_quit": + self.game.quit_game() + elif ef["call"] == "se_switch_mode": + self.game.switch_mode(STATE_MODES[ef["data"]]) + def update_scene(self, surface = None): """ Update and draw the current scene. Behaves differently @@ -161,6 +174,9 @@ class StillScene(object): self.rendered_name = self.current_name_font.render(self.script[self.script_index]["speaker"], False, (255, 255, 255)).convert() 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"]) + def write_text(self): """ Write out the text of a script and render it to