Experimental changes to addon loading.
This commit is contained in:
@@ -1999,15 +1999,15 @@ class DoomLauncher(QMainWindow):
|
||||
with open(self.configFile, 'r') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
# Try to find and replace existing setting
|
||||
# Replace ALL occurrences of Toby_NarrationOutputType (for all game sections)
|
||||
found = False
|
||||
for i, line in enumerate(lines):
|
||||
if line.strip().startswith('Toby_NarrationOutputType='):
|
||||
lines[i] = f'Toby_NarrationOutputType={value}\n'
|
||||
found = True
|
||||
break
|
||||
# Don't break - continue to update all occurrences
|
||||
|
||||
# If not found, add to end or after [GlobalSettings]
|
||||
# If not found anywhere, add to end or after [GlobalSettings]
|
||||
if not found:
|
||||
globalSettingsIndex = -1
|
||||
for i, line in enumerate(lines):
|
||||
@@ -2265,6 +2265,50 @@ class DoomLauncher(QMainWindow):
|
||||
|
||||
return True
|
||||
|
||||
def find_best_addon_file(self, addon_path: Path, base_name: str, suffix: str = "", extension: str = ".pk3") -> Optional[Path]:
|
||||
"""Find the best matching addon file with version fallback logic.
|
||||
|
||||
Searches for addon files in this priority order:
|
||||
1. Files matching current TOBY_VERSION_NUMBER (e.g., V9)
|
||||
2. Falls back through previous versions (V8, V7, V6, etc.)
|
||||
3. Falls back to unversioned files
|
||||
|
||||
Args:
|
||||
addon_path: Directory to search in
|
||||
base_name: Base name of the addon (e.g., "TobyHereticWeapons", "Toby")
|
||||
suffix: Suffix after version (e.g., "_Guns", "_Pickups") - for DOOM files
|
||||
extension: File extension (default: ".pk3")
|
||||
|
||||
Returns:
|
||||
Path to the best matching file, or None if no match found
|
||||
|
||||
Examples:
|
||||
find_best_addon_file(path, "TobyHereticWeapons", "", ".pk3")
|
||||
-> Prefers TobyHereticWeaponsV9.pk3, falls back to V8, V7, then TobyHereticWeapons.pk3
|
||||
|
||||
find_best_addon_file(path, "Toby", "_Guns", ".pk3")
|
||||
-> Prefers TobyV9_Guns.pk3, falls back to V8, V7, then Toby_Guns.pk3
|
||||
"""
|
||||
if not addon_path.exists():
|
||||
return None
|
||||
|
||||
# Get current version as integer (9.0 -> 9, "9-0" -> 9)
|
||||
# tobyVersion is a string like "9-0", extract the major version number
|
||||
current_version = int(self.tobyVersion.split('-')[0])
|
||||
|
||||
# Try versioned files from current down to V1
|
||||
for version in range(current_version, 0, -1):
|
||||
versioned_file = addon_path / f"{base_name}V{version}{suffix}{extension}"
|
||||
if versioned_file.exists():
|
||||
return versioned_file
|
||||
|
||||
# Fall back to unversioned file
|
||||
unversioned_file = addon_path / f"{base_name}{suffix}{extension}"
|
||||
if unversioned_file.exists():
|
||||
return unversioned_file
|
||||
|
||||
return None
|
||||
|
||||
def get_addon_files(self, game_type: str = "DOOM", use_funny_pack: bool = False) -> List[str]:
|
||||
"""Get all addon PK3 files for specified game type
|
||||
|
||||
@@ -2273,53 +2317,58 @@ class DoomLauncher(QMainWindow):
|
||||
use_funny_pack: Whether to use the Funny Pack instead of normal monsters
|
||||
"""
|
||||
addonFiles = []
|
||||
|
||||
|
||||
# Game specific addons first (following bat file order)
|
||||
gamePath = self.gamePath / "Addons" / game_type
|
||||
if gamePath.exists():
|
||||
if game_type == "HERETIC":
|
||||
heretic_addons = [
|
||||
"TobyHereticWeaponsV9.pk3",
|
||||
"TobyHereticMonsters.pk3",
|
||||
"TobyHereticItemsV8.pk3",
|
||||
"TobyHereticDecorations.pk3",
|
||||
"TobyHereticMenu.wad",
|
||||
"TobyHereticBeacons.pk3"
|
||||
# Define addon base names in load order
|
||||
heretic_addon_specs = [
|
||||
("TobyHereticWeapons", "", ".pk3"),
|
||||
("TobyHereticMonsters", "", ".pk3"),
|
||||
("TobyHereticItems", "", ".pk3"),
|
||||
("TobyHereticDecorations", "", ".pk3"),
|
||||
("TobyHereticMenu", "", ".wad"),
|
||||
("TobyHereticBeacons", "", ".pk3")
|
||||
]
|
||||
|
||||
for addon in heretic_addons:
|
||||
addon_path = gamePath / addon
|
||||
if addon_path.exists():
|
||||
addonFiles.append(str(addon_path))
|
||||
|
||||
|
||||
for base_name, suffix, extension in heretic_addon_specs:
|
||||
found_file = self.find_best_addon_file(gamePath, base_name, suffix, extension)
|
||||
if found_file:
|
||||
addonFiles.append(str(found_file))
|
||||
|
||||
elif game_type == "HEXEN":
|
||||
hexen_addons = [
|
||||
"TobyHexenWeaponsV9.pk3",
|
||||
"TobyHexenMonsters.pk3",
|
||||
"TobyHexenItems.pk3",
|
||||
"TobyHexenDecorations.pk3",
|
||||
"TobyHexenMenu.wad"
|
||||
# Define addon base names in load order
|
||||
hexen_addon_specs = [
|
||||
("TobyHexenWeapons", "", ".pk3"),
|
||||
("TobyHexenMonsters", "", ".pk3"),
|
||||
("TobyHexenItems", "", ".pk3"),
|
||||
("TobyHexenDecorations", "", ".pk3"),
|
||||
("TobyHexenMenu", "", ".wad")
|
||||
]
|
||||
|
||||
for addon in hexen_addons:
|
||||
addon_path = gamePath / addon
|
||||
if addon_path.exists():
|
||||
addonFiles.append(str(addon_path))
|
||||
|
||||
for base_name, suffix, extension in hexen_addon_specs:
|
||||
found_file = self.find_best_addon_file(gamePath, base_name, suffix, extension)
|
||||
if found_file:
|
||||
addonFiles.append(str(found_file))
|
||||
|
||||
else: # DOOM
|
||||
# Add Doom addons in specific order matching bat file
|
||||
doom_addons = [
|
||||
"TobyV9_Guns.pk3",
|
||||
"TobyV7_Monsters.pk3" if not use_funny_pack else None,
|
||||
"TobyV8_Pickups.pk3",
|
||||
"TobyV8_Decorations.pk3"
|
||||
# DOOM files use pattern: TobyV{version}_{component}.pk3
|
||||
doom_addon_specs = [
|
||||
("Toby", "_Guns", ".pk3"),
|
||||
("Toby", "_Monsters", ".pk3") if not use_funny_pack else None,
|
||||
("Toby", "_Pickups", ".pk3"),
|
||||
("Toby", "_Decorations", ".pk3")
|
||||
]
|
||||
|
||||
for addon in doom_addons:
|
||||
if addon:
|
||||
addon_path = gamePath / addon
|
||||
if addon_path.exists():
|
||||
addonFiles.append(str(addon_path))
|
||||
|
||||
|
||||
for spec in doom_addon_specs:
|
||||
if spec:
|
||||
base_name, suffix, extension = spec
|
||||
found_file = self.find_best_addon_file(gamePath, base_name, suffix, extension)
|
||||
if found_file:
|
||||
addonFiles.append(str(found_file))
|
||||
|
||||
if use_funny_pack:
|
||||
# Look for Funny Pack in the APRIL folder
|
||||
aprilPath = self.gamePath / "Addons" / "APRIL"
|
||||
@@ -2330,7 +2379,7 @@ class DoomLauncher(QMainWindow):
|
||||
addonFiles.append(str(funnyPackPath))
|
||||
else:
|
||||
QMessageBox.warning(
|
||||
None,
|
||||
None,
|
||||
"Funny Pack Missing",
|
||||
f"Toby_Funny_Pack.pk3 not found in {aprilPath}. Please make sure it's installed correctly in the Addons/APRIL folder."
|
||||
)
|
||||
@@ -2341,15 +2390,16 @@ class DoomLauncher(QMainWindow):
|
||||
# Add menu files in order
|
||||
# Sound directory files use capitalized names (DOOM, Heretic, Hexen)
|
||||
sound_dir_name = game_type if game_type == "DOOM" else game_type.capitalize()
|
||||
menu_addons = [
|
||||
"TobyV9_SimpleMenu.pk3",
|
||||
f"TobySoundDirectory_{sound_dir_name}.pk3"
|
||||
]
|
||||
|
||||
for addon in menu_addons:
|
||||
addon_path = menuPath / addon
|
||||
if addon_path.exists():
|
||||
addonFiles.append(str(addon_path))
|
||||
# SimpleMenu uses Toby prefix with version
|
||||
simple_menu = self.find_best_addon_file(menuPath, "Toby", "_SimpleMenu", ".pk3")
|
||||
if simple_menu:
|
||||
addonFiles.append(str(simple_menu))
|
||||
|
||||
# Sound directory files typically don't have version numbers, but check anyway
|
||||
sound_dir = self.find_best_addon_file(menuPath, f"TobySoundDirectory_{sound_dir_name}", "", ".pk3")
|
||||
if sound_dir:
|
||||
addonFiles.append(str(sound_dir))
|
||||
|
||||
return addonFiles
|
||||
|
||||
|
||||
Reference in New Issue
Block a user