More code for nested doubles

pull/11/head
Nicholas Hope 2022-08-04 15:14:13 -04:00
parent 56441229c9
commit 1e3093ec58
1 changed files with 42 additions and 14 deletions

View File

@ -4,6 +4,7 @@
condDict = {}
def makeCFG(cfg):
condDict.clear()
ret = ''
for key, data in cfg.items():
# I know all of these fields exist because it was verified in verify.py
@ -16,7 +17,7 @@ def makeCFG(cfg):
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'
f'bind {key} "+{key}_toggles"\n'
return ret
@ -69,9 +70,9 @@ def impulse(key, instruction):
instruction = voice(restOfCmd)
elif cmd == "build" or cmd == "destroy":
instruction = f"{cmd} "+expandBuildings(restOfCmd)
instruction = f"{cmd} " + expandBuildings(restOfCmd)
return f'bind {key} "{instruction}"\n'
return f'// impulse\nbind {key} "{instruction}"\n'
def voice(keyword):
keyword = keyword.lower()
@ -100,15 +101,18 @@ def expandBuildings(building):
def simpleHold(key, instruction):
# This isn't quite right, fix later!
ret = '// simple hold\n'
if instruction[0] != '+':
return f'bind {key} +{instruction}\n'
ret += f'bind {key} "+{instruction}"\n'
else:
return f'bind {key} {instruction}\n'
ret += f'bind {key} "{instruction}"\n'
return ret
def listHold(key, options):
ret = f'alias +{key}_bind {options["press"]}\n' +\
f'alias -{key}_bind {options["release"]}\n' +\
f'bind {key} +{key}_bind\n'
ret = '// list hold\n' +\
f'alias +{key}_bind "{options["press"]}"\n' +\
f'alias -{key}_bind "{options["release"]}"\n' +\
f'bind {key} "+{key}_bind"\n'
return ret
def toggle(key, instruction):
@ -116,10 +120,11 @@ def toggle(key, instruction):
offStr = f'turn_{key}_off'
togStr = f'toggle_{key}'
ret = f'alias {onStr} "+{instruction}; alias {togStr} {offStr}"\n' +\
ret = '// toggle\n'+\
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'
f'alias {togStr} "{onStr}"\n' +\
f'bind {key} "{togStr}"\n'
return ret
def double(key, options):
@ -135,17 +140,40 @@ def double(key, options):
alt_str = f'{key}_alt'
tog_str = f'toggle_{key}'
ret = branch(main_str, pBindContent, pBindType) +\
branch(alt_str, sBindContent, sBindType) +\
recursive_code = branch(main_str, pBindContent, pBindType) +\
branch(alt_str, sBindContent, sBindType)
newcode = []
for line in recursive_code.split('\n'):
# For every line gotten by the recursive call, change all "bind"s to "alias",
# since main_str and alt_str aren't valid bind targes
llist = line.split(' ')
for i in range(len(llist)):
alphanum_chars = ''.join(c for c in llist[i] if c.isalnum())
if alphanum_chars == 'bind':
if llist[i][0].isalnum():
llist[i] = 'alias'
else:
# If the first character isn't a normal character.
# Almost always because it is a double quote
llist[i] = llist[i][0] + 'alias'
newcode.append(' '.join(llist))
ret = '// double\n' +\
'\n'.join(newcode) +\
f'alias +{tog_str} "bind {key} {alt_str}"\n' +\
f'alias -{tog_str} "bind {key} {main_str}"\n'
f'alias -{tog_str} "bind {key} {main_str}"\n'+\
f'bind {key} "{main_str}"\n'
cond_name = options["condition"]
if cond_name in condDict:
# If the condition key (like "mouse4") already has toggles,
# just append another toggle string (it gets encased in quotes later)
condDict[cond_name]["plus_toggles"] += f"; +{tog_str}"
condDict[cond_name]["minus_toggles"] += f"; -{tog_str}"
else:
# If the condition key doesn't already exist, make it with the correct values
condDict.update( {
cond_name: {
"plus_toggles": f"+{tog_str}",