commit 122a12362778f74af7c7c60e92db73b615bbd9fc
parent 61dfc70d41c72141b7f57337659a775afd21d2f4
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Mon, 1 Feb 2021 16:32:44 -0600
work toward generic base ents
Diffstat:
5 files changed, 135 insertions(+), 6 deletions(-)
diff --git a/data/board/testbase1/testbase1.json b/data/board/testbase1/testbase1.json
@@ -0,0 +1,17 @@
+{
+ "gatekeeperent" : {
+ "name" : "Bidru",
+ "type" : "Normal",
+ "sheet" : "Jisella_1",
+ "sprite" : [0, 0],
+ "visible" : true,
+ "animation" : "stand_L",
+ "animated" : true,
+ "tile" : [5, 4],
+ "occupied" : [0, 0],
+ "ereact" : true,
+ "spec" : {
+ "-1" : "gatekeeper_generic.json"
+ }
+ }
+}
diff --git a/data/json/scenes/gatekeeper_generic.json b/data/json/scenes/gatekeeper_generic.json
@@ -0,0 +1,53 @@
+{
+ "name" : "GenericGatekeeperDialog",
+ "fonts" : {
+ "A" : ["ArchivoNarrow-Regular.otf", 28]
+ },
+ "bg_sheet" : null,
+ "bg_sprite" : null,
+ "script" : [
+ {
+ "speaker" : "Bidru the Guide",
+ "name_font" : "A",
+ "name_pos" : [20, 480],
+ "line_font" : "A",
+ "voice" : null,
+ "portrait" : null,
+ "line" : "Please select a destination...",
+ "characters" : [ ],
+ "effects" : [ ]
+ },
+ {
+ "speaker" : "",
+ "name_font" : "A",
+ "name_pos" : [20, 480],
+ "line_font" : "A",
+ "voice" : null,
+ "portrait" : null,
+ "line" : "",
+ "characters" : [ ],
+ "effects" : [
+ {
+ "call" : "ef_scene_fade",
+ "data" : [[0, 0, 0], "-SW", 0, 38, 0, 30]
+ }
+ ]
+ },
+ {
+ "speaker" : "",
+ "name_font" : "A",
+ "name_pos" : [20, 480],
+ "line_font" : "A",
+ "voice" : null,
+ "portrait" : null,
+ "line" : "",
+ "characters" : [ ],
+ "effects" : [
+ {
+ "call" : "ef_game_switch_mode",
+ "data" : ["Battle_Mode", "testmap1"]
+ }
+ ]
+ }
+ ]
+}
diff --git a/src/base.py b/src/base.py
@@ -1,4 +1,4 @@
-import pygame
+import pygame, os, json, copy
from . import manager, entity, piece
from .constants import *
@@ -35,11 +35,27 @@ class BaseManager(manager.Manager):
# Event stages
self.current_event_stage = 0
- def load_base_from_file(self, filename):
+ def load_base(self, basename):
"""
Load the base from a given definition JSON.
"""
- pass
+ with open(os.path.join("data", "board", basename, basename + ".json")) as f: definiton = json.load(f)
+ for e in definition:
+ work = copy.deepcopy(definition[e])
+ if work["type"] == "Normal":
+ n_sheet = self.bus.fetch("sheet_manager", "sheets")[work["sheet"]]
+ n_sprite = tuple(work["sprite"])
+ n_anim = n_sheet.animations[work["animation"]]
+ n_animated = work["animated"]
+ n_occ = work["occupied"]
+ n_spec = {}
+ for k in work["spec"]:
+ n_spec[int(k)] = work["spec"][l]
+ n_react = work["ereact"]
+ ne = BaseEntity(self, n_react, n_spec, n_occ, n_sheet, n_sprite, n_anim, n_animated)
+ ne.assign_tile(tuple(work["tile"]), self.bus.fetch("board_manager", "board_tile_layer")[tuple(work["tile"])])
+ ne.snap_to_tile()
+ self.base_entities.add(ne)
def play_base_dialog(self, scenefile = None, definition = None):
"""
@@ -73,6 +89,28 @@ class BaseManager(manager.Manager):
self.tile_cursor.assign_tile(tile_pos, self.bus.fetch("board_manager", "board_tile_layer")[tile_pos])
self.tile_cursor.snap_to_tile()
+ def handle_base_entity_click(self, pos):
+ """
+ Handle when a base entity is clicked. This is the
+ standard way to interact with base mode NPCs and other
+ entities. Takes a pos value.
+ """
+ ent = None
+ for e in self.base_entities.sprites():
+ if e.rect.collidepoint(pos):
+ ent = e
+ break
+
+ if ent != None and ent.event_react:
+ for e in ent.event_spec:
+ if e == self.current_event_stage:
+ self.game.control_mode = CTRL_MODE.Base_Dialog
+ self.bus.perform_scene_manager_load_scene_from_file(ent.event_spec[e])
+ return
+ if -1 in self.event_spec.keys():
+ self.game.control_mode = CTRL_MODE.Base_Dialog
+ self.bus.perform_scene_manager_load_scene_from_file(ent.event_spec[-1])
+
def update_managed(self, surface = None):
"""
Update the base entities.
@@ -86,8 +124,26 @@ class BaseManager(manager.Manager):
# Section 2 - Various Base Mode Entity Subclasses #
###################################################
+class BaseEntity(entity.Entity):
+ """
+ Class representing the basic form of entity that
+ appears in base mode. All entities in the base
+ (e.g. npcs, buildings) inherit from this class,
+ which implements some basic features like reacting
+ to a click.
+ """
+
+ def __init__(self, manager, ereact, spec, occupied, sheet, sprite = (0, 0), animation = None, animated = False):
+
+ # Parent initialization
+ super().__init__(sheet, sprite, animation, animated)
+
+ # Other vals
+ self.manager = manager
+ self.event_react = ereact
+ self.event_spec = spec
+ self.occupied = occupied
+
####################################################
# Section 3 - Various Base Mode UI Element Classes #
####################################################
-
-#class
diff --git a/src/bus.py b/src/bus.py
@@ -121,6 +121,8 @@ class ManagerBus(subsystem.GameSubsystem):
self.game.piece_manager.kill_piece(piece)
def perform_base_manager_position_tile_cursor(self, tile_pos):
self.game.base_manager.position_tile_cursor(tile_pos)
+ def perform_click_base_entity_at_pos(self, pos):
+ self.game.base_manager.handle_base_entity_click(pos)
def perform_scene_manager_load_scene_from_file(self, scenefile):
self.game.scene_manager.load_still_scene_from_file(scenefile)
def perform_scene_manager_load_scene_from_def(self, definition):
diff --git a/src/interface.py b/src/interface.py
@@ -108,7 +108,8 @@ class GameInterface(subsystem.GameSubsystem):
# Base mode behavior
if self.game.state_mode == STATE_MODES.Base_Mode:
- pass
+ # Check for clicking on base entities
+ self.bus.perform_click_base_entity_at_pos(mouseraw)
# Battle mode behavior
elif self.game.state_mode == STATE_MODES.Battle_Mode: