From 8664ad155c89d47affd94f8b0385ebf39841f1f8 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Tue, 12 Mar 2024 17:46:44 +0000 Subject: Add YAML modal --- lib/questsLoader.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'lib') diff --git a/lib/questsLoader.ts b/lib/questsLoader.ts index 0623f04..a4ea64f 100644 --- a/lib/questsLoader.ts +++ b/lib/questsLoader.ts @@ -66,3 +66,45 @@ export function loadCategoriesFromJson(config: any): EditorCategory[] { }; }); } + +//TODO don't write fields if they're unchanged +export function mapJsonQuestToYamlObject(quest: EditorQuest): any { + return { + tasks: Object.fromEntries(Object.keys(quest.tasks).map((taskId: string) => { + return [taskId, quest.tasks[taskId].config] + })), + display: { + name: quest.display.name, + "lore-normal": quest.display.lore.normal, + "lore-started": quest.display.lore.started, + type: quest.display.type + }, + rewards: quest.rewards, + ...(quest.startCommands && { startcommands: quest.startCommands }), + ...(quest.startString && { startstring: quest.startString }), + ...(quest.rewardString && { rewardstring: quest.rewardString }), + ...(quest.placeholders && { placeholders: quest.placeholders }), + options: { + category: quest.options.category, + requires: quest.options.requirements, + "permission-required": quest.options.permissionRequired, + cancellable: quest.options.cancellable, + "counts-towards-limit": quest.options.countsTowardsLimit, + repeatable: quest.options.repeatable, + cooldown: { + enabled: quest.options.cooldown.enabled, + time: quest.options.cooldown.time, + }, + "time-limit": { + enabled: quest.options.timeLimit.enabled, + time: quest.options.timeLimit.time, + }, + "sort-order": quest.options.sortOrder, + autostart: quest.options.autostart || false, + ...(quest.options.completedDisplay && { completedDisplay: quest.options.completedDisplay }), + ...(quest.options.cooldownDisplay && { cooldownDisplay: quest.options.cooldownDisplay }), + ...(quest.options.permissionDisplay && { permissionDisplay: quest.options.permissionDisplay }), + ...(quest.options.lockedDisplay && { lockedDisplay: quest.options.lockedDisplay }), + }, + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2