All verification done, impulse.toTF2() done
parent
80a1379f49
commit
8bf19e6153
|
@ -33,6 +33,7 @@ class bind:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, key, fields):
|
def __init__(self, key, fields):
|
||||||
|
self.alias = False
|
||||||
self.key = key
|
self.key = key
|
||||||
self.fields = fields
|
self.fields = fields
|
||||||
self.errors = []
|
self.errors = []
|
||||||
|
@ -67,14 +68,14 @@ class bind:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
isalias = self.fields.pop('alias')
|
self.alias = self.fields.pop('alias')
|
||||||
if not isinstance(isalias, bool):
|
if not isinstance(self.alias, bool):
|
||||||
self.errors.append(f'alias should be yes or no, not "{isalias}"')
|
self.errors.append(f'alias should be yes or no, not "{self.alias}"')
|
||||||
isalias = False
|
self.alias = False
|
||||||
except (KeyError, AttributeError, TypeError):
|
except (KeyError, AttributeError, TypeError):
|
||||||
isalias = False
|
self.alias = False
|
||||||
|
|
||||||
if (not isalias) and (self.key not in validKeyList):
|
if (not self.alias) and (self.key not in validKeyList):
|
||||||
self.errors.append(f'invalid key name: "{self.key}"')
|
self.errors.append(f'invalid key name: "{self.key}"')
|
||||||
|
|
||||||
types = {
|
types = {
|
||||||
|
@ -112,15 +113,92 @@ class impulse(bind):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.command = self.fields.pop('command')
|
self.command = self.fields.pop('command')
|
||||||
if not isinstance(self.command, (str, list)):
|
|
||||||
self.err('command must be string or list')
|
|
||||||
self.command = None
|
|
||||||
except (KeyError, AttributeError, TypeError):
|
except (KeyError, AttributeError, TypeError):
|
||||||
self.fields = {'command': self.fields}
|
self.fields = {'command': self.fields}
|
||||||
self.command = self.fields.pop('command')
|
self.command = self.fields.pop('command')
|
||||||
if not isinstance(self.command, (str, list)):
|
|
||||||
self.err('must be command or argument of string or list')
|
if isinstance(self.command, str):
|
||||||
self.command = None
|
self.command = self.command.split(';')
|
||||||
|
|
||||||
|
elif not isinstance(self.command, list):
|
||||||
|
self.err('must be command or argument of string or list')
|
||||||
|
self.command = None
|
||||||
|
|
||||||
|
def toTF2(self) -> str:
|
||||||
|
if self.alias:
|
||||||
|
bindOrAlias = 'alias'
|
||||||
|
else:
|
||||||
|
bindOrAlias = 'bind'
|
||||||
|
|
||||||
|
allInstructions = self.shortcut(self.command)
|
||||||
|
instruction = ';'.join(allInstructions)
|
||||||
|
|
||||||
|
return f'{bindOrAlias} {self.key} "{instruction}"\n'
|
||||||
|
|
||||||
|
def shortcut(self, instList):
|
||||||
|
for i, instruction in enumerate(instList):
|
||||||
|
try:
|
||||||
|
cmd, restOfCmd = instruction.split(' ', 1)
|
||||||
|
except ValueError:
|
||||||
|
# no spaces in cmd
|
||||||
|
cmd, restOfCmd = instruction, ''
|
||||||
|
|
||||||
|
simpleSCs = {
|
||||||
|
"primary": "slot1",
|
||||||
|
"secondary": "slot2",
|
||||||
|
"melee": "slot3"
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
cmd = simpleSCs[cmd]
|
||||||
|
except KeyError:
|
||||||
|
# not a shortcut
|
||||||
|
pass
|
||||||
|
|
||||||
|
if cmd == "voice":
|
||||||
|
cmd = "voicemenu"
|
||||||
|
restOfCmd = self.expandVoice(restOfCmd)
|
||||||
|
|
||||||
|
elif cmd == "build" or cmd == "destroy":
|
||||||
|
restOfCmd = self.expandBuildings(restOfCmd)
|
||||||
|
|
||||||
|
elif cmd == "load_itempreset" and restOfCmd.isalpha():
|
||||||
|
try:
|
||||||
|
restOfCmd = restOfCmd.lower()
|
||||||
|
restOfCmd = ['a','b','c','d'].index(restOfCmd)
|
||||||
|
except ValueError:
|
||||||
|
# not a load_itempreset shortcut
|
||||||
|
pass
|
||||||
|
|
||||||
|
if restOfCmd != "":
|
||||||
|
cmd += ' ' + restOfCmd
|
||||||
|
instList[i] = cmd
|
||||||
|
|
||||||
|
return instList
|
||||||
|
|
||||||
|
def expandVoice(self, keyword):
|
||||||
|
keyword = keyword.lower()
|
||||||
|
|
||||||
|
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", "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:
|
||||||
|
return f'{menu} {selection}'
|
||||||
|
|
||||||
|
def expandBuildings(self, building):
|
||||||
|
buildingNums = {
|
||||||
|
"dispenser": "0 0",
|
||||||
|
"entrance": "1 0",
|
||||||
|
"exit": "1 1",
|
||||||
|
"sentry": "2 0"
|
||||||
|
}
|
||||||
|
for shortBuild, num in buildingNums.items():
|
||||||
|
if building == shortBuild:
|
||||||
|
return num
|
||||||
|
|
||||||
|
|
||||||
class hold(bind):
|
class hold(bind):
|
||||||
|
|
Loading…
Reference in New Issue