Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug that game crush loading level3 #80

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/services/global_foes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from src.game_entities.foe import Foe

foes_by_mission: dict[str, list[Foe]] = {}

def link_foe_to_mission(foe: Foe, mission_id: str) -> None:
if mission_id not in foes_by_mission:
foes_by_mission[mission_id] = []
foes_by_mission[mission_id].append(foe)

11 changes: 2 additions & 9 deletions src/services/load_from_tmx_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,9 @@
from src.game_entities.shop import Shop
from src.gui.position import Position
from src.services import load_from_xml_manager as xml_loader
from src.services.global_foes import foes_by_mission, link_foe_to_mission

objective_tile_by_mission: dict[str, list[Objective]] = {}
foes_by_mission: dict[str, list[Foe]] = {}


def _link_foe_to_mission(foe: Foe, mission_id: str) -> None:
if mission_id not in foes_by_mission:
foes_by_mission[mission_id] = []
foes_by_mission[mission_id].append(foe)


def _get_object_position(
tile_object: TiledObject, horizontal_gap: int, vertical_gap: int
Expand Down Expand Up @@ -191,7 +184,7 @@ def load_foes(
foes.append(foe)

if mission_target:
_link_foe_to_mission(foe, mission_target)
link_foe_to_mission(foe, mission_target)

return foes

Expand Down
11 changes: 2 additions & 9 deletions src/services/load_from_xml_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
RACES_DATA_PATH = "data/races.xml"
CLASSES_DATA_PATH = "data/classes.xml"

foes_by_mission: dict[str, list[Foe]] = {}
from src.services.global_foes import foes_by_mission, link_foe_to_mission


def load_races() -> dict[str, dict[str, any]]:
Expand Down Expand Up @@ -485,13 +485,6 @@ def load_ally(name: str, position: Position) -> Character:

return loaded_ally


def _link_foe_to_mission(foe: Foe, mission_id: str) -> None:
if mission_id not in foes_by_mission:
foes_by_mission[mission_id] = []
foes_by_mission[mission_id].append(foe)


def load_foe_from_save(foe_element, gap_x, gap_y):
"""

Expand Down Expand Up @@ -597,7 +590,7 @@ def load_foe_from_save(foe_element, gap_x, gap_y):
loaded_foe.earn_xp(experience)

if mission_target is not None:
_link_foe_to_mission(loaded_foe, mission_target)
link_foe_to_mission(loaded_foe, mission_target)

return loaded_foe

Expand Down
Loading