commit 087ad955ffa7c1654efbb4e0aac11d0a036e8359
parent 4cc566979026349edfb3739b739dcdcde02f1b7a
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Sat, 28 Aug 2021 13:31:58 -0500
basic save-load working
Diffstat:
3 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/src/board.py b/src/board.py
@@ -198,7 +198,7 @@ class Board(object):
"""
if event["type"] == "changeboard":
self.game.switch_board(event["board"], tuple(event["cell"]))
- self.game.spawn_player(tuple(event["cell"]), tuple(event["tile"]))
+ self.game.spawn_player(self.game.party[self.game.player_name], tuple(event["cell"]), tuple(event["tile"]))
def update_board(self, draw_surface, viewport_rect):
"""
diff --git a/src/game.py b/src/game.py
@@ -44,7 +44,7 @@ class Game(object):
# Gameplay objects
self.player = None
self.player_name = ""
- self.party = {}
+ self.party = []
# UI elements
self.ui_font = pygame.font.Font(os.path.join(FONT_PATH, MESSAGE_FONT), MESSAGE_FONT_SIZE) # TODO: Should there be a UI font option???
@@ -84,6 +84,9 @@ class Game(object):
self.load_boards("boards.json")
self.build_ui()
+ # TMP!
+ self.load_game("savegame1")
+
def load_sheets(self, imagefile):
"""
Load all of the images as sheets.
@@ -140,18 +143,17 @@ class Game(object):
else:
return 1
- def spawn_player(self, playername, cellpos, tilepos):
+ def spawn_player(self, playerchar, cellpos, tilepos):
"""
Spawn the player in the current board at
- the given cell and tile coordinates. Called
- by board entity placement events once to
- place the player initially, then again
- whenever the player changes from one board
- to another.
+ the given cellpos and tilepos. Called on load
+ and game start. 'playerchar' is a party
+ character dict, which should contain info
+ needed to create a player.
"""
if self.current_board != None:
- self.player = entity.PlayerEntity(self.sheets["chars" + str(self.current_board.scale_factor)].sprites[(0, 0)], cellpos, tilepos)
- self.player_name = playername
+ self.player = entity.PlayerEntity(self.sheets[playerchar["sheet"] + str(self.current_board.scale_factor)].sprites[tuple(playerchar["sprite"])], cellpos, tilepos)
+ self.player_name = playerchar["name"]
self.player.rect.topleft = ((SCREEN_WIDTH // 3) - 6, (SCREEN_HEIGHT // 3) - 6)# TODO: Weirdly derived
self.current_board.position_offset = self.player.rect.topleft
self.current_board.position_to_tile(tilepos)
@@ -273,7 +275,7 @@ class Game(object):
else:
day_index = 0
self.datestring = day_meas + self.day_descriptors[day_index] + " of " + mnth
- self.clockstring = "Year " + str(self.years) + " | " + str("0" if self.hours <= 9 else "") + str(self.hours) + ":" + str("0" if self.minutes <= 9 else "") + str(self.minutes) + ":" + str("0" if self.seconds <= 9 else "") + str(self.seconds) + " o'clock"
+ self.clockstring = "Year " + str(self.years) + " ]|[ " + str("0" if self.hours <= 9 else "") + str(self.hours) + ":" + str("0" if self.minutes <= 9 else "") + str(self.minutes) + ":" + str("0" if self.seconds <= 9 else "") + str(self.seconds) + " o'clock"
def post_message(self, text):
"""
@@ -345,7 +347,7 @@ class Game(object):
self.player_name = saveraw["player"]
self.party = saveraw["party"]
self.switch_board(saveraw["board"], tuple(saveraw["cell"]))
- self.spawn
+ self.spawn_player(saveraw["party"][saveraw["player"]], tuple(saveraw["cell"]), tuple(saveraw["tile"]))
# Switch to game control
# TODO: Saves will eventually take note of what mode they were saved in
diff --git a/src/gamelib.py b/src/gamelib.py
@@ -16,7 +16,7 @@ import pygame, os, pathlib, enum, json
# Conditional/initial paths
DATA_PATH = os.path.join(os.getcwd(), "data")
ETC_PATH = os.path.join(DATA_PATH, "etc")
-USERLOCAL_PATH = os.path.join(str(pathlib.Path.home), ".local", "share", "tzed")
+USERLOCAL_PATH = os.path.join(str(pathlib.Path.home()), ".local", "share", "tzed")
if os.path.exists(os.path.join(USERLOCAL_PATH, "settings.json")):
SETTINGS_PATH = os.path.join(USERLOCAL_PATH, "settings.json")
else:
@@ -38,7 +38,7 @@ SCREEN_HEIGHT = SETTINGS_RAW["screen_height"]
SCREEN_MARGINS = (SETTINGS_RAW["screen_margin_x"], SETTINGS_RAW["screen_margin_y"])
FRAMERATE = SETTINGS_RAW["framerate"]
CONTROLS = SETTINGS_RAW["controls"]
-MESSAGE_FONT = SETTINGS_RAW["message_font"]t
+MESSAGE_FONT = SETTINGS_RAW["message_font"]
MESSAGE_FONT_SIZE = SETTINGS_RAW["message_font_size"]
COLOR_PALETTE = tuple(tuple(color) for color in SETTINGS_RAW["color_palette"])
OVERLAY_SHEET = SETTINGS_RAW["overlay_sheet"]