Newer
Older
// rewrite of the rules assistant options page in javascript
// uses an object-oriented widget pattern
// 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
globalThis.rulesAssistantOptions = (function() {
const noDefaultSetting = {value: "!NDS!", text: "no default setting"};

MouseOfLight
committed
let current_rule, root;
V.nextButton = "Back to Main";
V.nextLink = "Main";
V.returnTo = "Main";
V.showEncyclopedia = 1;
V.encyclopedia = "Personal Assistant";
if (V.currentRule !== null) {
const idx = V.defaultRules.findIndex(rule => rule.ID === V.currentRule);

MouseOfLight
committed
root = new Root(element);
function returnP(e) { return e.keyCode === 13; }

MouseOfLight
committed
function newRule() {
const rule = emptyDefaultRule();
V.defaultRules.push(rule);

MouseOfLight
committed
reload();

MouseOfLight
committed
function removeRule() {
const idx = V.defaultRules.findIndex(rule => rule.ID === current_rule.ID);
if (V.defaultRules.length > 0) {
const new_idx = idx < V.defaultRules.length ? idx : V.defaultRules.length - 1;
V.currentRule = V.defaultRules[new_idx].ID;

MouseOfLight
committed
reload();

MouseOfLight
committed
function lowerPriority() {
const idx = V.defaultRules.findIndex(rule => rule.ID === current_rule.ID);

MouseOfLight
committed
reload();

MouseOfLight
committed
function higherPriority() {
const idx = V.defaultRules.findIndex(rule => rule.ID === current_rule.ID);

MouseOfLight
committed
reload();

MouseOfLight
committed
function changeName(name) {

MouseOfLight
committed
reload();

MouseOfLight
committed
function reload() {
const parse = {
integer(string) {
let n = parseInt(string, 10);
},
boobs(string) {
return Math.clamp(parse.integer(string), 0, 48000);
},
butt(string) {
},
lips(string) {
return Math.clamp(parse.integer(string), 0, 100);
},
dick(string) {
// 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 = [];
/**
* returns the first argument to simplify creation of basic container items
* @returns {*}
*/
remove() {
const idx = this.parent.children.findIndex(child => child === this);
this.parent.children.slice(idx, 1);
this.element.remove();
}
/**
* @protected
* @param {HTMLElement} container
*/
_appendContentTo(container) {
container.appendChild(this.element);
}
super(header);
this.hidey = this.element.querySelector("div");
render(header) {
const section = document.createElement("section");
section.classList.add("rajs-section");
const h1 = document.createElement("h1");
h1.innerHTML = header;
const hidey = document.createElement("div");
section.appendChild(h1);
section.appendChild(hidey);
return section;
}
appendChild(child) {
child.parent = this;
this.children.push(child);
case "none":
this.hidey.style.display = "initial";
break;
default:
this.hidey.style.display = "none";
break;
}
}
}
class Tab extends Element {
/**
*
* @param {string} name
* @param {string} label
* @param {HTMLDivElement} tabButtonsContainer
*/
constructor(name, label, tabButtonsContainer) {
super(name);
tabButtonsContainer.appendChild(Tab.makeTabButton(name, label));
}
render(name) {
const tab = document.createElement("div");
tab.id = name;
tab.className = "tabcontent";
this.tabContent_ = document.createElement("div");
Loading
Loading full blame...