commit f2b9a44e4d23fb336b08918b25af09df3d1038a3
parent bf87579fa0a2179c619a2a30d9854a07b57cf8a5
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Wed, 14 Oct 2020 16:19:55 -0500
Mode switching works now
Diffstat:
3 files changed, 39 insertions(+), 23 deletions(-)
diff --git a/data/json/menus/mainmenu.json b/data/json/menus/mainmenu.json
@@ -8,21 +8,29 @@
"sprite" : [0, 0],
"pos" : [100, 100],
"intlayer" : 0,
- "effect" : ["me_shift_battle_mode"]
+ "effects" : {
+ "me_switch_mode" : {
+ "mode" : "Battle_Mode"
+ }
+ }
},
"LoadGame" : {
"sheet" : "mainmenu_buttons_1",
"sprite" : [0, 1],
"pos" : [100, 200],
"intlayer" : 0,
- "effect" : ["me_quit"]
+ "effects" : {
+ "me_quit" : {}
+ }
},
"Options" : {
"sheet" : "mainmenu_buttons_1",
"sprite" : [0, 2],
"pos" : [100, 300],
"intlayer" : 0,
- "effect" : ["me_quit"]
+ "effects" : {
+ "me_quit" : {}
+ }
}
},
"entities" : { },
diff --git a/src/game.py b/src/game.py
@@ -53,28 +53,33 @@ class Game(object):
# Setup (This is WIP)
self.sheet_manager.load_sheets_from_json("sheets.json")
self.sheet_manager.load_animations_from_json("anims.json")
- self.entity_manager.load_tile_cursor("cursor1")
- # TODO: Fix this up, will see lots of revision
- self.menu_manager.load_menu_from_file("mainmenu.json")
- self.menu_manager.switch_to_menu("mainmenu.json")
- self.board_manager.load_board_from_file("testmap1.tmx")
- self.board_manager.switch_to_board("testmap1.tmx")
- self.unit_manager.load_stats_from_json("jisella_1.json")
- self.entity_manager.load_entities_from_json("testmap1.json")
+ # Switch to game control
+ self.switch_mode("Main_Menu_Mode")
- def switch_mode(self, new_mode_def):
+ def switch_mode(self, new_mode):
"""
Change the current state_mode, as well as load up
- the elements of the new mode.
- """
- self.state_mode = new_mode_def["new_mode"]
- self.control_mode = new_mode_def["control_mode"]
- for action in new_mode_def:
- if action == "switch_to_board":
- self.board_manager.load_board_from_file(new_mode_def[action]["name"] + ".tmx")
- self.board_manager.switch_to_board(new_mode_def[action]["name"] + ".tmx")
- self.entity_manager.load_entities_from_json(new_mode_def[action]["name"] + ".json")
+ the elements of the new mode. This large method
+ should take account of every possible mode in the
+ game. Such data has no reason to exists e.g. as a
+ JSON file.
+ """
+ self.state_mode = new_mode
+
+ if new_mode == "Main_Menu_Mode":
+ self.control_mode = "Main_Menu_Normal"
+ self.menu_manager.load_menu_from_file("mainmenu.json")
+ self.menu_manager.switch_to_menu("mainmenu.json")
+ elif new_mode == "Battle_Mode":
+ self.control_mode = "Turn_Normal"
+ # TODO: Obv this must be made more generic. Currently only
+ # sources from the one map file.
+ self.board_manager.load_board_from_file("testmap1.tmx")
+ self.board_manager.switch_to_board("testmap1.tmx")
+ self.unit_manager.load_stats_from_json("jisella_1.json")
+ self.entity_manager.load_entities_from_json("testmap1.json")
+ self.entity_manager.load_tile_cursor("cursor1")
def shift_frames(self):
"""
@@ -230,4 +235,5 @@ class GameInterface(GameSubsystem):
e.g. an Entity, and is logic-only.
"""
# Update cursor position
- self.game.entity_manager.position_tile_cursor(self.game.board_manager.get_tile_at_position(pygame.mouse.get_pos()))
+ if self.game.state_mode == "Battle_Mode":
+ self.game.entity_manager.position_tile_cursor(self.game.board_manager.get_tile_at_position(pygame.mouse.get_pos()))
diff --git a/src/menu.py b/src/menu.py
@@ -55,6 +55,8 @@ class MenuManager(manager.Manager):
for e in events:
if e == "me_quit": # Quit the game
self.game.on = False
+ elif e == "me_switch_mode": # Switch to another game mode
+ self.game.switch_mode(events[e]["mode"])
def trigger_button_at_pos(self, pos):
"""
@@ -123,7 +125,7 @@ class Menu(object):
for b in self.definition["buttons"]:
nmb = vgo.MenuButton(b, self.contained_entities,
self.manager.game.sheet_manager.loaded_sheets[self.definition["buttons"][b]["sheet"]],
- None, False, True, None, self.definition["buttons"][b]["effect"])
+ None, False, True, None, self.definition["buttons"][b]["effects"])
nmb.set_sprite(tuple(self.definition["buttons"][b]["sprite"]))
nmb.rect.topleft = tuple(self.definition["buttons"][b]["pos"])
self.button_group.add(nmb)