// rewrite of the rules assistant options page in javascript
// uses an object-oriented widget pattern
// wrapped in a closure so as not to polute the global namespace
// the widgets are generic enough to be reusable; if similar user interfaces are ported to JS, we could move the classes to the global scope
window.rulesAssistantOptions = (function() {
"use strict"
let V
let r = ""
let root
function rulesAssistantOptions() {
V = State.variables
V.nextButton = "Back to Main"
V.nextLink = "Main"
V.returnTo = "Main"
V.showEncyclopedia = 1
V.encyclopedia = "Personal Assistant"
root = new Element(document.querySelector("#passage-rules-assistant"))
let tmp = document.createElement("p")
tmp.innerHTML = `${propertTitle()}, I will review your slaves and make changes that will have a beneficial effect. Apologies, ${properTitle()}, but this function is... not fully complete. It may have some serious limitations. Please use the 'no default setting' option to identify areas I should not address.`
root.appendChild(new Element(tmp))
}
// helper function returning PC's title
function properTitle() {
if (V.PC.customTitle) return V.PC.customTitle
else if (V.PC.title !== 0) return "Sir"
else return "Ma'am"
}
// the Element class wraps around a DOM element and adds extra functionality
// this is safer than extending DOM objects directly
// it also turns DOM manipulation into an implementation detail
class Element {
constructor(...args) {
this.parent = null
this.element = this.render(...args)
this.children = []
}
appendChild(child) {
child.parent = this
this.children.push(child)
this.element.appendChild(child.element)
}
// return the first argument to simplify creation of basic container items
render(...args) {
return args[0]
}
}
// list of clickable elements
// has a short explanation (the prefix) and a value display
// value display can optionally be an editable text input field
// it can be "bound" to a variable by setting its "onchange" method