Compare commits

...

2 Commits

Author SHA1 Message Date
Nicholas Hope ace0af7101 ignore 2022-09-17 22:17:42 -04:00
Nicholas Hope 4babdedb81 cancel: both works, fixed swapped var names 2022-09-17 22:17:34 -04:00
2 changed files with 93 additions and 66 deletions

View File

@ -9,51 +9,50 @@
default:
# voice-based doubles
double e:
impulse primary: voice medic
impulse secondary: voice activate uber
type: impulse
primary: voice medic
secondary: voice activate uber
condition: mouse4
double t:
impulse primary: voice thanks
impulse secondary: voice nice shot
type: impulse
primary: voice thanks
secondary: voice nice shot
condition: mouse4
double v:
impulse primary: voice spy
impulse secondary: voice help
type: impulse
primary: voice spy
secondary: voice help
condition: mouse4
# hold doubles
double r:
primary:
hold: "class_action"
secondary:
hold: "reload"
type: hold
primary: +class_action
secondary: +reload
condition: mouse4
cancel both: yes
cancel: both
# other
double =:
primary:
impulse: kill
secondary:
impulse: explode
condition: "-"
impulse =: kill
impulse -: explode
double q:
impulse primary: lastinv
impulse secondary:
type: impulse
primary: lastinv
secondary:
- "slot2"
- "wait 10"
- "slot1"
condition: mouse4
double ctrl:
# I use shift to crouch
impulse primary:
voice yes
impulse secondary:
voice no
type: impulse
primary: voice yes
secondary: voice no
condition: mouse4
# toggle
toggle capslock: voicerecord
toggle capslock: +voicerecord
# hold: null-cancelled movement, so hitting a while holding d causes
# me to go left instead of stopping, or vice-versa.
@ -83,7 +82,6 @@ default:
impulse maybeMoveRight:
alias: yes
command: ""
# class action is something useful for each class,
# like destroying and rebuilding a sentry for the engineer
# this is just the default. I do a lot of hybridknight and
@ -99,16 +97,16 @@ default:
impulse load0:
alias: yes
command: "load_itempreset 0"
command: "load_itempreset a"
impulse load1:
alias: yes
command: "load_itempreset 1"
command: "load_itempreset b"
impulse load2:
alias: yes
command: "load_itempreset 2"
command: "load_itempreset c"
impulse load3:
alias: yes
command: "load_itempreset 3"
command: "load_itempreset d"
impulse INS:
- "load0"
@ -140,12 +138,21 @@ medic:
alias: yes
press: "hud_medicautocallersthreshold 150"
release: "hud_medicautocallersthreshold 75"
double e:
type: impulse
condition: mouse4
primary: voice medic
secondary: voice uber ready
soldier:
double mouse1:
hold primary:
attack
hold secondary:
type: hold
condition: mouse4
cancel: both
# normal firing
primary: +attack
# rocket jump
secondary:
press:
- +attack
- +duck
@ -154,5 +161,3 @@ soldier:
- -attack
- -duck
- -jump
condition: mouse4

View File

