Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for images in descriptions #28

Merged
merged 5 commits into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading