diff --git a/examples/nicks_config.yaml b/examples/nicks_config.yaml index e56de61..fc2afde 100644 --- a/examples/nicks_config.yaml +++ b/examples/nicks_config.yaml @@ -89,6 +89,11 @@ default: - "-moveright" - "maybe_move_left" - "unalias maybe_move_right" + + # both do something different for engi + bind mouse5: +jump + bind 4: slot4 + # This just stops an error message the first time you release # either of 'a' or 'd' impulse maybe_move_left: @@ -134,6 +139,28 @@ engi: press: - destroy sentry - build sentry + double 4: + type: double + condition: mouse4 + + primary: + type: impulse + condition: mouse5 + primary: + - destroy dispenser + - build dispenser + secondary: + - destroy exit + - build exit + secondary: + type: impulse + condition: mouse5 + primary: + - destroy entrance + - build entrance + secondary: + - destroy entrance + - build entrance medic: # "Radar" feature: causes all teammates to autocall for medic, allowing @@ -147,21 +174,3 @@ medic: condition: mouse4 primary: voice medic secondary: voice uber ready - -soldier: - double mouse1: - type: hold - condition: mouse4 - cancel: both - # normal firing - primary: +attack - # rocket jump - secondary: - press: - - +attack - - +duck - - +jump - release: - - -attack - - -duck - - -jump diff --git a/tfscript/tftypes.py b/tfscript/tftypes.py index e4b8fd4..79e2fc0 100644 --- a/tfscript/tftypes.py +++ b/tfscript/tftypes.py @@ -20,7 +20,7 @@ validKeyList = [ popErrors = (AttributeError, KeyError, TypeError) -class Bind(object): +class ScriptBind(object): ''' Parent class for all bind types. Verifies key, creates local variables @@ -47,7 +47,7 @@ class Bind(object): # and some other universal fields like alias and finds targetType self.verify() - if type(self) is Bind: + if type(self) is ScriptBind: # not using isinstance(), because all subclasses are also instances # of bind. return @@ -137,7 +137,7 @@ class Bind(object): ) -class Impulse(Bind): +class Impulse(ScriptBind): def verify(self): self.command: list = None if not isinstance(self.fields, dict): @@ -231,7 +231,7 @@ class Impulse(Bind): return buildingNums.get(building, building) -class Hold(Bind): +class Hold(ScriptBind): def verify(self): self.press: list = None self.release: list = None @@ -293,7 +293,7 @@ class Hold(Bind): return code -class Toggle(Bind): +class Toggle(ScriptBind): def verify(self): self.on : list = None self.off: list = None @@ -349,7 +349,7 @@ class Toggle(Bind): ) -class Double(Bind): +class Double(ScriptBind): defaultDict = {} condDict = {} bindNames = [] @@ -360,8 +360,8 @@ class Double(Bind): self.isToggle = False self.cancelBoth = False - self.primary: Bind = None - self.secondary: Bind = None + self.primary: ScriptBind = None + self.secondary: ScriptBind = None self.condition: str = None self.type: str = None @@ -427,9 +427,9 @@ class Double(Bind): if self.primary is self.secondary is None: self.err('has neither primary nor secondary') - def getSection(self, popName, key, /) -> Bind: + def getSection(self, popName, key, /) -> ScriptBind: section = self.fields.pop(popName) - bind = Bind(f'{self.type} {key}', section) + bind = ScriptBind(f'{self.type} {key}', section) bind = bind.toTargetType() bind.errors.remove(f'invalid key name: "{key}"') @@ -543,7 +543,7 @@ class Double(Bind): ) -class Repeat(Bind): +class Repeat(ScriptBind): def verify(self): self.interval = None self.command = None @@ -573,7 +573,7 @@ class Repeat(Bind): return f'// repeat {self.key}\n' -class Literal(Bind): +class Literal(ScriptBind): def verify(self): self.text = '' self.run = False @@ -617,8 +617,23 @@ class Literal(Bind): result += f'\n{self.key}' return result + '\n' + +class Bind(ScriptBind): + def verify(self): + # just set self.text, and if it's not a string, make an error + self.text = self.fields + if isinstance(self.text, str): + # clear self.fields to assure no "extra field" warnings + self.fields = {} + else: + # not passed string ==> error + self.err('argument must be a string') + + def toTF2(self) -> str: + return f'bind {self.key} {self.text}\n' + # This is at the bottom because it has to happen after # all inheritances have been completed -Bind.bindTypes = Bind.__subclasses__() -Double.bindNames = [ bind.__name__.lower() for bind in Bind.bindTypes ] \ No newline at end of file +ScriptBind.bindTypes = ScriptBind.__subclasses__() +Double.bindNames = [ bind.__name__.lower() for bind in ScriptBind.bindTypes ] \ No newline at end of file diff --git a/tfscript/verify.py b/tfscript/verify.py index aabfc43..7b76e80 100644 --- a/tfscript/verify.py +++ b/tfscript/verify.py @@ -47,7 +47,7 @@ def verifyConfig(cfg: dict) -> (dict, dict): errMessages = [] warnMessages = [] for key, data in classCFG.items(): - bind = tftypes.Bind(key, data) + bind = tftypes.ScriptBind(key, data) bind = bind.toTargetType() if isclass: