More code for nested doubles
parent
56441229c9
commit
1e3093ec58
56
tfscript.py
56
tfscript.py
|
@ -4,6 +4,7 @@
|
||||||
condDict = {}
|
condDict = {}
|
||||||
|
|
||||||
def makeCFG(cfg):
|
def makeCFG(cfg):
|
||||||
|
condDict.clear()
|
||||||
ret = ''
|
ret = ''
|
||||||
for key, data in cfg.items():
|
for key, data in cfg.items():
|
||||||
# I know all of these fields exist because it was verified in verify.py
|
# 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():
|
for key, toggles in condDict.items():
|
||||||
ret += f'alias +{key}_toggles "{toggles["plus_toggles"]}"\n' +\
|
ret += f'alias +{key}_toggles "{toggles["plus_toggles"]}"\n' +\
|
||||||
f'alias -{key}_toggles "{toggles["minus_toggles"]}"\n' +\
|
f'alias -{key}_toggles "{toggles["minus_toggles"]}"\n' +\
|
||||||
f'bind {key} +{key}_toggles\n'
|
f'bind {key} "+{key}_toggles"\n'
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -69,9 +70,9 @@ def impulse(key, instruction):
|
||||||
instruction = voice(restOfCmd)
|
instruction = voice(restOfCmd)
|
||||||
|
|
||||||
elif cmd == "build" or cmd == "destroy":
|
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):
|
def voice(keyword):
|
||||||
keyword = keyword.lower()
|
keyword = keyword.lower()
|
||||||
|
@ -100,15 +101,18 @@ def expandBuildings(building):
|
||||||
|
|
||||||
def simpleHold(key, instruction):
|
def simpleHold(key, instruction):
|
||||||
# This isn't quite right, fix later!
|
# This isn't quite right, fix later!
|
||||||
|
ret = '// simple hold\n'
|
||||||
if instruction[0] != '+':
|
if instruction[0] != '+':
|
||||||
return f'bind {key} +{instruction}\n'
|
ret += f'bind {key} "+{instruction}"\n'
|
||||||
else:
|
else:
|
||||||
return f'bind {key} {instruction}\n'
|
ret += f'bind {key} "{instruction}"\n'
|
||||||
|
return ret
|
||||||
|
|
||||||
def listHold(key, options):
|
def listHold(key, options):
|
||||||
ret = f'alias +{key}_bind {options["press"]}\n' +\
|
ret = '// list hold\n' +\
|
||||||
f'alias -{key}_bind {options["release"]}\n' +\
|
f'alias +{key}_bind "{options["press"]}"\n' +\
|
||||||
f'bind {key} +{key}_bind\n'
|
f'alias -{key}_bind "{options["release"]}"\n' +\
|
||||||
|
f'bind {key} "+{key}_bind"\n'
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def toggle(key, instruction):
|
def toggle(key, instruction):
|
||||||
|
@ -116,10 +120,11 @@ def toggle(key, instruction):
|
||||||
offStr = f'turn_{key}_off'
|
offStr = f'turn_{key}_off'
|
||||||
togStr = f'toggle_{key}'
|
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 {offStr} "-{instruction}; alias {togStr} {onStr}"\n' +\
|
||||||
f'alias {togStr} {onStr}\n' +\
|
f'alias {togStr} "{onStr}"\n' +\
|
||||||
f'bind {key} {togStr}\n'
|
f'bind {key} "{togStr}"\n'
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def double(key, options):
|
def double(key, options):
|
||||||
|
@ -135,17 +140,40 @@ def double(key, options):
|
||||||
alt_str = f'{key}_alt'
|
alt_str = f'{key}_alt'
|
||||||
tog_str = f'toggle_{key}'
|
tog_str = f'toggle_{key}'
|
||||||
|
|
||||||
ret = branch(main_str, pBindContent, pBindType) +\
|
recursive_code = branch(main_str, pBindContent, pBindType) +\
|
||||||
branch(alt_str, sBindContent, sBindType) +\
|
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} {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"]
|
cond_name = options["condition"]
|
||||||
|
|
||||||
if cond_name in condDict:
|
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]["plus_toggles"] += f"; +{tog_str}"
|
||||||
condDict[cond_name]["minus_toggles"] += f"; -{tog_str}"
|
condDict[cond_name]["minus_toggles"] += f"; -{tog_str}"
|
||||||
else:
|
else:
|
||||||
|
# If the condition key doesn't already exist, make it with the correct values
|
||||||
condDict.update( {
|
condDict.update( {
|
||||||
cond_name: {
|
cond_name: {
|
||||||
"plus_toggles": f"+{tog_str}",
|
"plus_toggles": f"+{tog_str}",
|
||||||
|
|
Loading…
Reference in New Issue