Better verification, works with new tfscript file
parent
faa6f4a3bf
commit
398c80b760
44
verify.py
44
verify.py
|
@ -36,12 +36,14 @@ def validBind(key, data, alias = False) -> list:
|
|||
if (not alias and not validKey(key)):
|
||||
ret.append(f'Invalid key "{key}"')
|
||||
|
||||
data, errMsgs = validBindType(key, data)
|
||||
# The values passed to validBindType get mutilated, so a copy must be made
|
||||
dataCopy = data.copy()
|
||||
dataCopy, errMsgs = validBindType(key, dataCopy)
|
||||
if len(errMsgs) > 0:
|
||||
for msg in errMsgs:
|
||||
ret.append(msg)
|
||||
|
||||
extras = data.keys()
|
||||
extras = dataCopy.keys()
|
||||
if len(extras) > 0:
|
||||
extrasString = "\n\t".join(extras)
|
||||
ret.append(f'Unused fields in "{key}":\n\t{extrasString}')
|
||||
|
@ -91,8 +93,18 @@ def validBindType(key, data: dict):
|
|||
def removeRelaventFields(data, bindType):
|
||||
errMsgs = []
|
||||
# These types are simple, just the bind type and argument
|
||||
if bindType in ["impulse", "hold", "toggle"]:
|
||||
if bindType in ["impulse", "toggle"]:
|
||||
data.pop(bindType)
|
||||
|
||||
elif bindType == "hold":
|
||||
content = data.pop("hold")
|
||||
if isinstance(content, dict):
|
||||
if "press" not in content:
|
||||
errMsgs.append("If hold is not a single argument, it requires a `press` argument")
|
||||
elif "release" not in content:
|
||||
errMsgs.append("If hold is not a single argument, it requires a `release` argument")
|
||||
elif not isinstance(content, str):
|
||||
errMsgs.append(f"Hold must be either single action or press and release")
|
||||
|
||||
elif bindType == "double":
|
||||
content = data.pop("double")
|
||||
|
@ -105,7 +117,7 @@ def removeRelaventFields(data, bindType):
|
|||
errMessages = validBind("primary", content["primary"], alias = True)
|
||||
if len(errMessages) > 0:
|
||||
errMsgs += errMessages
|
||||
|
||||
|
||||
if "secondary" not in content:
|
||||
errMsgs.append("Double requires secondary action")
|
||||
else:
|
||||
|
@ -113,13 +125,33 @@ def removeRelaventFields(data, bindType):
|
|||
errMessages = validBind("secondary", content["secondary"], alias = True)
|
||||
if len(errMessages) > 0:
|
||||
errMsgs += errMessages
|
||||
|
||||
|
||||
if "condition" not in content:
|
||||
errMsgs.append("Double requires condition to toggle")
|
||||
else:
|
||||
# Validate the toggler
|
||||
key = content["condition"]
|
||||
if not validKey(key):
|
||||
errMsgs.append(f'Invalid key "{key}"')
|
||||
errMsgs.append(f'Invalid condition to toggle "{key}"')
|
||||
|
||||
elif bindType == "repeat":
|
||||
content = data.pop("repeat")
|
||||
|
||||
unit = "s"
|
||||
if "unit" in content:
|
||||
# Set unit if provided
|
||||
unitStr = str(content["unit"]).lower()
|
||||
if unitStr in ["t", "ticks"]:
|
||||
unit = "t"
|
||||
elif unitStr not in ["s", "seconds"]:
|
||||
# If not seconds or ticks, error
|
||||
errMsgs.append(f"Invalid interval unit {unitStr}")
|
||||
|
||||
if "interval" not in content:
|
||||
errMsgs.append("Repeat requires interval")
|
||||
else:
|
||||
interval = content["interval"]
|
||||
if unit == "t" and isinstance(interval, float):
|
||||
errMsgs.append("Repeat interval must be integer if unit is ticks")
|
||||
|
||||
return data, errMsgs
|
||||
|
|
Loading…
Reference in New Issue