Return to repo list

heart-of-gold

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

commit 0a2aa78205ca007c335947aa593a11ecd548bb53
parent 72a64ac5abe037c008f8971eda23aadfde2c6cde
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Mon, 22 Mar 2021 16:31:14 -0500

first part of save system

Diffstat:
Mdata/etc/introvidscript.txt | 2+-
Mmain.py | 3++-
Msrc/constants.py | 15+++++++++++++--
Msrc/subsystem.py | 14+++++++++++++-
4 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/data/etc/introvidscript.txt b/data/etc/introvidscript.txt @@ -4,7 +4,7 @@ In the former Kingdom of Klassinoa, petty warlords raise armies to vie for scrap at the hands of these opportunists, who behave like little more than brigands. The warlords push anyone of fighting age into service in their armies. Able-bodied Klassinoans die by the thousands in the wars, and the villages are populated mostly with - fatherless children, the infirm, and the elderly. Crops fail in the absence of workers. Famine and disease are rampant. + fatherless children, the infirm, and the elderly. Crops fail for want of workers. Famine and disease are rampant. In the nation's south, a general known as Uolgro Yorlith has amassed a fearsome army. Striking from his base at Sassonod, he has taken control of much of the Heartmarsh and the eastern grasslands, and has positioned himself as the strongest contender to rule the whole of Klassinoa. diff --git a/main.py b/main.py @@ -15,7 +15,8 @@ from src import game # 8. BoardManager has specialized methods for creating and finding different kinds of overlay entities, but these entities are differentiated only # by the custom_flags vals. There should be a universal method for creating overlay entities, which you pass values to to determine their # custom_flags and images, as well as a universal method for fetching entities from the overlay list. Functionally, moving and attacking are -# the same as far as the BoardManager and its overlay, so generalizing this method will probably be very useful when implementing tactics. +# the same as far as the BoardManager and its overlay are concerned, so generalizing this method will probably be very useful when implementing +# tactics. # 9. Need to redo the directory and file structure for boards. Boards should have all of their files (json and all) in an entry under the 'boards' # dir, and the files should be named "map.tmx", "dialogs.json" and "entities.json" (any other files that should be common across all boards can # be added later). The game can use the board directory name to find these files, since it now needs to be shared across multiple managers (the diff --git a/src/constants.py b/src/constants.py @@ -1,4 +1,4 @@ -import os, enum, json +import os, enum, json, pathlib ################ # constants.py # @@ -40,6 +40,7 @@ JSON_PATH = os.path.join(DATA_PATH, "json") MENU_JSON_PATH = os.path.join(JSON_PATH, "menus") SCENE_JSON_PATH = os.path.join(JSON_PATH, "scenes") ACTORS_PATH = os.path.join(IMAGE_PATH, "actors") +SAVE_PATH = os.path.join(str(pathlib.Path.home), ".local", "HoG", "Savegames") # Piece constants with open(os.path.join(JSON_PATH, "pieces.json")) as f: CHARBASE = json.load(f) @@ -97,10 +98,20 @@ SCENE_EFFECTS = enum.Enum('SCENE_EFFECTS', 'ef_scene_dummy ef_scene_delay ef_sce TEAMS = enum.Enum('TEAMS', 'Player Ally Neutral Enemy Other') ATTACK_NOTATIONS = enum.Enum('ATTACK_NOTATIONS', 'backattack critical counter opposite weakness resist riposte ignoredef parry block sweep miss onetwo stun') +# Save environment +SAVE_ENV = { + "profile_name" : "", + "save_slot" : -1, + "pieces" : [], + "items" : [], + "hq_upgrades" : [], + "progress_state" : -1, + "unlock_flags" : [] +} + # Error types class ManagerBusError(Exception): """ Raised when an error occurs as part of ManagerBus operation. """ - diff --git a/src/subsystem.py b/src/subsystem.py @@ -1,4 +1,4 @@ -import pygame +import pygame, os, json from .constants import * ################ @@ -76,3 +76,15 @@ class SaveSystem(GameSubsystem): # Parent init super().__init__(game) + + # Environment + self.active_save_env = {} + + def save_to_file(self, filename): + with open(os.path.join(SAVE_PATH, filename)) as sf: json.dump(self.active_save_env, sf) + + def load_from_file(self, filename): + with open(os.path.join(SAVE_PATH, filename)) as lf: self.active_save_env = json.load(lf) + + def apply_environment(self): + pass