Compare commits
2 commits
dce9e5fcdc
...
0a5cb83274
| Author | SHA1 | Date | |
|---|---|---|---|
| 0a5cb83274 | |||
| 049acf68be |
2 changed files with 63 additions and 6 deletions
15
src/mod.py
15
src/mod.py
|
|
@ -43,13 +43,16 @@ class Mod:
|
|||
def __init__(self, path: str) -> None:
|
||||
self.__path = path
|
||||
|
||||
with open(path + "config.toml") as config_file:
|
||||
self.__config = tomlkit.load(config_file)
|
||||
try:
|
||||
with open(path + "config.toml") as config_file:
|
||||
self.__config = tomlkit.load(config_file)
|
||||
|
||||
if "enabled" not in self.__config:
|
||||
raise InvalidModError("config.toml does not contain the enabled key")
|
||||
else:
|
||||
self.__enabled = self.__config["enabled"]
|
||||
if "enabled" not in self.__config:
|
||||
raise InvalidModError("config.toml does not contain the enabled key")
|
||||
else:
|
||||
self.__enabled = self.__config["enabled"]
|
||||
except FileNotFoundError:
|
||||
raise InvalidModError("config.toml does not exist")
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Mod({self.__path})"
|
||||
|
|
|
|||
54
src/mod_list.py
Normal file
54
src/mod_list.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
from PySide6.QtQml import QmlElement
|
||||
from PySide6.QtCore import QAbstractListModel, QModelIndex
|
||||
from mod import Mod, InvalidModError
|
||||
import os
|
||||
|
||||
QML_IMPORT_NAME = "Leek"
|
||||
QML_IMPORT_MAJOR_VERSION = 1
|
||||
|
||||
# TODO: Don't harcode the mods path
|
||||
GAME_PATH = "/home/toast/.local/share/Steam/steamapps/common/Hatsune Miku Project DIVA Mega Mix Plus/"
|
||||
|
||||
# Qt follows C++ naming conventions
|
||||
# ruff: noqa: N802
|
||||
@QmlElement
|
||||
class QModListModel(QAbstractListModel):
|
||||
def __init__(self, parent=None) -> None:
|
||||
super().__init__(parent=parent)
|
||||
mods: list[Mod] = []
|
||||
|
||||
with os.scandir(GAME_PATH + "mods/") as dirs:
|
||||
for dir in dirs:
|
||||
try:
|
||||
new_mod: Mod = Mod(dir.path + "/" )
|
||||
mods.append(new_mod)
|
||||
except InvalidModError as e:
|
||||
print(f"Found invalid mod at {dir.path}: {e.message}")
|
||||
continue
|
||||
|
||||
self.mods = mods
|
||||
|
||||
def roleNames(self) -> dict[int, bytes]:
|
||||
return {
|
||||
0: b"name",
|
||||
1: b"description",
|
||||
2: b"enabled"
|
||||
}
|
||||
|
||||
def rowCount(self, parent=QModelIndex()) -> int:
|
||||
return len(self.mods)
|
||||
|
||||
def data(self, index: QModelIndex, role: int) -> None | str | bool:
|
||||
i: int = index.row()
|
||||
result: None | str | bool
|
||||
if not index.isValid():
|
||||
result = None
|
||||
elif role == 0:
|
||||
result = self.mods[i].name
|
||||
elif role == 1:
|
||||
result = self.mods[i].description
|
||||
elif role == 2:
|
||||
result = self.mods[i].enabled
|
||||
else:
|
||||
result = None
|
||||
return result
|
||||
Loading…
Add table
Add a link
Reference in a new issue