|
| 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) |
0 commit comments