2024-01-03 07:50:44 +00:00
|
|
|
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
|
|
|
|
2024-01-03 07:50:44 +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 {
|
2024-01-03 07:50:44 +00:00
|
|
|
return prop.celmasks.map(celmaskShower(prop))
|
2023-12-25 23:46:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-03 07:50:44 +00:00
|
|
|
const showBody = (body) => actionShower(body)("walk")
|
2023-12-25 23:46:04 +00:00
|
|
|
|
2024-01-03 07:50:44 +00:00
|
|
|
const displayFile = async (doc, container, filename, decode, show) => {
|
|
|
|
const value = await decodeBinary(filename, decode)
|
2023-12-28 21:10:00 +00:00
|
|
|
if (value.error) {
|
2023-12-25 20:32:41 +00:00
|
|
|
container.parentNode.removeChild(container)
|
2024-01-03 07:50:44 +00:00
|
|
|
doc.showError(value.error, filename)
|
2023-12-23 02:32:31 +00:00
|
|
|
} else {
|
|
|
|
try {
|
2024-01-03 07:50:44 +00:00
|
|
|
showAll(doc, container, filename, [value], show)
|
2023-12-23 02:32:31 +00:00
|
|
|
} catch (e) {
|
2023-12-25 20:32:41 +00:00
|
|
|
container.parentNode.removeChild(container)
|
2024-01-03 07:50:44 +00:00
|
|
|
doc.showError(e, filename)
|
2023-12-23 02:01:54 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-22 19:59:08 +00:00
|
|
|
}
|
|
|
|
|
2024-01-03 07:50:44 +00:00
|
|
|
const displayList = async (doc, indexFile, containerId, decode, show) => {
|
2023-12-28 21:10:00 +00:00
|
|
|
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"
|
2024-01-03 07:50:44 +00:00
|
|
|
fileContainer.appendChild(doc.linkDetail(textNode(filename, "div"), filename))
|
2023-12-28 21:10:00 +00:00
|
|
|
container.appendChild(fileContainer)
|
2024-01-03 07:50:44 +00:00
|
|
|
displayFile(doc, fileContainer, filename, decode, show)
|
2023-12-28 21:10:00 +00:00
|
|
|
}
|
2024-01-03 07:50:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|