2022-09-17 14:08:25 -04:00
|
|
|
""" This has only one function. It mostly exists to allow imports of things like tftypes """
|
2022-08-06 22:12:31 -04:00
|
|
|
|
2022-08-15 13:41:09 -04:00
|
|
|
from copy import deepcopy
|
2022-10-02 12:12:55 -04:00
|
|
|
from tfscript.tftypes import Double
|
2022-08-15 13:41:09 -04:00
|
|
|
|
2022-09-17 14:08:25 -04:00
|
|
|
def makeCFG(bindList, default=False):
|
2022-08-15 13:41:09 -04:00
|
|
|
|
|
|
|
if default:
|
|
|
|
# Write to defaultDict instead of condDict
|
2022-10-02 12:12:55 -04:00
|
|
|
Double.condDict = Double.defaultDict
|
2022-08-15 13:41:09 -04:00
|
|
|
else:
|
2022-10-02 12:12:55 -04:00
|
|
|
Double.condDict = deepcopy(Double.defaultDict)
|
2022-08-06 22:12:31 -04:00
|
|
|
|
|
|
|
ret = ''
|
2022-09-17 14:08:25 -04:00
|
|
|
|
|
|
|
for bind in bindList:
|
|
|
|
ret += bind.toTF2()
|
2022-08-06 22:12:31 -04:00
|
|
|
|
|
|
|
# Doubles are weird. All of the toggles got put into a dictionary.
|
|
|
|
# This takes all of the nested dictionaries and turns them into the right string
|
2022-10-02 12:12:55 -04:00
|
|
|
if default or Double.condDict != Double.defaultDict:
|
2022-08-19 21:34:45 -04:00
|
|
|
# ==, and by extension !=, does in fact check
|
|
|
|
# for dictionary equality in keys and values
|
2022-10-02 12:12:55 -04:00
|
|
|
for key, toggles in Double.condDict.items():
|
2022-08-19 21:34:45 -04:00
|
|
|
onCondPress = ';'.join(toggles["change_keys"])
|
|
|
|
onCondRelease = ';'.join(toggles["restore_keys"])
|
2022-10-02 12:12:55 -04:00
|
|
|
ret += (
|
|
|
|
f'alias +{key}_toggles "{onCondPress}"\n'
|
|
|
|
+ f'alias -{key}_toggles "{onCondRelease}"\n'
|
|
|
|
+ f'bind {key} "+{key}_toggles"\n'
|
|
|
|
)
|
2022-08-15 13:41:09 -04:00
|
|
|
|
2022-08-06 22:12:31 -04:00
|
|
|
return ret
|