diff --git a/Toby Doom Launcher.py b/Toby Doom Launcher.py index 49ad7f6..d35e351 100755 --- a/Toby Doom Launcher.py +++ b/Toby Doom Launcher.py @@ -854,14 +854,14 @@ class DoomLauncher(QMainWindow): self.configFile = Path(os.getenv('XDG_CONFIG_HOME', Path.home() / '.config')) / 'gzdoom/gzdoom.ini' # Make sure controls are set - self.checkAndFixControls() + self.check_and_fix_controls() self.tobyVersion = TOBY_VERSION self.speechHandler = SpeechHandler(self.configFile) self.iwadSelector = IWADSelector() # Add IWAD selector self.init_launcher_ui() - def checkAndFixControls(self): + def check_and_fix_controls(self): """Check and fix control bindings in GZDoom configuration for all game types.""" if not self.configFile.exists(): print("Config file not found") @@ -886,7 +886,8 @@ class DoomLauncher(QMainWindow): 'R': 'pukename TurnCompass 0', # Turn compass left 'Q': 'pukename CompassScript', # Compass script ';': 'netevent Toby_CheckLevelStats', # Check level stats - "'": 'toby_proximity_toggle_keybind' # Toggle proximity detector + "'": 'toby_proximity_toggle_keybind', # Toggle proximity detector + 'Z': '+toby_snap_to_target_keybind' # Target snap function } # Map section prefixes to their control sections @@ -928,6 +929,7 @@ class DoomLauncher(QMainWindow): compassModSection = f"{prefix}.CompassMod.Bindings" proximitySection = f"{prefix}.ProximityDetector.Bindings" checkModSection = f"{prefix}.CheckMod.Bindings" + targetSnapSection = f"{prefix}.TargetSnap.Bindings" # Check if the accessibility sections exist, create them if not if compassModSection not in sections: @@ -951,7 +953,7 @@ class DoomLauncher(QMainWindow): for i, line in enumerate(configLines): if line.strip() == f"[{mainBindingSection}]": # Find the next section - nextSectionIdx = next((j for j in range(i+1, len(configLines)) if configLines[j].strip().startswith('[')), len(configLines)) + nextSectionIdx = next((j for j in range(i+1, len(configLines)) if configLines[j].strip().startsWith('[')), len(configLines)) # Insert the new section before the next section configLines.insert(nextSectionIdx, f"\n[{proximitySection}]\n") configLines.insert(nextSectionIdx+1, "'=toby_proximity_toggle_keybind\n\n") @@ -978,6 +980,20 @@ class DoomLauncher(QMainWindow): print(f"Added {checkModSection} section") break + # Check if the target snap section exists, create it if not + if targetSnapSection not in sections: + # Need to add this section + for i, line in enumerate(configLines): + if line.strip() == f"[{mainBindingSection}]": + # Find the next section + nextSectionIdx = next((j for j in range(i+1, len(configLines)) if configLines[j].strip().startswith('[')), len(configLines)) + # Insert the new section before the next section + configLines.insert(nextSectionIdx, f"\n[{targetSnapSection}]\n") + configLines.insert(nextSectionIdx+1, "Z=+toby_snap_to_target_keybind\n\n") + changesNeeded = True + print(f"Added {targetSnapSection} section with Z key binding") + break + # Check if accessibility keys are correctly set in existing sections currentSection = None for i, line in enumerate(configLines): @@ -1031,6 +1047,18 @@ class DoomLauncher(QMainWindow): configLines[i] = ";=netevent Toby_CheckLevelStats\n" changesNeeded = True print(f"Fixed ; key in {checkModSection}") + + # Process target snap bindings + if currentSection == targetSnapSection and '=' in line: + key, binding = line.split('=', 1) + key = key.strip() + binding = binding.strip() + + # Check Z key for target snap function + if key == "Z" and binding != '+toby_snap_to_target_keybind': + configLines[i] = "Z=+toby_snap_to_target_keybind\n" + changesNeeded = True + print(f"Fixed Z key in {targetSnapSection}") # Write the config if needed if changesNeeded: