Add all changes Wire requested

This commit is contained in:
Alwinfy 2022-05-21 15:18:26 -04:00
parent 0dca1378b4
commit 7b6df0d696
No known key found for this signature in database
GPG key ID: 2CCB99445F0C949E
2 changed files with 76 additions and 32 deletions

View file

@ -10,10 +10,11 @@ import os # listdir
# extra info :(
lang = "en_us"
repo_names = {
"hexcasting": "https://raw.githubusercontent.com/gamma-delta/HexMod/main/src/main/resources",
"hexcasting": "https://raw.githubusercontent.com/gamma-delta/HexMod/main/Common/src/main/resources",
}
extra_i18n = {
"item.minecraft.amethyst_shard": "Amethyst Shard",
"item.minecraft.budding_amethyst": "Budding Amethyst",
"block.hexcasting.slate": "Blank Slate",
}
@ -210,12 +211,15 @@ def fixup_pattern(do_sig, root_data, page):
page["header"] += f" ({inp} \u2192 {oup})"
page["op"] = [(p["signature"], p["startdir"], False) for p in patterns]
def fetch_recipe_result(root_data, recipe):
def fetch_recipe(root_data, recipe):
modid, recipeid = recipe.split(":")
gen_resource_dir = root_data["resource_dir"].replace("/main", "/generated") # TODO hack
recipe_path = f"{gen_resource_dir}/data/{modid}/recipes/{recipeid}.json"
recipe_data = slurp(recipe_path)
return recipe_data["result"]["item"]
return slurp(recipe_path)
def fetch_recipe_result(root_data, recipe):
return fetch_recipe(root_data, recipe)["result"]["item"]
def fetch_bswp_recipe_result(root_data, recipe):
return fetch_recipe(root_data, recipe)["result"]["name"]
def localize_item(root_data, item):
# TODO hack
@ -229,8 +233,9 @@ page_types = {
"hexcasting:pattern": resolve_pattern,
"hexcasting:manual_pattern": bind1(fixup_pattern, True),
"hexcasting:manual_pattern_nosig": bind1(fixup_pattern, False),
"hexcasting:brainsweep": lambda rd, page: page.__setitem__("output_name", localize_item(rd, fetch_bswp_recipe_result(rd, page["recipe"]))),
"patchouli:link": lambda rd, page: do_localize(rd, page, "link_text"),
"patchouli:crafting": lambda rd, page: page.__setitem__("item_name", localize_item(rd, fetch_recipe_result(rd, page["recipe"]))),
"patchouli:crafting": lambda rd, page: page.__setitem__("item_name", [localize_item(rd, fetch_recipe_result(rd, page[ty])) for ty in ("recipe", "recipe2") if ty in page]),
"hexcasting:crafting_multi": lambda rd, page: page.__setitem__("item_name", [localize_item(rd, fetch_recipe_result(rd, recipe)) for recipe in page["recipes"]]),
"patchouli:spotlight": lambda rd, page: page.__setitem__("item_name", localize_item(rd, page["item"]))
}
@ -302,6 +307,7 @@ def parse_book(root, mod_name, book_name):
do_format(root_info, root_info, "landing_text")
root_info["categories"] = categories
root_info["blacklist"] = set()
root_info["spoilers"] = set()
return root_info
@ -406,7 +412,7 @@ def write_page(out, pageid, page):
elif ty == "patchouli:empty": pass
elif ty == "patchouli:link":
write_block(out, page["text"])
with out.pair_tag("p", clazz="linkout"):
with out.pair_tag("h4", clazz="linkout"):
with out.pair_tag("a", href=page["url"]):
out.text(page["link_text"])
elif ty == "patchouli:spotlight":
@ -416,7 +422,11 @@ def write_page(out, pageid, page):
elif ty == "patchouli:crafting":
with out.pair_tag("blockquote", clazz="crafting-info"):
out.text(f"Depicted in the book: The crafting recipe for the ")
with out.pair_tag("code"): out.text(page["item_name"])
first = True
for name in page["item_name"]:
if not first: out.text(" and ")
first = False
with out.pair_tag("code"): out.text(name)
out.text(".")
if "text" in page: write_block(out, page["text"])
elif ty == "patchouli:image":
@ -436,12 +446,16 @@ def write_page(out, pageid, page):
out.text(".")
if "text" in page: write_block(out, page["text"])
elif ty == "hexcasting:brainsweep":
with out.pair_tag("blockquote", clazz="crafting-info"):
out.text(f"Depicted in the book: A mind-flaying recipe producing the ")
with out.pair_tag("code"): out.text(page["output_name"])
out.text(".")
if "text" in page: write_block(out, page["text"])
elif ty in ("hexcasting:pattern", "hexcasting:manual_pattern_nosig", "hexcasting:manual_pattern"):
if "name" in page:
with out.pair_tag("h4", clazz="pattern-title"):
inp = page.get("input", None) or "nothing"
oup = page.get("output", None) or "nothing"
inp = page.get("input", None) or ""
oup = page.get("output", None) or ""
out.text(f"{page['name']} ({inp} \u2192 {oup})")
if anchor_id:
with out.pair_tag("a", href="#" + anchor_id, clazz="permalink small"):
@ -468,7 +482,7 @@ def write_entry(out, entry):
for page in entry["pages"]:
write_page(out, entry["id"], page)
def write_category(out, blacklist, category):
def write_category(out, book, category):
with out.pair_tag("section", id=category["id"]):
with out.pair_tag("h2", clazz="category-title page-header"):
write_block(out, category["name"])
@ -476,8 +490,9 @@ def write_category(out, blacklist, category):
out.empty_pair_tag("i", clazz="bi bi-link-45deg")
write_block(out, category["description"])
for entry in category["entries"]:
if entry["id"] not in blacklist:
write_entry(out, entry)
if entry["id"] not in book["blacklist"]:
with out.pair_tag_if(entry.get("advancement", None) in book["spoilers"], "div", clazz="spoilered"):
write_entry(out, entry)
def write_toc(out, book):
with out.pair_tag("h2", id="table-of-contents", clazz="page-header"):
@ -507,7 +522,7 @@ def write_book(out, book):
write_toc(out, book)
with out.pair_tag("main", clazz="book-body"):
for category in book["categories"]:
write_category(out, book["blacklist"], category)
write_category(out, book, category)
def main(argv):
if len(argv) < 5:
@ -524,6 +539,9 @@ def main(argv):
if line.startswith("#DO_NOT_RENDER"):
_, *blacklist = line.split()
book["blacklist"].update(blacklist)
if line.startswith("#SPOILER"):
_, *spoilers = line.split()
book["spoilers"].update(spoilers)
elif line == "#DUMP_BODY_HERE\n":
write_book(Stream(out), book)
print('', file=out)

View file

@ -64,7 +64,7 @@
content: "\2022";
margin: 1ex;
}
p.linkout::before {
.linkout::before {
content: "Link: ";
}
p.todo-note {
@ -74,6 +74,16 @@
.obfuscated {
filter: blur(1em);
}
.spoilered {
filter: blur(1ex);
transition: filter 0.2s ease;
}
.spoilered:hover {
filter: blur(0.5ex);
}
.spoilered.unspoilered {
filter: blur(0);
}
</style>
<script>
"use strict";
@ -229,21 +239,23 @@
rfaQueue.push(tick);
// scrolling input
canvas.addEventListener("wheel", ev => {
speedIncrement += ev.deltaY;
const oldSpeedLevel = speedLevel;
if (speedIncrement >= scrollThreshold) {
speedLevel--;
} else if (speedIncrement <= -scrollThreshold) {
speedLevel++;
}
if (oldSpeedLevel != speedLevel) {
speedIncrement = 0;
speedLevel = Math.max(0, Math.min(speeds.length - 1, speedLevel));
scrollTimeout = 0;
}
ev.preventDefault();
});
if (!perWorld) {
canvas.addEventListener("wheel", ev => {
speedIncrement += ev.deltaY;
const oldSpeedLevel = speedLevel;
if (speedIncrement >= scrollThreshold) {
speedLevel--;
} else if (speedIncrement <= -scrollThreshold) {
speedLevel++;
}
if (oldSpeedLevel != speedLevel) {
speedIncrement = 0;
speedLevel = Math.max(0, Math.min(speeds.length - 1, speedLevel));
scrollTimeout = 0;
}
ev.preventDefault();
});
}
}
function hookLoad(elem) {
let init = false;
@ -265,9 +277,23 @@
}
});
}
const params = new URLSearchParams(document.location.search);
function hookSpoiler(elem) {
if (params.get("nospoiler") !== null) {
elem.classList.add("unspoilered");
} else {
const thunk = ev => {
ev.preventDefault();
elem.classList.add("unspoilered");
elem.removeEventListener("click", thunk);
};
elem.addEventListener("click", thunk);
}
}
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('details.spell-collapsible').forEach(hookLoad);
document.querySelectorAll('a.toggle-link').forEach(hookToggle);
document.querySelectorAll('div.spoilered').forEach(hookSpoiler);
function tick(prevTime, time) {
const dt = time - prevTime;
for (const q of rfaQueue) {
@ -285,11 +311,11 @@
<blockquote>
<h1>This is the online version of the Hexcasting documentation.</h1>
<p>Embedded images and patterns are included, but not crafting recipes or items. There's an in-game book for those.</p>
<p>Additionally, this is built from the latest commits on the source code. It may describe <b>newer</b> features that you may not necessarily have, even on latest!</p>
<p><b>WARNING: THIS DOCUMENT CONTAINS SPOILERS!</b> Read at your own risk.</p>
<p>Additionally, this is built from the latest code on GitHub. It may describe <b>newer</b> features that you may not necessarily have, even on the latest CurseForge version!</p>
<p><b>Entries which are blurred are spoilers</b>. Click to reveal them, but be aware that they may spoil endgame progression. Alternatively, click <a href="?nospoiler">here</a> to get a version with all spoilers showing.</p>
</blockquote>
</div>
#DO_NOT_RENDER basics/couldnt_cast basics/start_to_see
#SPOILER hexcasting:opened_eyes hexcasting:y_u_no_cast_angy hexcasting:enlightenment
#DUMP_BODY_HERE
</body>
</html>