tfscript/src/tfscript/__init__.py

32 lines
1.1 KiB
Python
Raw Normal View History

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-09-17 14:08:25 -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-09-17 14:08:25 -04:00
double.condDict = double.defaultDict
2022-08-15 13:41:09 -04:00
else:
2022-09-17 14:08:25 -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-09-17 14:08:25 -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-09-17 14:08:25 -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"])
ret += f'alias +{key}_toggles "{onCondPress}"\n' +\
f'alias -{key}_toggles "{onCondRelease}"\n' +\
2022-09-17 14:08:25 -04:00
f'bind {key} "+{key}_toggles"\n'
2022-08-15 13:41:09 -04:00
2022-08-06 22:12:31 -04:00
return ret