@ -63,22 +63,27 @@ class bind(object):
def verify(self):
try:
typeName, self.key = self.key.split(' ', 1)
self.key = self.key.lower()
except ValueError:
# catastrophic error: either no type or no key, assume no type
self.errors.append(f'could not find type in "{self.key}"')
return
try:
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):
# KeyError, if dict but no alias field;
# AttributeError, if no pop method;
# TypeError, if pop method won't take str() as arg
self.alias = False
try:
typeName, self.key = self.key.split(' ', 1)
if not self.alias:
# don't mess with alias names
self.key = self.key.lower()
except ValueError:
# catastrophic error: either no type or no key, assume no type
self.errors.append(f'could not find type in "{self.key}"')
return
if (not self.alias) and (self.key not in validKeyList):
self.errors.append(f'invalid key name: "{self.key}"')
@ -163,7 +168,7 @@ class impulse(bind):
elif cmd == 'load_itempreset' and restOfCmd.isalpha():
try:
restOfCmd = restOfCmd.lower()
restOfCmd = ['a','b','c','d'].index(restOfCmd)
restOfCmd = str(['a','b','c','d'].index(restOfCmd))
except ValueError:
# not a load_itempreset shortcut
pass
@ -367,7 +372,7 @@ class double(bind):
self.err('requires `type` field')
return
# cancel mode
# cancel mode, must happend after type has been inferred
if 'cancel' in self.fields:
self.cancel = self.fields.pop('cancel')
if self.cancel in ('released', 'both'):
@ -408,38 +413,20 @@ class double(bind):
self.secondary.alias = True
altCode = self.secondary.toTF2()
# Make code to toggle between the two actions
# Make code to switch between the two actions
pShiftStr = f'+shift_{self.key}'
mShiftStr = f'-shift_{self.key}'
if self.cancel == 'both':
# code to cancel both if either is released
# it copies the - statement from each to both.
# if it just extracted the name of the - statement,
# you'd end up with each recursively calling the other
mainLines = mainCode.splitlines()
mainMinusLine = mainLines[1]
# second arg, without first quote
mainMinusStr = mainMinusLine.split(' ', 2)[2][1:]
altLines = altCode.splitlines()
altMinusLine = altLines[1]
# same as above
altMinusStr = altMinusLine.split(' ', 2)[2][1:]
mainLines[1] = mainLines[1][:-1] + f';{altMinusStr}'
altLines[1] = altLines[1][:-1] + f';{mainMinusStr}'
mainCode = '\n'.join(mainLines) + '\n'
altCode = '\n'.join(altLines) + '\n'
mainCode, altCode = self.cancelBoth(mainCode, altCode)
if self.type == 'hold':
self.primStr = '+' + self.primStr
self.secondStr = '+' + self.secondStr
result = mainCode + altCode +\
f'alias {pShiftStr} "{bindOrAlias} {self.key} {self.primStr}"\n' +\
f'alias {mShiftStr} "{bindOrAlias} {self.key} {self.secondStr}"\n'+\
f'alias {pShiftStr} "{bindOrAlias} {self.key} {self.secondStr}"\n' +\
f'alias {mShiftStr} "{bindOrAlias} {self.key} {self.primStr}"\n'+\
f'{bindOrAlias} {self.key} "{self.primStr}"\n'
try:
@ -465,6 +452,41 @@ class double(bind):
return result
def cancelBoth(self, mainCode, altCode) -> (str, str):
# code to cancel both if either is released
# it copies the - statement from each to both.
# if it just extracted the name of the - statement,
# you'd end up with each recursively calling the other
mainLines = mainCode.splitlines()
mainMinusLine = mainLines[1]
# second arg, without first or last quote
mainMinusStr = mainMinusLine.split(' ', 2)[2][1:-1]
altLines = altCode.splitlines()
altMinusLine = altLines[1]
# same as above
altMinusStr = altMinusLine.split(' ', 2)[2][1:-1]
# remove duplicate - actions
mainMinusList = set(mainMinusStr.split(';'))
altMinusList = set(altMinusStr.split(';'))
uniqMain = mainMinusList.difference(altMinusList)
uniqAlt = altMinusList.difference(mainMinusList)
mainMinusStr = ';'.join(uniqMain)
altMinusStr = ';'.join(uniqAlt)
if not uniqMain.issuperset(uniqAlt):
# main has things alt doesn't
mainLines[1] = mainLines[1][:-1] + f';{altMinusStr}"'
if not uniqAlt.issuperset(uniqMain):
altLines[1] = altLines[1][:-1] + f';{mainMinusStr}"'
return (
'\n'.join(mainLines) + '\n',
'\n'.join(altLines) + '\n'
)
class repeat(bind):
def verify(self):