Added new syntax for impulse
parent
1ca30fe589
commit
31c0d41e83
26
tfscript.py
26
tfscript.py
|
@ -37,19 +37,36 @@ def firstTypeIn(inputList):
|
|||
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):
|
||||
if isinstance(instruction, list):
|
||||
instruction = ';'.join(instruction)
|
||||
|
||||
allInstructions = []
|
||||
|
||||
for indivCmd in instruction.split(';'):
|
||||
allInstructions.append(impulseShortcuts(indivCmd))
|
||||
|
||||
instruction = ';'.join(allInstructions)
|
||||
|
||||
return f'bind {key} "{instruction}"\n'
|
||||
|
||||
def impulseShortcuts(instruction):
|
||||
splitCommand = instruction.split(' ')
|
||||
cmd = splitCommand[0]
|
||||
shortcuts = {
|
||||
|
@ -64,15 +81,14 @@ def impulse(key, instruction):
|
|||
break
|
||||
instruction = ' '.join(splitCommand)
|
||||
|
||||
|
||||
restOfCmd = ' '.join(splitCommand[1:])
|
||||
if cmd == "voice":
|
||||
instruction = voice(restOfCmd)
|
||||
|
||||
elif cmd == "build" or cmd == "destroy":
|
||||
instruction = f"{cmd} " + expandBuildings(restOfCmd)
|
||||
|
||||
return f'bind {key} "{instruction}"\n'
|
||||
|
||||
return instruction
|
||||
|
||||
def voice(keyword):
|
||||
keyword = keyword.lower()
|
||||
|
@ -138,7 +154,7 @@ def double(key, options):
|
|||
|
||||
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",
|
||||
|
@ -154,7 +170,7 @@ def double(key, options):
|
|||
# Almost always because it is a double quote
|
||||
llist[i] = llist[i][0] + 'alias'
|
||||
newcode.append(' '.join(llist))
|
||||
|
||||
|
||||
ret = '\n'.join(newcode) +\
|
||||
f'alias +{tog_str} "bind {key} {alt_str}"\n' +\
|
||||
f'alias -{tog_str} "bind {key} {main_str}"\n'+\
|
||||
|
|
Loading…
Reference in New Issue