aboutsummaryrefslogtreecommitdiff
path: root/libs/basic_games/games/baldursgate3/bg3_data_content.py
blob: c378520e32553f71b3c6b143f0eb4062b2fd3493 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from enum import IntEnum, auto

import mobase

from . import bg3_utils


class Content(IntEnum):
    PAK = auto()
    WORKSPACE = auto()
    NATIVE = auto()
    LOOSE_FILES = auto()
    SE_FILES = auto()


class BG3DataContent(mobase.ModDataContent):
    BG3_CONTENTS: list[tuple[Content, str, str, bool] | tuple[Content, str, str]] = [
        (Content.WORKSPACE, "Mod workspace", ":/MO/gui/content/script"),
        (Content.PAK, "Pak", ":/MO/gui/content/bsa"),
        (Content.LOOSE_FILES, "Loose file override mod", ":/MO/gui/content/texture"),
        (Content.SE_FILES, "Script Extender Files", ":/MO/gui/content/inifile"),
        (Content.NATIVE, "Native DLL mod", ":/MO/gui/content/plugin"),
    ]

    def getAllContents(self) -> list[mobase.ModDataContent.Content]:
        return [
            mobase.ModDataContent.Content(id, name, icon, *filter_only)
            for id, name, icon, *filter_only in self.BG3_CONTENTS
        ]

    def getContentsFor(self, filetree: mobase.IFileTree) -> list[int]:
        contents: set[int] = set()
        for entry in filetree:
            if isinstance(entry, mobase.IFileTree):
                match entry.name():
                    case "Script Extender":
                        contents.add(Content.SE_FILES)
                    case "Data":
                        contents.add(Content.LOOSE_FILES)
                    case "Mods":
                        for e in entry:
                            if e.name().endswith(".pak"):
                                contents.add(Content.PAK)
                                break
                    case "bin":
                        contents.add(Content.NATIVE)
                    case _:
                        for e in entry:
                            if e.name() in bg3_utils.loose_file_folders:
                                contents.add(Content.WORKSPACE)
                                break
            elif entry.name().endswith(".pak"):
                contents.add(Content.PAK)
        return list(contents)