Compare commits

...

3 Commits

Author SHA1 Message Date
Nicholas Hope 8bf19e6153 All verification done, impulse.toTF2() done 2022-09-04 09:26:57 -04:00
Nicholas Hope 80a1379f49 changed some variable names 2022-09-04 09:26:22 -04:00
Nicholas Hope bacc858826 removed repeated code 2022-09-04 09:25:33 -04:00
3 changed files with 111 additions and 31 deletions

View File

@ -61,15 +61,15 @@ def parseConfig(config, defaults):
tempsAndReals = {}
if defaults is not None:
stringToWrite = tfscript.makeCFG(defaults, default=True)
# replaceDict = writing.writeOutput(stringToWrite, 'default', args)
# tempsAndReals.update(replaceDict)
config.update({'default': defaults})
for currentClass in config:
classDict = config[currentClass]
stringToWrite = tfscript.makeCFG(classDict)
# replaceDict = writing.writeOutput(stringToWrite, currentClass, args)
# tempsAndReals.update(replaceDict)
bindList = config[currentClass]
stringToWrite = ''
for bind in bindList:
stringToWrite += bind.toTF2()
replaceDict = writing.writeOutput(stringToWrite, currentClass, args)
tempsAndReals.update(replaceDict)
return tempsAndReals

View File

@ -33,6 +33,7 @@ class bind:
'''
def __init__(self, key, fields):
self.alias = False
self.key = key
self.fields = fields
self.errors = []
@ -67,14 +68,14 @@ class bind:
return
try:
isalias = self.fields.pop('alias')
if not isinstance(isalias, bool):
self.errors.append(f'alias should be yes or no, not "{isalias}"')
isalias = False
self.alias = self.fields.pop('alias')
if not isinstance(self.alias, bool):
self.errors.append(f'alias should be yes or no, not "{self.alias}"')
self.alias = False
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}"')
types = {
@ -112,15 +113,92 @@ class impulse(bind):
try:
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):
self.fields = {'command': self.fields}
self.command = self.fields.pop('command')
if not isinstance(self.command, (str, list)):
self.err('must be command or argument of string or list')
self.command = None
if isinstance(self.command, str):
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):

View File

@ -5,9 +5,9 @@ from tfscript import tftypes
def verifyConfig(cfg: dict) -> (dict, dict):
verifiedConfig = {}
# Do defaults first
errors = {}
# Do defaults first
defaults = []
classList = [
@ -23,20 +23,22 @@ def verifyConfig(cfg: dict) -> (dict, dict):
'spy'
]
for isclass, cclass in enumerate(classList):
for isclass, class_ in enumerate(classList):
classCFG = None
classBinds = []
className = cclass
className = class_
if isinstance(cclass, str) and cclass in cfg:
classCFG = cfg.pop(cclass)
elif isinstance(cclass, tuple):
for tupClass in cclass:
if isinstance(class_, str) and class_ in cfg:
classCFG = cfg.pop(class_)
elif isinstance(class_, tuple):
for tupClass in class_:
if tupClass in cfg:
classCFG = cfg.pop(tupClass)
className = cclass[0]
className = class_[0]
break
if classCFG is None:
# Invalid class, this gets caught later.
# It may be less efficient this way, but
@ -61,10 +63,10 @@ def verifyConfig(cfg: dict) -> (dict, dict):
verifiedConfig.update({className: classBinds})
# Turn list into only strings by expanding tuples
for i, cclass in enumerate(classList):
if isinstance(cclass, tuple):
classList.insert(i+1, cclass[1])
classList.insert(i+1, cclass[0])
for i, class_ in enumerate(classList):
if isinstance(class_, tuple):
classList.insert(i+1, class_[1])
classList.insert(i+1, class_[0])
classList.pop(i)
globalErrors = []