Skip to content

Commit

Permalink
Add support for images in descriptions (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
MsRandom authored Nov 4, 2024
1 parent 92b8233 commit 62cd5d7
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions odysseus/convertFtbQuests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,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 @@ -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 += `<img src="${obj.image}`;

if ("align" in obj) {
const 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 @@ -684,7 +729,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 62cd5d7

Please sign in to comment.