Added code for the double type

pull/11/head
Nicholas Hope 2022-08-02 13:47:35 -04:00
parent 26d4d6f2be
commit 49a23ba3e5
2 changed files with 66 additions and 26 deletions

6
cli.py
View File

@ -32,7 +32,8 @@ def parseConfig(config):
if os.path.isdir( prefix ) == False:
try:
os.mkdir( prefix )
args.debug and print( f'DEBUG: created {prefix}')
if args.debug:
print( f'DEBUG: created {prefix}')
except Exception as fileExcept:
print( f'WARN: Failed to create {prefix}: {fileExcept.strerror}\nUsing current directory instead.' )
prefix = '.'
@ -47,7 +48,8 @@ def parseConfig(config):
outfile.write(stringToWrite.encode("utf8"))
os.replace(outfile.name, f'{prefix}/{currentClass}_nscript.txt')
args.debug and print( f'DEBUG: Created {prefix}/{currentClass}_nscript.txt')
if args.debug:
print( f'DEBUG: Created {prefix}/{currentClass}_nscript.txt')
outfile.close()
# Main function

View File

@ -1,4 +1,7 @@
""" Makes the configs as a massive string """
condDict = {}
def makeCFG(cfg):
ret = ''
for key, data in cfg.items():
@ -7,6 +10,13 @@ def makeCFG(cfg):
bindContent = data[bindType]
ret += branch(key, bindContent, bindType)
# Doubles are weird. All of the toggles got put into a dictionary.
# This takes all of the nested dictionaries and turns them into the right string
for key, toggles in condDict.items():
ret += f'alias +{key}_toggles \"{toggles["plus_toggles"]}\"\n' +\
f'alias -{key}_toggles \"{toggles["minus_toggles"]}\"\n' +\
f'bind {key} +{key}_toggles\n'
return ret
def firstTypeIn(inputList):
@ -18,9 +28,9 @@ def firstTypeIn(inputList):
"double",
"repeat"
]
for e in types:
if e in inputList:
return e
for t in types:
if t in inputList:
return t
def branch(keyName, bindContent, bindType):
if bindType == "impulse":
@ -51,18 +61,15 @@ def impulse(key, instruction):
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)
elif cmd == "build" or cmd == "destroy":
instruction = f"{cmd} "+expandBuildings(restOfCmd)
return f'bind {key} {instruction}\n'
def voice(keyword):
@ -70,10 +77,10 @@ def voice(keyword):
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)"],
["incoming", "spy", "sentry ahead", "teleporter here", "dispenser here", "sentry here", "activate uber", "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:
@ -96,25 +103,56 @@ def simpleHold(key, instruction):
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'
ret = f'alias +{key}_bind {options["press"]}\n' +\
f'alias -{key}_bind {options["release"]}\n' +\
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'
onStr = f'turn_{key}_on'
offStr = f'turn_{key}_off'
togStr = f'toggle_{key}'
ret = f'alias {onStr} "+{instruction}; alias {togStr} {offStr}"\n' +\
f'alias {offStr} "-{instruction}; alias {togStr} {onStr}"\n' +\
f'alias {togStr} {onStr}\n' +\
f'bind {key} {togStr}\n'
return ret
# return f'placeholder for {key} (toggle)\n'
def double(key, options):
return f'placeholder for {key} (double)\n'
prim_action = options["primary"]
pBindType = firstTypeIn(prim_action.keys())
pBindContent = prim_action[pBindType]
sec_action = options["secondary"]
sBindType = firstTypeIn(sec_action.keys())
sBindContent = sec_action[sBindType]
main_str = f'{key}_main'
alt_str = f'{key}_alt'
tog_str = f'toggle_{key}'
ret = branch(main_str, pBindContent, pBindType) +\
branch(alt_str, sBindContent, sBindType) +\
f'alias +{tog_str} \"bind {key} {alt_str}\"\n' +\
f'alias -{tog_str} \"bind {key} {main_str}\"\n'
cond_name = options["condition"]
if cond_name in condDict:
condDict[cond_name]["plus_toggles"] += f"; +{tog_str}"
condDict[cond_name]["minus_toggles"] += f"; -{tog_str}"
else:
condDict.update( {
cond_name: {
"plus_toggles": f"+{tog_str}",
"minus_toggles": f"-{tog_str}"
}
} )
return ret
def repeat(key, options):
return f'placeholder for {key} (repeat)\n'