Updated the keybinding fix part of the program.
This commit is contained in:
parent
432a55308f
commit
b17f1c0672
@ -866,71 +866,154 @@ class DoomLauncher(QMainWindow):
|
||||
if not self.configFile.exists():
|
||||
print("Config file not found")
|
||||
return False
|
||||
|
||||
|
||||
try:
|
||||
# Read config file
|
||||
with open(self.configFile, 'r') as f:
|
||||
configLines = f.readlines()
|
||||
|
||||
|
||||
changesNeeded = False
|
||||
|
||||
|
||||
# Standard controls that should be consistent
|
||||
standardControls = {
|
||||
'attack': 'Ctrl',
|
||||
'altattack': 'Alt',
|
||||
'use': 'Space',
|
||||
'turn180': 'X'
|
||||
'attack': '+attack',
|
||||
'altattack': '+altattack',
|
||||
'use': '+use',
|
||||
'crouch': '+crouch',
|
||||
'turn180': 'turn180',
|
||||
'jump': '+jump'
|
||||
}
|
||||
|
||||
|
||||
# Standard key bindings
|
||||
standardKeys = {
|
||||
'Ctrl': '+attack',
|
||||
'Alt': '+altattack',
|
||||
'Space': '+use',
|
||||
'C': '+crouch',
|
||||
'X': 'turn180',
|
||||
'J': '+jump'
|
||||
}
|
||||
|
||||
# Arrow key setup for aiming
|
||||
arrowControls = {
|
||||
'UpArrow': '+forward',
|
||||
'DownArrow': '+back',
|
||||
'LeftArrow': '+left',
|
||||
'RightArrow': '+right'
|
||||
}
|
||||
|
||||
# Accessibility controls that need to be in special sections
|
||||
tobyAccessibilityControls = {
|
||||
'E': 'pukename TurnCompass 1', # Turn compass right
|
||||
'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
|
||||
'Z': '+toby_snap_to_target_keybind' # Target snap function
|
||||
'E': 'pukename TurnCompass 1',
|
||||
'R': 'pukename TurnCompass 0',
|
||||
'Q': 'pukename CompassScript',
|
||||
';': 'netevent Toby_CheckLevelStats',
|
||||
"'": 'toby_proximity_toggle_keybind',
|
||||
'Z': '+toby_snap_to_target_keybind'
|
||||
}
|
||||
|
||||
|
||||
# Map section prefixes to their control sections
|
||||
controlSections = {}
|
||||
|
||||
|
||||
currentSection = None
|
||||
for i, line in enumerate(configLines):
|
||||
line = line.strip()
|
||||
|
||||
|
||||
# Detect section headers
|
||||
if line.startswith('[') and line.endswith(']'):
|
||||
currentSection = line[1:-1]
|
||||
|
||||
|
||||
# If this is a bindings section, extract the game prefix
|
||||
if '.Bindings' in currentSection:
|
||||
prefix = currentSection.split('.')[0] # e.g., 'Doom', 'Heretic'
|
||||
controlSections[prefix] = controlSections.get(prefix, []) + [currentSection]
|
||||
|
||||
|
||||
continue
|
||||
|
||||
# Check if we're in any Bindings section
|
||||
if currentSection and '.Bindings' in currentSection and '=' in line:
|
||||
|
||||
# Fix main bindings in each game's Bindings section
|
||||
if currentSection and currentSection.endswith('.Bindings') and not any(x in currentSection for x in ['Double', 'Automap', 'CompassMod', 'TargetSnap', 'CheckMod', 'ProximityDetector']) and '=' in line:
|
||||
key, binding = line.split('=', 1)
|
||||
key = key.strip()
|
||||
binding = binding.strip()
|
||||
|
||||
# Check if this line defines a binding we want to change
|
||||
for control, standardKey in standardControls.items():
|
||||
if binding == f"+{control}" and key != standardKey:
|
||||
# This is a binding we want to fix
|
||||
configLines[i] = f"{standardKey}=+{control}\n"
|
||||
|
||||
# Fix the turn180 command specifically (should not have + prefix)
|
||||
if binding == '+turn180':
|
||||
configLines[i] = f"{key}=turn180\n"
|
||||
changesNeeded = True
|
||||
|
||||
# Check if standard keys have correct bindings
|
||||
if key in standardKeys and binding != standardKeys[key]:
|
||||
configLines[i] = f"{key}={standardKeys[key]}\n"
|
||||
changesNeeded = True
|
||||
print(f"Fixed {key} binding to {standardKeys[key]} in {currentSection}")
|
||||
|
||||
# Remove E=+use binding (this should be in CompassMod section)
|
||||
if key == "E" and binding == "+use":
|
||||
configLines[i] = f"# {line} # Removed by Toby Launcher\n"
|
||||
changesNeeded = True
|
||||
print(f"Removed E=+use binding in {currentSection}")
|
||||
|
||||
# Fix arrow key controls
|
||||
for arrowKey, arrowBinding in arrowControls.items():
|
||||
if key == arrowKey and binding != arrowBinding:
|
||||
configLines[i] = f"{arrowKey}={arrowBinding}\n"
|
||||
changesNeeded = True
|
||||
print(f"Fixed {control} binding in {currentSection} from {key} to {standardKey}")
|
||||
|
||||
# Check for the Toby accessibility controls across all game types
|
||||
# For each game prefix, check if it has the correct CompassMod.Bindings, etc.
|
||||
print(f"Fixed {arrowKey} in {currentSection} to {arrowBinding}")
|
||||
|
||||
# Make sure all arrow key controls exist in main binding sections
|
||||
for prefix, sections in controlSections.items():
|
||||
mainBindingSection = f"{prefix}.Bindings"
|
||||
|
||||
# Find the index of the main binding section
|
||||
mainSectionIndex = -1
|
||||
for i, line in enumerate(configLines):
|
||||
if line.strip() == f"[{mainBindingSection}]":
|
||||
mainSectionIndex = i
|
||||
break
|
||||
|
||||
if mainSectionIndex == -1:
|
||||
continue # Skip if section not found
|
||||
|
||||
# Find the end of the section
|
||||
nextSectionIdx = next((j for j in range(mainSectionIndex+1, len(configLines)) if configLines[j].strip().startswith('[')), len(configLines))
|
||||
|
||||
# Check existing bindings in this section
|
||||
existingBindings = {}
|
||||
existingKeys = {}
|
||||
for i in range(mainSectionIndex+1, nextSectionIdx):
|
||||
line = configLines[i].strip()
|
||||
if '=' in line and not line.startswith('#'):
|
||||
key, binding = line.split('=', 1)
|
||||
key = key.strip()
|
||||
binding = binding.strip()
|
||||
existingBindings[binding] = key
|
||||
existingKeys[key] = binding
|
||||
|
||||
# Add missing standard key bindings
|
||||
missingKeys = []
|
||||
for key, binding in standardKeys.items():
|
||||
if key not in existingKeys:
|
||||
missingKeys.append(f"{key}={binding}\n")
|
||||
|
||||
# Add missing arrow controls
|
||||
for arrowKey, arrowBinding in arrowControls.items():
|
||||
if arrowKey not in existingKeys:
|
||||
missingKeys.append(f"{arrowKey}={arrowBinding}\n")
|
||||
|
||||
# Insert missing controls at the end of the section
|
||||
if missingKeys:
|
||||
configLines[nextSectionIdx:nextSectionIdx] = missingKeys
|
||||
changesNeeded = True
|
||||
print(f"Added missing standard controls to {mainBindingSection}")
|
||||
|
||||
# Now check for the Toby accessibility controls across all game types
|
||||
for prefix, sections in controlSections.items():
|
||||
mainBindingSection = f"{prefix}.Bindings"
|
||||
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:
|
||||
# Add this section after the main Bindings section
|
||||
@ -947,131 +1030,130 @@ class DoomLauncher(QMainWindow):
|
||||
changesNeeded = True
|
||||
print(f"Added {compassModSection} section")
|
||||
break
|
||||
|
||||
if proximitySection not in sections:
|
||||
# Need to add this section
|
||||
|
||||
# Check if ProximityDetector section needs the apostrophe key binding
|
||||
proximityFound = False
|
||||
for i, line in enumerate(configLines):
|
||||
if line.strip() == f"[{proximitySection}]":
|
||||
proximityFound = True
|
||||
|
||||
# Find the start and end of this section
|
||||
sectionStart = i
|
||||
sectionEnd = next((j for j in range(i+1, len(configLines)) if configLines[j].strip().startswith('[')), len(configLines))
|
||||
|
||||
# Check if the section has the apostrophe binding
|
||||
hasApostrophe = False
|
||||
for j in range(sectionStart+1, sectionEnd):
|
||||
if configLines[j].strip().startswith("'="):
|
||||
hasApostrophe = True
|
||||
break
|
||||
|
||||
if not hasApostrophe:
|
||||
# Add the apostrophe binding right after the section header
|
||||
configLines.insert(sectionStart+1, "'=toby_proximity_toggle_keybind\n")
|
||||
changesNeeded = True
|
||||
print(f"Added apostrophe key binding to {proximitySection}")
|
||||
|
||||
break
|
||||
|
||||
# If ProximityDetector section doesn't exist, create it
|
||||
if not proximityFound:
|
||||
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
|
||||
nextSectionIdx = next((j for j in range(i+1, len(configLines)) if configLines[j].strip().startswith('[')), len(configLines))
|
||||
# Insert the new section
|
||||
configLines.insert(nextSectionIdx, f"\n[{proximitySection}]\n")
|
||||
configLines.insert(nextSectionIdx+1, "'=toby_proximity_toggle_keybind\n\n")
|
||||
changesNeeded = True
|
||||
print(f"Added {proximitySection} section")
|
||||
print(f"Added {proximitySection} section with apostrophe key binding")
|
||||
break
|
||||
|
||||
if checkModSection 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[{checkModSection}]\n")
|
||||
configLines.insert(nextSectionIdx+1, "U=netevent Toby_CheckCoordinates\n")
|
||||
configLines.insert(nextSectionIdx+2, "H=netevent Toby_CheckHealth\n")
|
||||
configLines.insert(nextSectionIdx+3, "N=netevent Toby_CheckArmor\n")
|
||||
configLines.insert(nextSectionIdx+4, "B=netevent Toby_CheckAmmo\n")
|
||||
configLines.insert(nextSectionIdx+5, "K=netevent Toby_CheckKeys\n")
|
||||
configLines.insert(nextSectionIdx+6, "I=netevent Toby_CheckCurrentItem\n")
|
||||
configLines.insert(nextSectionIdx+7, ";=netevent Toby_CheckLevelStats\n\n")
|
||||
|
||||
# Check if TargetSnap section needs the Z key binding
|
||||
targetSnapFound = False
|
||||
for i, line in enumerate(configLines):
|
||||
if line.strip() == f"[{targetSnapSection}]":
|
||||
targetSnapFound = True
|
||||
|
||||
# Find the start and end of this section
|
||||
sectionStart = i
|
||||
sectionEnd = next((j for j in range(i+1, len(configLines)) if configLines[j].strip().startswith('[')), len(configLines))
|
||||
|
||||
# Check if the section has the Z binding
|
||||
hasZKey = False
|
||||
for j in range(sectionStart+1, sectionEnd):
|
||||
if configLines[j].strip().startswith("Z="):
|
||||
hasZKey = True
|
||||
break
|
||||
|
||||
if not hasZKey:
|
||||
# Add the Z binding right after the section header
|
||||
configLines.insert(sectionStart+1, "Z=+toby_snap_to_target_keybind\n")
|
||||
changesNeeded = True
|
||||
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
|
||||
print(f"Added Z key binding to {targetSnapSection}")
|
||||
|
||||
break
|
||||
|
||||
# If TargetSnap section doesn't exist, create it
|
||||
if not targetSnapFound:
|
||||
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
|
||||
# Insert the new 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):
|
||||
line = line.strip()
|
||||
|
||||
# Detect section headers
|
||||
if line.startswith('[') and line.endswith(']'):
|
||||
currentSection = line[1:-1]
|
||||
continue
|
||||
|
||||
# Process compass mod bindings
|
||||
if currentSection == compassModSection and '=' in line:
|
||||
key, binding = line.split('=', 1)
|
||||
key = key.strip()
|
||||
binding = binding.strip()
|
||||
|
||||
# Check E and R keys for compass functions
|
||||
if key == 'E' and binding != 'pukename TurnCompass 1':
|
||||
configLines[i] = "E=pukename TurnCompass 1\n"
|
||||
|
||||
# Check for missing bindings in sections that do exist
|
||||
if checkModSection in sections:
|
||||
# Extract all keys in the CheckMod section
|
||||
checkModStart = -1
|
||||
checkModEnd = -1
|
||||
|
||||
for i, line in enumerate(configLines):
|
||||
if line.strip() == f"[{checkModSection}]":
|
||||
checkModStart = i
|
||||
checkModEnd = next((j for j in range(i+1, len(configLines)) if configLines[j].strip().startswith('[')), len(configLines))
|
||||
break
|
||||
|
||||
if checkModStart != -1:
|
||||
# Check for semicolon and N keys
|
||||
hasNKey = False
|
||||
hasSemicolonKey = False
|
||||
|
||||
for i in range(checkModStart+1, checkModEnd):
|
||||
line = configLines[i].strip()
|
||||
if line.startswith("N="):
|
||||
hasNKey = True
|
||||
elif line.startswith(";="):
|
||||
hasSemicolonKey = True
|
||||
|
||||
# Add missing keys
|
||||
if not hasNKey:
|
||||
configLines.insert(checkModEnd-1, "N=netevent Toby_CheckArmor\n")
|
||||
changesNeeded = True
|
||||
print(f"Fixed E key in {compassModSection}")
|
||||
elif key == 'R' and binding != 'pukename TurnCompass 0':
|
||||
configLines[i] = "R=pukename TurnCompass 0\n"
|
||||
print(f"Added N key binding to {checkModSection}")
|
||||
|
||||
if not hasSemicolonKey:
|
||||
configLines.insert(checkModEnd-1, ";=netevent Toby_CheckLevelStats\n")
|
||||
changesNeeded = True
|
||||
print(f"Fixed R key in {compassModSection}")
|
||||
elif key == 'Q' and binding != 'pukename CompassScript':
|
||||
configLines[i] = "Q=pukename CompassScript\n"
|
||||
changesNeeded = True
|
||||
print(f"Fixed Q key in {compassModSection}")
|
||||
|
||||
# Process proximity detector bindings
|
||||
if currentSection == proximitySection and '=' in line:
|
||||
key, binding = line.split('=', 1)
|
||||
key = key.strip()
|
||||
binding = binding.strip()
|
||||
|
||||
# Check apostrophe key for proximity toggle
|
||||
if key == "'" and binding != 'toby_proximity_toggle_keybind':
|
||||
configLines[i] = "'=toby_proximity_toggle_keybind\n"
|
||||
changesNeeded = True
|
||||
print(f"Fixed ' key in {proximitySection}")
|
||||
|
||||
# Process check mod bindings
|
||||
if currentSection == checkModSection and '=' in line:
|
||||
key, binding = line.split('=', 1)
|
||||
key = key.strip()
|
||||
binding = binding.strip()
|
||||
|
||||
# Check semicolon key for level stats
|
||||
if key == ";" and binding != 'netevent Toby_CheckLevelStats':
|
||||
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}")
|
||||
|
||||
print(f"Added semicolon key binding to {checkModSection}")
|
||||
|
||||
# Write the config if needed
|
||||
if changesNeeded:
|
||||
with open(self.configFile, 'w') as f:
|
||||
f.writelines(configLines)
|
||||
print("Updated GZDoom configuration with standard key bindings")
|
||||
|
||||
|
||||
return changesNeeded
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error checking/fixing controls: {e}", file=sys.stderr)
|
||||
return False
|
||||
|
||||
|
||||
def generate_single_player_script(self):
|
||||
"""Generate script for single player game"""
|
||||
selectedGame = self.gameCombo.currentText()
|
||||
|
Loading…
x
Reference in New Issue
Block a user