From 62cd5d7f2200f9ca7d534561ca2e64ffe7ebe0aa Mon Sep 17 00:00:00 2001 From: Ashley Wright Date: Mon, 4 Nov 2024 09:48:41 +0300 Subject: [PATCH] Add support for images in descriptions (#28) --- odysseus/convertFtbQuests.ts | 49 ++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/odysseus/convertFtbQuests.ts b/odysseus/convertFtbQuests.ts index b113c52..bd1c1a0 100644 --- a/odysseus/convertFtbQuests.ts +++ b/odysseus/convertFtbQuests.ts @@ -559,7 +559,7 @@ export const convertFtbQuests = async ( const fileWrites: Promise[] = []; const warnings = new Set(); - const formatString = (text: string) => { + const formatString = (text: string, description = false) => { let result = ""; for (let i = 0; i < text.length; ++i) { @@ -577,6 +577,51 @@ export const convertFtbQuests = async ( continue; } + if (description && character === "{") { + const end = text.indexOf("}", i + 1); + + const fieldsStrings = text.substring(i + 1, end).split(" "); + + const fields = fieldsStrings.map( + (field): [name: string, value: string] => { + const nameEnd = field.indexOf(":"); + + const name = field.substring(0, nameEnd); + const value = field.substring(nameEnd + 1); + + return [name, value]; + }, + ); + + const obj = Object.fromEntries(fields); + + if ("image" in obj) { + text += ` formatString(s, true)) ?.map((s) => (s.length ? s : "
")) ?? []), ...(rewardsIds.length