121 lines
3.7 KiB
Python
121 lines
3.7 KiB
Python
""" Makes the configs as a massive string """
|
|
def makeCFG(cfg):
|
|
ret = ''
|
|
for key, data in cfg.items():
|
|
# I know all of these fields exist because it was verified in verify.py
|
|
bindType = firstTypeIn(data.keys())
|
|
bindContent = data[bindType]
|
|
ret += branch(key, bindContent, bindType)
|
|
|
|
return ret
|
|
|
|
def firstTypeIn(inputList):
|
|
""" Find the first element common to both lists """
|
|
types = [
|
|
"impulse",
|
|
"hold",
|
|
"toggle",
|
|
"double",
|
|
"repeat"
|
|
]
|
|
for e in types:
|
|
if e in inputList:
|
|
return e
|
|
|
|
def branch(keyName, bindContent, bindType):
|
|
if bindType == "impulse":
|
|
return impulse(keyName, bindContent)
|
|
elif bindType == "hold":
|
|
if isinstance(bindContent, str):
|
|
return simpleHold(keyName, bindContent)
|
|
else:
|
|
return listHold(keyName, bindContent)
|
|
elif bindType == "toggle":
|
|
return toggle(keyName, bindContent)
|
|
elif bindType == "double":
|
|
return double(keyName, bindContent)
|
|
elif bindType == "repeat":
|
|
return repeat(keyName, bindContent)
|
|
|
|
def impulse(key, instruction):
|
|
splitCommand = instruction.split(' ')
|
|
cmd = splitCommand[0]
|
|
shortcuts = {
|
|
"primary": "slot1",
|
|
"secondary": "slot2",
|
|
"melee": "slot3"
|
|
}
|
|
if cmd in shortcuts:
|
|
for sc, expansion in shortcuts.items():
|
|
if cmd == shortcut:
|
|
splitCommand[0] = expansion
|
|
break
|
|
instruction = ' '.join(splitCommand)
|
|
|
|
|
|
restOfCmd = ' '.join(splitCommand[1:])
|
|
if cmd == "voice":
|
|
instruction = voice(restOfCmd)
|
|
|
|
elif cmd == "build":
|
|
instruction = "build "+expandBuildings(restOfCmd)
|
|
|
|
elif cmd == "destroy":
|
|
instruction = "destroy "+expandBuildings(restOfCmd)
|
|
|
|
return f'bind {key} {instruction}\n'
|
|
|
|
def voice(keyword):
|
|
keyword = keyword.lower()
|
|
|
|
allLists = [
|
|
["medic", "thanks", "go", "move up", "go left", "go right", "yes", "no", "pass to me"],
|
|
["incoming", "spy", "sentry ahead", "teleporter here", "dispenser here", "sentry here", "uber (ask)", "uber (ready)"],
|
|
["help", "battle cry", "cheers", "jeers", "positive", "negative", "nice shot", "good job"]
|
|
]
|
|
|
|
for menu, voiceList in enumerate(allLists):
|
|
for selection, shortcut in enumerate(voiceList):
|
|
if keyword == shortcut:
|
|
return f'voicemenu {menu} {selection}'
|
|
|
|
def expandBuildings(building):
|
|
buildingNums = {
|
|
"dispenser": "0 0",
|
|
"entrance": "1 0",
|
|
"exit": "1 1",
|
|
"sentry": "2 0"
|
|
}
|
|
for shortBuild, num in buildingNums.items():
|
|
if building == shortBuild:
|
|
return num
|
|
|
|
def simpleHold(key, instruction):
|
|
# This isn't quite right, fix later!
|
|
if instruction[0] != '+':
|
|
return f'bind {key} +{instruction}\n'
|
|
else:
|
|
return f'bind {key} {instruction}\n'
|
|
# return f'placeholder for {key} (single instruction hold)\n'
|
|
|
|
def listHold(key, options):
|
|
ret = f'alias +{key}_bind {options["press"]}\n'
|
|
ret += f'alias -{key}_bind {options["release"]}\n'
|
|
ret += f'bind {key} +{key}_bind\n'
|
|
return ret
|
|
# return f'placeholder for {key} (press-and-release hold)\n'
|
|
|
|
def toggle(key, instruction):
|
|
ret = f'alias turn_{key}_on "+{instruction}; alias toggle_{key} turn_key_off"\n'
|
|
ret += f'alias turn_{key}_off "-{instruction}; alias toggle_{key} turn_ley_on"\n'
|
|
ret += f'alias toggle_{key} turn_{key}_on\n'
|
|
ret += f'bind {key} toggle_{key}\n'
|
|
return ret
|
|
# return f'placeholder for {key} (toggle)\n'
|
|
|
|
def double(key, options):
|
|
return f'placeholder for {key} (double)\n'
|
|
|
|
def repeat(key, options):
|
|
return f'placeholder for {key} (repeat)\n'
|