Experimental changes to addon loading.
This commit is contained in:
@@ -1999,15 +1999,15 @@ class DoomLauncher(QMainWindow):
|
|||||||
with open(self.configFile, 'r') as f:
|
with open(self.configFile, 'r') as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
|
||||||
# Try to find and replace existing setting
|
# Replace ALL occurrences of Toby_NarrationOutputType (for all game sections)
|
||||||
found = False
|
found = False
|
||||||
for i, line in enumerate(lines):
|
for i, line in enumerate(lines):
|
||||||
if line.strip().startswith('Toby_NarrationOutputType='):
|
if line.strip().startswith('Toby_NarrationOutputType='):
|
||||||
lines[i] = f'Toby_NarrationOutputType={value}\n'
|
lines[i] = f'Toby_NarrationOutputType={value}\n'
|
||||||
found = True
|
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:
|
if not found:
|
||||||
globalSettingsIndex = -1
|
globalSettingsIndex = -1
|
||||||
for i, line in enumerate(lines):
|
for i, line in enumerate(lines):
|
||||||
@@ -2265,6 +2265,50 @@ class DoomLauncher(QMainWindow):
|
|||||||
|
|
||||||
return True
|
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]:
|
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
|
"""Get all addon PK3 files for specified game type
|
||||||
|
|
||||||
@@ -2278,47 +2322,52 @@ class DoomLauncher(QMainWindow):
|
|||||||
gamePath = self.gamePath / "Addons" / game_type
|
gamePath = self.gamePath / "Addons" / game_type
|
||||||
if gamePath.exists():
|
if gamePath.exists():
|
||||||
if game_type == "HERETIC":
|
if game_type == "HERETIC":
|
||||||
heretic_addons = [
|
# Define addon base names in load order
|
||||||
"TobyHereticWeaponsV9.pk3",
|
heretic_addon_specs = [
|
||||||
"TobyHereticMonsters.pk3",
|
("TobyHereticWeapons", "", ".pk3"),
|
||||||
"TobyHereticItemsV8.pk3",
|
("TobyHereticMonsters", "", ".pk3"),
|
||||||
"TobyHereticDecorations.pk3",
|
("TobyHereticItems", "", ".pk3"),
|
||||||
"TobyHereticMenu.wad",
|
("TobyHereticDecorations", "", ".pk3"),
|
||||||
"TobyHereticBeacons.pk3"
|
("TobyHereticMenu", "", ".wad"),
|
||||||
|
("TobyHereticBeacons", "", ".pk3")
|
||||||
]
|
]
|
||||||
|
|
||||||
for addon in heretic_addons:
|
for base_name, suffix, extension in heretic_addon_specs:
|
||||||
addon_path = gamePath / addon
|
found_file = self.find_best_addon_file(gamePath, base_name, suffix, extension)
|
||||||
if addon_path.exists():
|
if found_file:
|
||||||
addonFiles.append(str(addon_path))
|
addonFiles.append(str(found_file))
|
||||||
|
|
||||||
elif game_type == "HEXEN":
|
elif game_type == "HEXEN":
|
||||||
hexen_addons = [
|
# Define addon base names in load order
|
||||||
"TobyHexenWeaponsV9.pk3",
|
hexen_addon_specs = [
|
||||||
"TobyHexenMonsters.pk3",
|
("TobyHexenWeapons", "", ".pk3"),
|
||||||
"TobyHexenItems.pk3",
|
("TobyHexenMonsters", "", ".pk3"),
|
||||||
"TobyHexenDecorations.pk3",
|
("TobyHexenItems", "", ".pk3"),
|
||||||
"TobyHexenMenu.wad"
|
("TobyHexenDecorations", "", ".pk3"),
|
||||||
|
("TobyHexenMenu", "", ".wad")
|
||||||
]
|
]
|
||||||
|
|
||||||
for addon in hexen_addons:
|
for base_name, suffix, extension in hexen_addon_specs:
|
||||||
addon_path = gamePath / addon
|
found_file = self.find_best_addon_file(gamePath, base_name, suffix, extension)
|
||||||
if addon_path.exists():
|
if found_file:
|
||||||
addonFiles.append(str(addon_path))
|
addonFiles.append(str(found_file))
|
||||||
|
|
||||||
else: # DOOM
|
else: # DOOM
|
||||||
# Add Doom addons in specific order matching bat file
|
# Add Doom addons in specific order matching bat file
|
||||||
doom_addons = [
|
# DOOM files use pattern: TobyV{version}_{component}.pk3
|
||||||
"TobyV9_Guns.pk3",
|
doom_addon_specs = [
|
||||||
"TobyV7_Monsters.pk3" if not use_funny_pack else None,
|
("Toby", "_Guns", ".pk3"),
|
||||||
"TobyV8_Pickups.pk3",
|
("Toby", "_Monsters", ".pk3") if not use_funny_pack else None,
|
||||||
"TobyV8_Decorations.pk3"
|
("Toby", "_Pickups", ".pk3"),
|
||||||
|
("Toby", "_Decorations", ".pk3")
|
||||||
]
|
]
|
||||||
|
|
||||||
for addon in doom_addons:
|
for spec in doom_addon_specs:
|
||||||
if addon:
|
if spec:
|
||||||
addon_path = gamePath / addon
|
base_name, suffix, extension = spec
|
||||||
if addon_path.exists():
|
found_file = self.find_best_addon_file(gamePath, base_name, suffix, extension)
|
||||||
addonFiles.append(str(addon_path))
|
if found_file:
|
||||||
|
addonFiles.append(str(found_file))
|
||||||
|
|
||||||
if use_funny_pack:
|
if use_funny_pack:
|
||||||
# Look for Funny Pack in the APRIL folder
|
# Look for Funny Pack in the APRIL folder
|
||||||
@@ -2341,15 +2390,16 @@ class DoomLauncher(QMainWindow):
|
|||||||
# Add menu files in order
|
# Add menu files in order
|
||||||
# Sound directory files use capitalized names (DOOM, Heretic, Hexen)
|
# Sound directory files use capitalized names (DOOM, Heretic, Hexen)
|
||||||
sound_dir_name = game_type if game_type == "DOOM" else game_type.capitalize()
|
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:
|
# SimpleMenu uses Toby prefix with version
|
||||||
addon_path = menuPath / addon
|
simple_menu = self.find_best_addon_file(menuPath, "Toby", "_SimpleMenu", ".pk3")
|
||||||
if addon_path.exists():
|
if simple_menu:
|
||||||
addonFiles.append(str(addon_path))
|
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
|
return addonFiles
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user