Return to repo list

heart-of-gold

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

commit f259afbd29eec78b1d0db11502c3f48a9872b6f6
parent 4b225ef023480504ae18a712b5221cc68ca3216c
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Mon, 28 Dec 2020 17:14:02 -0600

Added battle dialog

Diffstat:
Adata/board/testmap1/events.json | 4++++
Mdata/json/scenes/testdia.json | 14+-------------
Msrc/game.py | 9+++++----
Msrc/interface.py | 7++-----
Msrc/manager.py | 2+-
Msrc/turn.py | 8++++++--
6 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/data/board/testmap1/events.json b/data/board/testmap1/events.json @@ -0,0 +1,4 @@ +{ + "start_dialog" : "testdia.json", + "end_dialog" : null +} diff --git a/data/json/scenes/testdia.json b/data/json/scenes/testdia.json @@ -14,19 +14,7 @@ "voice" : null, "portrait" : "jisella_actor_portrait", "line" : "Hello there. How are you doing today? I'm fine, thanks for asking.", - "characters" : [ - { - "name" : "jisella", - "flipped" : true, - "pos" : [70, 118], - "actor" : [ - { "sheet" : "base", "sprite" : [0, 0] }, - { "sheet" : "eyes", "sprite" : [1, 2] }, - { "sheet" : "mouth", "sprite" : [1, 0] }, - { "sheet" : "brows", "sprite" : [0, 0] } - ] - } - ], + "characters" : [ ], "effects" : [ ] }, { diff --git a/src/game.py b/src/game.py @@ -91,7 +91,7 @@ class Game(object): self.piece_manager.load_ui_elements() self.camera.load_camera_surface(self.board_manager.current_board.pixel_dimensions) # TODO: This maybe shouldn't happen here, probably not ideal in a more complex transition to battle - self.turn_manager.initialize_turns(self.piece_manager.pieces) + self.turn_manager.initialize_turns(self.piece_manager.pieces, data) elif new_mode == STATE_MODES.Still_Scene_Mode: self.control_mode = CTRL_MODES.Still_Scene_Normal self.scene_manager.load_still_scene_from_file(data) @@ -146,10 +146,11 @@ class Game(object): # moving entity caused by the drawing order. if self.control_mode == CTRL_MODES.Turn_Watch_Move: self.camera.snap_to_position(self.turn_manager.current_active_piece.rect.center) - elif self.control_mode == CTRL_MODES.Battle_Dialog: - self.scene_manager.update(self.camera.camera_surface) self.camera.update_camera(self.screen) - self.turn_manager.update(self.screen) # Draw to the screen since it manages UI elements + if self.control_mode == CTRL_MODES.Battle_Dialog: + self.scene_manager.update(self.screen) + else: + self.turn_manager.update(self.screen) # Draw to the screen since it manages UI elements elif self.state_mode == STATE_MODES.Still_Scene_Mode: self.scene_manager.update(self.camera.camera_surface) self.camera.update_camera(self.screen) diff --git a/src/interface.py b/src/interface.py @@ -149,10 +149,7 @@ class GameInterface(subsystem.GameSubsystem): # StillScene in-battle dialog options elif self.game.control_mode == CTRL_MODES.Battle_Dialog: - - # Normal still-scene control - if self.game.control_mode == CTRL_MODES.Still_Scene_Normal: - self.bus.perform_continue_current_scene_script() + self.bus.perform_continue_current_scene_script() # Still-scene mode behavior elif self.game.state_mode == STATE_MODES.Still_Scene_Mode: @@ -231,7 +228,7 @@ class GameInterface(subsystem.GameSubsystem): if not ap.path_moving: self.game.control_mode = CTRL_MODES.Turn_Normal - # Watchin the brief guard anim + # Watching the brief guard anim elif self.game.control_mode == CTRL_MODES.Turn_Watch_Guard: ap = self.bus.fetch("turn_manager", "active_piece") if ap.has_guarded: diff --git a/src/manager.py b/src/manager.py @@ -101,7 +101,7 @@ class Manager(subsystem.GameSubsystem): # be whatever game needs for that particular mode (even compound data types such as list/dict) elif ef["call"] == GAME_EFFECTS.ef_game_switch_mode.name: self.game.switch_mode(STATE_MODES[ef["data"][0]], ef["data"][1]) - elif ef["call"] == GAME_EFFECTS.ef_game_switch_control: + elif ef["call"] == GAME_EFFECTS.ef_game_switch_control.name: self.game.control_mode = CTRL_MODES[ef["data"]] def update(self, surface): diff --git a/src/turn.py b/src/turn.py @@ -1,4 +1,4 @@ -import pygame +import pygame, os, json from . import manager, entity, status from .constants import * @@ -33,6 +33,7 @@ class TurnManager(manager.Manager): self.turn_tick = 0 self.in_play_pieces = [] self.turn_depth = 10 + self.board_events = {} # Turn tray and other associated entities self.turn_tray = None @@ -43,12 +44,13 @@ class TurnManager(manager.Manager): # Stat screen values self.stat_screen = None - def initialize_turns(self, pieces): + def initialize_turns(self, pieces, boardname): """ Load up the turns for the first time. This also sets up persistent parts of the turn UI such as the trays and action buttons. """ + with open(os.path.join(BOARD_PATH, boardname, "events.json")) as b: self.board_events = json.load(b) sheets = self.bus.fetch("sheet_manager", "sheets") anims = self.bus.fetch("sheet_manager", "animations") self.in_play_pieces = pieces @@ -64,6 +66,8 @@ class TurnManager(manager.Manager): nab = ActionButton(sheets["action_buttons_1"], (0, b), None, False, self) nab.set_position(((SCREEN_WIDTH // 8), (SCREEN_HEIGHT // 10) + (((SCREEN_HEIGHT // 14) - 4)) * b)) self.action_buttons.append(nab) + if self.board_events["start_dialog"] != None: + self.play_battle_dialog(self.board_events["start_dialog"]) self.shift_turns() def shift_turns(self):