-
baletiballo authoredbaletiballo authored
SetScrollContent.js 2.95 KiB
/**
* A MMT..whatever. Somewhere between the first and second "meta-" MMT had to leave common nomenclature behind
* @typedef {{kind : string, uri: string}} MMTReference
*/
/**
* Facts, as they are send by MMT. Not *quite* the same format as Unity uses \*sigh\*, and everything has shortened names to avoid five additional letters \*double sigh\*
* @typedef {Object} MMTFact
* @property {MMTReference} ref the reference MMT uses to identify this fact
* @property {string} label the human readable lable to display this fact.
* @property {?any} df the definition of the Fact. May be null for {@link MMTScroll.requiredFacts}
* @property {?MMTReference} tp the MMT type of this fact
* @property {string} kind since a Fact is a MMTThingy, they also have a {@link MMTReference.kind}
*/
/**
* @typedef {Object} MMTScroll
* @property {string} ref The MMT URI
* @property {string} label The human-readable name
* @property {string} description The description to be rendered here
* @property {MMTFact[]} requiredFacts List of all facts required to apply the scroll. If the scroll has been partially applied these Facts may be the assigned ones
* @property {MMTFact[]} acquiredFacts List of all facts that will be acquired when applying the scroll
* @property {string} name Unity artifact; The URI again
* @property {?string} path Unity artifact; will always be null
*/
let currentScrollRef = "" // ref of the scroll currently displayed
function RenderScroll() {
/** @type {MMTScroll} */
const scroll = JSON.parse(document.querySelector("#Unity-Data-Interface").dataset.scrollDynamic);
//console.log(scroll.requiredFacts);
const scrollContainer = document.querySelector("#scrollContainer");
// replace the description if the scroll changed, otherwise only its content needs update
if (scroll.ref != currentScrollRef) {
currentScrollRef = scroll.ref;
scrollContainer.innerHTML = scroll.description;
}
// go through the facts in the scroll, show their labels, add dropzones and limit the allowed types
scroll.requiredFacts.forEach(fact => {
$("[data-slot-id='" + fact.ref.uri + "']")
.text(fact.label)
.attr("dropzone", "copy")
.attr("data-allowed-types", function (_, _) {
// Since MMT types are extremely expressive, many things can go wrong here. Luckily this means the fact is certainly not a PointFact, and we are done.
try {
if (fact.tp.uri = "http://mathhub.info/MitM/core/geometry?3DGeometry?point") { return "PointFact"; }
}
catch (err) { }
})
//.attr("data-fact-id", fact.df == null ? "" : fact.df.ref.uri)
})
// acquired facts only need updated labels
scroll.acquiredFacts.forEach(fact => {
$("[data-solution-id='" + fact.ref.uri + "']")
.text(fact.label)
})
console.log(scroll.label + 'Scroll rendered')
}
$(function () {
RenderScroll()
});