inhabitor/index.js

54 lines
2.2 KiB
JavaScript
Raw Normal View History

import { decodeProp, decodeBody } from "./codec.js"
import { docBuilder, showAll, decodeBinary, textNode, propAnimationShower, celmaskShower, actionShower } from "./show.js"
2023-12-22 21:54:40 +00:00
const showProp = (prop) => {
if (prop.filename == 'heads/fhead.bin') {
return textNode("CW: Pixel genitals")
} else if (prop.animations.length > 0) {
return prop.animations.map(propAnimationShower(prop))
2023-12-28 21:57:39 +00:00
} else {
return prop.celmasks.map(celmaskShower(prop))
2023-12-25 23:46:04 +00:00
}
}
const showBody = (body) => actionShower(body)("walk")
2023-12-25 23:46:04 +00:00
const displayFile = async (doc, container, filename, decode, show) => {
const value = await decodeBinary(filename, decode)
if (value.error) {
container.parentNode.removeChild(container)
doc.showError(value.error, filename)
2023-12-23 02:32:31 +00:00
} else {
try {
showAll(doc, container, filename, [value], show)
2023-12-23 02:32:31 +00:00
} catch (e) {
container.parentNode.removeChild(container)
doc.showError(e, filename)
2023-12-23 02:01:54 +00:00
}
}
2023-12-22 19:59:08 +00:00
}
const displayList = async (doc, indexFile, containerId, decode, show) => {
const response = await fetch(indexFile, { cache: "no-cache" })
const filenames = await response.json()
const container = document.getElementById(containerId)
for (const filename of filenames) {
const fileContainer = document.createElement("div")
fileContainer.style.border = "1px solid black"
fileContainer.style.margin = "2px"
fileContainer.style.padding = "2px"
fileContainer.style.display = "inline-block"
fileContainer.appendChild(doc.linkDetail(textNode(filename, "div"), filename))
container.appendChild(fileContainer)
displayFile(doc, fileContainer, filename, decode, show)
}
}
export const displayBodies = (indexFile, containerId) =>
displayList(docBuilder({ detailHref: "body.html", errorContainer: document.getElementById("errors") }),
indexFile, containerId, decodeBody, showBody)
export const displayProps = (indexFile, containerId) =>
displayList(docBuilder({ detailHref: "detail.html", errorContainer: document.getElementById("errors") }),
indexFile, containerId, decodeProp, showProp)