Skip to content

Commit 49f4bed

Browse files
committed
move globpattern declaration to bg3_data_checker.py
1 parent 5f9710b commit 49f4bed

5 files changed

Lines changed: 41 additions & 40 deletions

File tree

games/baldursgate3/bg3_data_checker.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
1+
from pathlib import Path
2+
13
import mobase
24

3-
from ...basic_features import BasicModDataChecker, utils
5+
from . import bg3_utils
6+
from ...basic_features import BasicModDataChecker, utils, GlobPatterns
47

58

69
class BG3ModDataChecker(BasicModDataChecker):
10+
def __init__(self):
11+
super().__init__(
12+
GlobPatterns(
13+
valid=[
14+
"*.pak",
15+
str(Path("Mods") / "*.pak"), # standard mods
16+
"bin", # native mods / Script Extender
17+
"Script Extender", # mods which are configured via jsons in this folder
18+
"Data", # loose file mods
19+
]
20+
+ [str(Path("*") / f) for f in bg3_utils.loose_file_folders],
21+
move={
22+
"Root/": "", # root builder not needed
23+
"*.dll": "bin/",
24+
"ScriptExtenderSettings.json": "bin/",
25+
}
26+
| {f: "Data/" for f in bg3_utils.loose_file_folders},
27+
delete=["info.json", "*.txt"],
28+
)
29+
)
30+
731
def dataLooksValid(
832
self, filetree: mobase.IFileTree
933
) -> mobase.ModDataChecker.CheckReturn:

games/baldursgate3/bg3_data_content.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import mobase
44

5+
from . import bg3_utils
6+
57

68
class Content(IntEnum):
79
PAK = auto()
@@ -44,13 +46,7 @@ def getContentsFor(self, filetree: mobase.IFileTree) -> list[int]:
4446
contents.add(Content.NATIVE)
4547
case _:
4648
for e in entry:
47-
if e.name() in {
48-
"Mods",
49-
"Localization",
50-
"ScriptExtender",
51-
"Public",
52-
"Generated",
53-
}:
49+
if e.name() in bg3_utils.loose_file_folders:
5450
contents.add(Content.WORKSPACE)
5551
break
5652
elif entry.name().endswith(".pak"):

games/baldursgate3/bg3_utils.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@
2020
)
2121
from PyQt6.QtWidgets import QApplication, QMainWindow, QProgressDialog
2222

23+
loose_file_folders = {
24+
"Public",
25+
"Mods",
26+
"Generated",
27+
"Localization",
28+
"ScriptExtender",
29+
}
30+
2331

2432
class BG3Utils:
25-
loose_file_folders = {
26-
"Public",
27-
"Mods",
28-
"Generated",
29-
"Localization",
30-
"ScriptExtender",
31-
}
3233
_mod_settings_xml_start = """<?xml version="1.0" encoding="UTF-8"?>
3334
<save>
3435
<version major="4" minor="8" revision="0" build="200"/>
@@ -288,7 +289,9 @@ def _convert_jsons_in_dir_to_yaml(path: Path):
288289
):
289290
with open(file, "r") as json_file:
290291
with open(converted_path, "w") as yaml_file:
291-
yaml.dump(json.load(json_file), yaml_file, indent=2)
292+
yaml.dump(
293+
json.load(json_file), yaml_file, indent=2, sort_keys=False
294+
)
292295
qInfo(f"Converted {file} to YAML")
293296
except OSError as e:
294297
qWarning(f"Error accessing file {converted_path}: {e}")

games/baldursgate3/pak_parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ def _get_metadata_for_file(
141141
return ""
142142
elif next(
143143
itertools.chain(
144-
file.glob(f"{folder}/*")
145-
for folder in self._utils.loose_file_folders
144+
file.glob(f"{folder}/*") for folder in bg3_utils.loose_file_folders
146145
),
147146
False,
148147
):

games/game_baldursgate3.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from ..basic_features import (
2222
BasicGameSaveGameInfo,
2323
BasicLocalSavegames,
24-
GlobPatterns,
2524
)
2625
from ..basic_game import BasicGame
2726

@@ -62,27 +61,7 @@ def init(self, organizer: mobase.IOrganizer) -> bool:
6261
bg3_script_extender,
6362
)
6463

65-
self._register_feature(
66-
bg3_data_checker.BG3ModDataChecker(
67-
GlobPatterns(
68-
valid=[
69-
"*.pak",
70-
str(Path("Mods") / "*.pak"), # standard mods
71-
"bin", # native mods / Script Extender
72-
"Script Extender", # mods which are configured via jsons in this folder
73-
"Data", # loose file mods
74-
]
75-
+ [str(Path("*") / f) for f in self._utils.loose_file_folders],
76-
move={
77-
"Root/": "",
78-
"*.dll": "bin/",
79-
"ScriptExtenderSettings.json": "bin/",
80-
} # root builder not needed
81-
| {f: "Data/" for f in self._utils.loose_file_folders},
82-
delete=["info.json", "*.txt"],
83-
)
84-
)
85-
)
64+
self._register_feature(bg3_data_checker.BG3ModDataChecker())
8665
self._register_feature(bg3_script_extender.BG3ScriptExtender(self))
8766
self._register_feature(bg3_data_content.BG3DataContent())
8867
self._register_feature(BasicGameSaveGameInfo(lambda s: s.with_suffix(".webp")))

0 commit comments

Comments
 (0)