Skip to content

Commit 589928f

Browse files
author
d.schlatter
committed
add bg3_data_content.py
1 parent 3b019cb commit 589928f

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from enum import IntEnum, auto
2+
3+
import mobase
4+
5+
6+
class Content(IntEnum):
7+
PAK = auto()
8+
WORKSPACE = auto()
9+
NATIVE = auto()
10+
LOOSE_FILES = auto()
11+
SE_FILES = auto()
12+
13+
14+
class BG3DataContent(mobase.ModDataContent):
15+
BG3_CONTENTS: list[tuple[Content, str, str, bool] | tuple[Content, str, str]] = [
16+
(Content.WORKSPACE, "Mod workspaces", ":/MO/gui/content/plugin"),
17+
(Content.PAK, "Paks", ":/MO/gui/content/geometries"),
18+
(Content.LOOSE_FILES, "Loose file override mods", ":/MO/gui/content/skse"),
19+
(Content.SE_FILES, "Script Extender Files", "", True),
20+
(Content.NATIVE, "Native DLL mods", ":/MO/gui/content/script"),
21+
]
22+
23+
def getAllContents(self) -> list[mobase.ModDataContent.Content]:
24+
return [
25+
mobase.ModDataContent.Content(id, name, icon, *filter_only)
26+
for id, name, icon, *filter_only in self.BG3_CONTENTS
27+
]
28+
29+
def getContentsFor(self, filetree: mobase.IFileTree) -> list[int]:
30+
contents: set[int] = set()
31+
for entry in filetree:
32+
if isinstance(entry, mobase.IFileTree):
33+
match entry.name().casefold():
34+
case "Script Extender":
35+
contents.add(Content.SE_FILES)
36+
case "Data":
37+
contents.add(Content.LOOSE_FILES)
38+
case x if x.endswith(".pak"):
39+
contents.add(Content.PAK)
40+
case "Mods":
41+
for e in entry:
42+
if e.name().endswith(".pak"):
43+
contents.add(Content.PAK)
44+
break
45+
case "bin":
46+
contents.add(Content.NATIVE)
47+
case _:
48+
for e in entry:
49+
match e.name().casefold():
50+
case "Mods" | "Localization" | "ScriptExtender" | "Public" | "Generated":
51+
contents.add(Content.WORKSPACE)
52+
break
53+
return list(contents)

games/game_baldursgate3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self):
5353

5454
def init(self, organizer: mobase.IOrganizer) -> bool:
5555
super().init(organizer)
56-
from baldursgate3 import bg3_data_checker, bg3_utils
56+
from baldursgate3 import bg3_data_checker, bg3_utils, bg3_data_content
5757

5858
self._utils = bg3_utils.BG3Utils(organizer, self.name())
5959
self._register_feature(
@@ -77,6 +77,7 @@ def init(self, organizer: mobase.IOrganizer) -> bool:
7777
)
7878
)
7979
)
80+
self._register_feature(bg3_data_content.BG3DataContent())
8081
self._register_feature(BasicGameSaveGameInfo(lambda s: s.with_suffix(".webp")))
8182
self._register_feature(BasicLocalSavegames(self.savesDirectory()))
8283
organizer.onAboutToRun(self._utils.construct_modsettings_xml)

0 commit comments

Comments
 (0)