-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbotaniaDebookified.js
95 lines (93 loc) · 3.4 KB
/
botaniaDebookified.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// priority: 10
function snakeToCamel(str) {
return str.replace(/(_\w)/g, (m) => m[1].toUpperCase());
}
function grabPage(camelCasedName, num, maxDepth) {
maxDepth = maxDepth || 2;
if (num > maxDepth) return "...";
let key = `botania.page.${camelCasedName}${num}`;
let translated = Text.translate(key);
if (translated.getString() === key) return "";
if (translated.getString() === "") return "";
return " " + translated.getString() + grabPage(camelCasedName, num + 1);
}
function parseBotaniaPageSyntax(str) {
return str
.replace(/\$\((p)?([^)]*)\)/g, (match, p1) => (p1 ? "" : "_")) // clean book references and replace with bold (_)
.replace(/(\.\s*)([A-Z])/g, ". $2") //add a space after a period if it's followed by an uppercase letter without a space
.replace(/__/g, "_")
}
const inconsistentNamesMap = {
manaPylon: "pylon",
rosaArcana: "arcanerose",
naturaPylon: "aIntro",
alfheimPortal: "aIntro",
lightRelay: "luminizerTransport",
detectorLightRelay: "luminizerTransport",
forkLightRelay: "luminizerTransport",
toggleLightRelay: "luminizerTransport",
lightLauncher: "luminizerTransport",
manaSpreader: "spreader",
manaPool: "pool",
dilutedPool: "pool",
fabulousPool: "pool",
elvenSpreader: "dreamwoodSpreader",
enchanter: "manaEnchanting",
manaDistributor: "distributor",
manaFluxfield: "rfGenerator",
twigWand: "wand",
pump: "poolCart",
craftyCrate: "craftCrate",
apothecary_: "apothecary",
gaiaPylon: "gaiaRitual",
dreamwoodWand: "elfResources",
shulkMeNot: "shulk_me_not",
bellethorn: "bellethorne",
dreadthorn: "dreadthorne",
};
function replaceInconsistentNames(str) {
Object.entries(inconsistentNamesMap).forEach(([key, value]) => {
if (key.endsWith("_") && str.includes(key.replace("_", ""))) {
str = value;
}
str = str.replace(key, value);
});
return str;
}
ClientEvents.highPriorityAssets((event) => {
let obj = {};
Ingredient.of(/^botania:/).stacks.forEach((item) => {
let cameCaseName = snakeToCamel(item.id.split(":")[1] + "");
cameCaseName = replaceInconsistentNames(cameCaseName);
let key = `botania.tagline.${cameCaseName}`;
let translated = Text.translate(key).getString();
if (translated == key) {
console.info(`missing description for ${item} key ${key}`);
return;
}
let description = `_${translated}._ ${parseBotaniaPageSyntax(
grabPage(cameCaseName, 0)
)}`;
// also add floating and chibi versions
let floatingVersion = Item.of(
item.id.split(":")[0] + ":floating_" + item.id.split(":")[1]
);
let chibiVersion = Item.of(item.id + "_chibi");
let floatingChibiVersion = Item.of(floatingVersion.id + "_chibi");
if (item.getDescriptionId() != "block.minecraft.air")
obj[`${item.getDescriptionId()}.tooltip.summary`] = description;
if (floatingVersion.getDescriptionId() != "block.minecraft.air")
obj[`${floatingVersion.getDescriptionId()}.tooltip.summary`] =
description;
if (chibiVersion.getDescriptionId() != "block.minecraft.air")
obj[`${chibiVersion.getDescriptionId()}.tooltip.summary`] = description;
if (floatingChibiVersion.getDescriptionId() != "block.minecraft.air")
obj[`${floatingChibiVersion.getDescriptionId()}.tooltip.summary`] =
description;
});
if (Object.keys(obj).length > 0)
JsonIO.write(
"kubejs/assets/botania_tooltips/lang/en_us.json",
sortObjectByKey(obj)
);
});