From 0c5f1b6a6f7c7bcfaf8a5b085cbc256630cb2ff0 Mon Sep 17 00:00:00 2001 From: horrible little slime <69secret69email69@gmail.com> Date: Mon, 11 Nov 2024 10:43:05 -0500 Subject: [PATCH] create & export `toJSON` replacement --- src/lib.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib.ts b/src/lib.ts index 567a1013e7..39303f4357 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -1470,3 +1470,19 @@ export function totalFamiliarWeight( (familiar.feasted ? 10 : 0) ); } + +/** + * JSON-ify an object with mafia constants rendered legibly + * @param obj The object to convert to a JSON string + * @returns A JSON string + */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function toMafiaJson(obj: any): string { + return JSON.stringify(obj, (_, value) => { + const mafiaClass = MafiaClasses.find( + (mafiaClass) => value instanceof mafiaClass, + ); + if (mafiaClass) return `[${mafiaClass.name}]${value}`; + return value; + }); +}