Return to repo list

heart-of-gold

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

commit d4f9a85b1e193e38d2419a8892deffc6414a4c3f
parent 10b25a2a80e8357d207196724328b2ee2d02e117
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Fri, 16 Oct 2020 16:53:18 -0500

Advancement in scene loading

Diffstat:
Adata/json/scenes/testscene.json | 44++++++++++++++++++++++++++++++++++++++++++++
Msrc/scene.py | 15+++++++++------
2 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/data/json/scenes/testscene.json b/data/json/scenes/testscene.json @@ -0,0 +1,44 @@ +{ + "name" : "TestScene", + "fonts" : { + "A" : ["ArchivoNarrow-Regular.otf", 16] + }, + "characters" : { + "Jisella1" : { + "sheet" : "JisellaChar1.png", + "sprite" : [0, 0] + } + }, + "script" : [ + { + "speaker" : "Jisella", + "name_font" : "A", + "line_font" : "A", + "voice" : 0, + "line" : "Hi there. This is a test of the Scene system.", + "characters" : [ + { + "name" : "Jisella1", + "pos" : [100, 600] + } + ], + "effects" : [ + ] + }, + { + "speaker" : "", + "name_font" : "A", + "line_font" : "A", + "voice" : 0, + "line" : "", + "characters" : [ + ], + "effects" : [ + { + "name" : "clear_character", + "target" : "Jisella1" + } + ] + } + ] +} diff --git a/src/scene.py b/src/scene.py @@ -1,6 +1,6 @@ import py, os, json from . import manager, vgo -from .constants import SCENE_JSON_PATH +from .constants import SCENE_JSON_PATH, FONT_PATH ############ # scene.py # @@ -59,8 +59,9 @@ class StillScene(object): self.manager = manager # Important values + self.name = None self.script = [] - self.fonts = [] + self.fonts = {} self.characters = {} self.text_speed = 10 self.text_write_timer = 0 @@ -81,9 +82,11 @@ class StillScene(object): """ scenedef = json.load(open(os.path.join(SCENE_JSON_PATH, scenefile))) - self.script = scenedef["script"]: - self.fonts = scenedef["fonts"] + self.name = scenedef["name"] + self.script = scenedef["script"] + for f in scenedef["fonts"]: + self.fonts[f] = pygame.font.Font(os.path.join(FONT_JSON_PATH, scenedef["fonts"][f][0]), scenedef["fonts"][f][1]) for c in scendef["characters"]: - nc = vgo.VGO(self.game.sheet_manager.loaded_sheets[scenedef["characters"][c]["sheet"]], scenedef["characters"][c]["sprite"]) - nc.set_position(scenedef["characters"][c]["pos"]) + nc = vgo.VGO(self.game.sheet_manager.loaded_sheets[scenedef["characters"][c]["sheet"]], tuple(scenedef["characters"][c]["sprite"])) + nc.custom_flags = c # TODO: Hacky solution for now, fix later self.characters[scenedef["characters"][c]["name"]] = nc