Skip to content

Commit

Permalink
Add image support in descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
MsRandom committed Nov 4, 2024
1 parent 1508985 commit ebeb96b
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions odysseus/convertFtbQuests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ export const convertFtbQuests = async (
const fileWrites: Promise<void>[] = [];
const warnings = new Set<string>();

const formatString = (text: string) => {
const formatString = (text: string, description = false) => {
let result = "";

for (let i = 0; i < text.length; ++i) {
Expand All @@ -571,6 +571,47 @@ export const convertFtbQuests = async (
continue;
}

if (description && character === "{") {
let 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 += `<img src="${obj.image}`;

if ("align" in obj) {
let alignment = ["left", "middle", "right"][parseInt(obj.align)];

text += ` align="${alignment}"`;
}

if ("width" in obj) {
text += ` width="${obj.width}"`;
}

if ("height" in obj) {
text += ` height="${obj.height}"`;
}

text += "/>";
}

i = end;

continue;
}

result += character;
}

Expand Down Expand Up @@ -677,7 +718,7 @@ export const convertFtbQuests = async (
: []),

...(quest.description
?.map(formatString)
?.map((s) => formatString(s, true))
?.map((s) => (s.length ? s : "<br/>")) ?? []),

...(rewardsIds.length
Expand Down

0 comments on commit ebeb96b

Please sign in to comment.