From ca3c8bd57824eaded97a6064769107a42cdd2115 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=B1=AA=E8=BE=89=EF=BC=8823=E7=A1=95=EF=BC=89?=
<22321203@zju.edu.cn>
Date: Tue, 2 Jan 2024 12:25:48 +0800
Subject: [PATCH 1/3] fix the bug that game crush when loading level 3
---
saves/options.xml | 2 +-
src/services/global_foes.py | 9 +++++++++
src/services/load_from_tmx_manager.py | 11 ++---------
src/services/load_from_xml_manager.py | 13 +++++++------
4 files changed, 19 insertions(+), 16 deletions(-)
create mode 100644 src/services/global_foes.py
diff --git a/saves/options.xml b/saves/options.xml
index c815c75e..649ba3e6 100644
--- a/saves/options.xml
+++ b/saves/options.xml
@@ -1,5 +1,5 @@
- en
+ zh_cn
4
1
\ No newline at end of file
diff --git a/src/services/global_foes.py b/src/services/global_foes.py
new file mode 100644
index 00000000..a8a6ec8f
--- /dev/null
+++ b/src/services/global_foes.py
@@ -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)
+
diff --git a/src/services/load_from_tmx_manager.py b/src/services/load_from_tmx_manager.py
index 9f5cd88d..c438a89b 100644
--- a/src/services/load_from_tmx_manager.py
+++ b/src/services/load_from_tmx_manager.py
@@ -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
@@ -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
diff --git a/src/services/load_from_xml_manager.py b/src/services/load_from_xml_manager.py
index 34c475d9..f6ce3407 100644
--- a/src/services/load_from_xml_manager.py
+++ b/src/services/load_from_xml_manager.py
@@ -38,7 +38,8 @@
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
+# foes_by_mission: dict[str, list[Foe]] = {}
def load_races() -> dict[str, dict[str, any]]:
@@ -486,10 +487,10 @@ 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 _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):
@@ -597,7 +598,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
From 5256cabe5983d40c352a97ed3854816f60235c99 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=B1=AA=E8=BE=89=EF=BC=8823=E7=A1=95=EF=BC=89?=
<22321203@zju.edu.cn>
Date: Tue, 2 Jan 2024 12:27:54 +0800
Subject: [PATCH 2/3] fix the bug that game crush when loading level 3
---
src/services/load_from_xml_manager.py | 7 -------
1 file changed, 7 deletions(-)
diff --git a/src/services/load_from_xml_manager.py b/src/services/load_from_xml_manager.py
index f6ce3407..056b8b9a 100644
--- a/src/services/load_from_xml_manager.py
+++ b/src/services/load_from_xml_manager.py
@@ -486,13 +486,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):
"""
From 3b021d96ff48c062cfe987d94f989f70ae46d07b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=B1=AA=E8=BE=89=EF=BC=8823=E7=A1=95=EF=BC=89?=
<22321203@zju.edu.cn>
Date: Thu, 11 Jan 2024 15:21:03 +0800
Subject: [PATCH 3/3] Modified according to review
---
saves/options.xml | 2 +-
src/services/load_from_xml_manager.py | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/saves/options.xml b/saves/options.xml
index 649ba3e6..c815c75e 100644
--- a/saves/options.xml
+++ b/saves/options.xml
@@ -1,5 +1,5 @@
- zh_cn
+ en
4
1
\ No newline at end of file
diff --git a/src/services/load_from_xml_manager.py b/src/services/load_from_xml_manager.py
index 056b8b9a..35ebeb85 100644
--- a/src/services/load_from_xml_manager.py
+++ b/src/services/load_from_xml_manager.py
@@ -39,7 +39,6 @@
CLASSES_DATA_PATH = "data/classes.xml"
from src.services.global_foes import foes_by_mission, link_foe_to_mission
-# foes_by_mission: dict[str, list[Foe]] = {}
def load_races() -> dict[str, dict[str, any]]: