From e7c1f8b74f92778f16721a6ad358f4f248f2a9f6 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 14 Feb 2025 15:56:05 +0100 Subject: 🐛 fix VALUES serialization for preventive archaeological files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'ishtar_common/utils.py') diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 95a7ebbaa..e69ef0290 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -112,10 +112,31 @@ class InlineClass: """ Dynamic class used in templates """ + def __init__(self, dct): for k in dct: setattr(self, k, dct[k]) + def toJSON(self): + return json.dumps( + self, + default=lambda o: o.__dict__, + sort_keys=True, + indent=4 + ) + + +def json_used_equipments(value): + res = [] + for gp in value: + res.append(gp[:4] + [cost.toJSON() for cost in gp[-1]]) + return res + + +JSON_SERIALIZATION = { + "used_equipments": json_used_equipments +} + def fake_task(*args): def fake(func): -- cgit v1.2.3