From 31c0d41e8330d9f37ca8c223e570c68f4e6d8a2e Mon Sep 17 00:00:00 2001 From: Nicholas Hope Date: Sat, 6 Aug 2022 15:05:36 -0400 Subject: [PATCH] Added new syntax for impulse --- tfscript.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tfscript.py b/tfscript.py index ade26a6..3dbdb3f 100644 --- a/tfscript.py +++ b/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'+\