Skip to content
Snippets Groups Projects
rulesAssistantOptions.tw 79 KiB
Newer Older
  • Learn to ignore specific revisions
  • vas's avatar
    vas committed
    :: Rules Assistant Options [script]
    
    vas's avatar
    vas committed
    // jshint esversion: 6
    // jshint browser: true
    
    vas's avatar
    vas committed
    // 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
    
    vas's avatar
    vas committed
    
    
    vas's avatar
    vas committed
    window.rulesAssistantOptions = (function() {
    
    vas's avatar
    vas committed
    	"use strict";
    
    vas's avatar
    vas committed
    	let V, current_rule;
    
    vas's avatar
    vas committed
    
    
    vas's avatar
    vas committed
    	function rulesAssistantOptions(element) {
    
    vas's avatar
    vas committed
    		V = State.variables;
    		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);
    			if (idx === -1)
    				current_rule = V.defaultRules[0];
    			else
    				current_rule = V.defaultRules[idx];
    		}
    
    vas's avatar
    vas committed
    		const root = new Root(element);
    
    vas's avatar
    vas committed
    	}
    
    
    vas's avatar
    vas committed
    	function onreturn(e, cb) {
    
    vas's avatar
    vas committed
    		if (e.keyCode === 13) cb();
    
    vas's avatar
    vas committed
    	}
    
    	// create a new rule and reload
    
    vas's avatar
    vas committed
    	function newRule(root) {
    
    		const rule = emptyDefaultRule();
    		V.defaultRules.push(rule);
    
    vas's avatar
    vas committed
    		V.currentRule = rule.ID;
    
    vas's avatar
    vas committed
    		reload(root);
    
    vas's avatar
    vas committed
    	}
    
    	function removeRule(root) {
    
    vas's avatar
    vas committed
    		const idx = V.defaultRules.findIndex(rule => rule.ID === current_rule.ID);
    
    vas's avatar
    vas committed
    		V.defaultRules.splice(idx, 1);
    
    		if (V.defaultRules.length > 0) {
    			const new_idx = idx < V.defaultRules.length ? idx : V.defaultRules.length - 1;
    			V.currentRule = V.defaultRules[new_idx].ID;
    		} else V.currentRule = null;
    
    vas's avatar
    vas committed
    		reload(root);
    
    vas's avatar
    vas committed
    	}
    
    
    vas's avatar
    vas committed
    	function lowerPriority(root) {
    
    vas's avatar
    vas committed
    		if (V.defaultRules.length === 1) return; // nothing to swap with
    
    vas's avatar
    vas committed
    		const idx = V.defaultRules.findIndex(rule => rule.ID === current_rule.ID);
    
    vas's avatar
    vas committed
    		if (idx === 0) return; // no lower rule
    		arraySwap(V.defaultRules, idx, idx-1);
    		reload(root);
    
    vas's avatar
    vas committed
    	}
    
    	function higherPriority(root) {
    
    vas's avatar
    vas committed
    		if (V.defaultRules.length === 1) return; // nothing to swap with
    
    vas's avatar
    vas committed
    		const idx = V.defaultRules.findIndex(rule => rule.ID === current_rule.ID);
    
    vas's avatar
    vas committed
    		if (idx === V.defaultRules.length - 1) return; // no higher rule
    		arraySwap(V.defaultRules, idx, idx+1);
    		reload(root);
    
    vas's avatar
    vas committed
    	}
    
    	function changeName(name, root) {
    
    vas's avatar
    vas committed
    		if (name === current_rule.name) return;
    		current_rule.name = name;
    
    vas's avatar
    vas committed
    		reload(root);
    
    vas's avatar
    vas committed
    	}
    
    	// reload the passage
    
    vas's avatar
    vas committed
    	function reload(root) {
    
    vas's avatar
    vas committed
    		const elem = root.element;
    		elem.innerHTML = ""
    		rulesAssistantOptions(elem);
    
    vas's avatar
    vas committed
    	}
    
    
    vas's avatar
    vas committed
    	const parse = {
    		integer(string) {
    			let n = parseInt(string, 10);
    			return isNaN(n)? 0: n;
    		},
    		boobs(string) {
    			return Math.clamp(parse.integer(string), 0, 48000);
    		},
    		butt(string) {
    			return Math.clamp(parse.integer(string), 0, 10);
    		},
    		lips(string) {
    			return Math.clamp(parse.integer(string), 0, 100);
    		},
    		dick(string) {
    			return Math.clamp(parse.integer(string), 0, 10);
    		},
    		balls(string) {
    			return Math.clamp(parse.integer(string), 0, 10);
    		},
    	};
    
    
    vas's avatar
    vas committed
    	// 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) {
    
    vas's avatar
    vas committed
    			this.parent = null;
    			this.element = this.render(...args);
    			this.children = [];
    
    vas's avatar
    vas committed
    		}
    
    		appendChild(child) {
    
    vas's avatar
    vas committed
    			child.parent = this;
    			this.children.push(child);
    			this.element.appendChild(child.element);
    
    vas's avatar
    vas committed
    		}
    
    		// return the first argument to simplify creation of basic container items
    		render(...args) {
    
    vas's avatar
    vas committed
    			return args[0];
    
    vas's avatar
    vas committed
    		}
    
    
    		remove() {
    			const idx = this.parent.children.findIndex(child => child === this);
    			this.parent.children.slice(idx, 1);
    			this.element.remove();
    		}
    
    vas's avatar
    vas committed
    	}
    
    vas's avatar
    vas committed
    	
    	class Section extends Element {
    		constructor(header, hidden=false) {
    			super(header);
    			this.hidey = this.element.querySelector("div");
    			if (hidden) this.toggle_hidey();
    		}
    		
    		render(header) {
    			const section = document.createElement("section");
    			section.classList.add("rajs-section");
    			const h1 = document.createElement("h1");
    			h1.onclick = () => { this.toggle_hidey(); };
    			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);
    			this.hidey.appendChild(child.element);
    		}
    
    		toggle_hidey() {
    			switch(this.hidey.style.display) {
    				case "none":
    					this.hidey.style.display = "initial";
    					break;
    				default:
    					this.hidey.style.display = "none";
    					break;
    			}
    		}
    	}
    
    vas's avatar
    vas committed
    
    	// 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
    	class List extends Element {
    
    vas's avatar
    vas committed
    		constructor(prefix, data=[], textinput=false) {
    
    vas's avatar
    vas committed
    			super(prefix + ": ", textinput);
    
    vas's avatar
    vas committed
    			this.selectedItem = null;
    
    vas's avatar
    vas committed
    			data.forEach(item => this.appendChild(new ListItem(...item)));
    
    vas's avatar
    vas committed
    		}
    
    vas's avatar
    vas committed
    
    
    vas's avatar
    vas committed
    		render(prefix, textinput) {
    
    vas's avatar
    vas committed
    			const elem = document.createElement("div");
    			const label = document.createElement("span");
    			label.innerHTML = prefix;
    			let value;
    
    vas's avatar
    vas committed
    			if (textinput) {
    
    vas's avatar
    vas committed
    				value = document.createElement("input");
    
    vas's avatar
    vas committed
    				value.setAttribute("type", "text");
    
    vas's avatar
    vas committed
    				value.classList.add("rajs-value"); // 
    
    vas's avatar
    vas committed
    				// call the variable binding when the input field is no longer being edited, and when the enter key is pressed
    
    vas's avatar
    vas committed
    				value.onfocusout = () => { this.inputEdited(); };
    				value.onkeypress = (e) => { onreturn(e, () => { this.inputEdited(); }); };
    
    vas's avatar
    vas committed
    			} else {
    
    vas's avatar
    vas committed
    				value = document.createElement("strong");
    
    vas's avatar
    vas committed
    			}
    
    vas's avatar
    vas committed
    			this.value = value;
    
    vas's avatar
    vas committed
    			elem.appendChild(label);
    			elem.appendChild(value);
    			elem.classList.add("rajs-list");
    			return elem;
    
    vas's avatar
    vas committed
    		}
    
    vas's avatar
    vas committed
    
    		inputEdited() {
    
    vas's avatar
    vas committed
    			if (this.selectedItem) this.selectedItem.deselect();
    			this.propagateChange();
    
    vas's avatar
    vas committed
    		}
    
    vas's avatar
    vas committed
    
    
    vas's avatar
    vas committed
    		selectItem(item) {
    
    vas's avatar
    vas committed
    			if (this.selectedItem) this.selectedItem.deselect();
    			this.selectedItem = item;
    
    vas's avatar
    vas committed
    			this.setValue(item.data);
    
    vas's avatar
    vas committed
    			this.propagateChange();
    
    vas's avatar
    vas committed
    		}
    
    		setValue(what) {
    			if (this.value.tagName === "input")
    
    vas's avatar
    vas committed
    				this.value.value = what;
    
    vas's avatar
    vas committed
    			else
    
    vas's avatar
    vas committed
    				this.value.innerHTML = what;
    
    vas's avatar
    vas committed
    		}
    
    
    vas's avatar
    vas committed
    		getData(what) {
    
    vas's avatar
    vas committed
    			return (this.value.tagName === "input" ? this.parse(this.value.value) : this.selectedItem.data);
    
    vas's avatar
    vas committed
    		}
    
    		// customisable input field parser / sanity checker
    
    vas's avatar
    vas committed
    		parse(what) { return what; }
    
    vas's avatar
    vas committed
    
    		propagateChange() {
    			if (this.onchange instanceof Function)
    
    vas's avatar
    vas committed
    				this.onchange(this.getData());
    
    vas's avatar
    vas committed
    		}
    	}
    
    	// a clickable item of a list
    	class ListItem extends Element {
    
    vas's avatar
    vas committed
    		constructor(displayvalue, data) {
    
    vas's avatar
    vas committed
    			super(displayvalue);
    			this.data = data !== undefined ? data: displayvalue;
    			this.selected = false;
    
    vas's avatar
    vas committed
    		}
    
    vas's avatar
    vas committed
    
    
    vas's avatar
    vas committed
    		render(displayvalue) {
    
    vas's avatar
    vas committed
    			const elem = document.createElement("span");
    			elem.classList.add("rajs-listitem");
    			elem.innerHTML = displayvalue;
    			elem.onclick = () => { return this.select(); };
    			return elem;
    
    vas's avatar
    vas committed
    		}
    
    		select() {
    
    vas's avatar
    vas committed
    			if (this.selected) return false;
    			this.parent.selectItem(this);
    
    vas's avatar
    vas committed
    			this.element.classList.add("selected");
    
    vas's avatar
    vas committed
    			this.selected = true;
    			return true;
    
    vas's avatar
    vas committed
    		}
    
    		deselect() {
    
    vas's avatar
    vas committed
    			this.element.classList.remove("selected");
    
    vas's avatar
    vas committed
    			this.selected = false;
    
    vas's avatar
    vas committed
    		}
    	}
    
    	// a way to organise lists with too many elements in subsections
    	// children are bound to the master list
    	class ListSubSection extends Element {
    
    vas's avatar
    vas committed
    		constructor(parent, label, pairs) {
    
    vas's avatar
    vas committed
    			super(label);
    
    vas's avatar
    vas committed
    			this.parent = parent;
    
    vas's avatar
    vas committed
    			pairs.forEach(item => this.appendChild(new ListItem(...item)));
    
    vas's avatar
    vas committed
    		}
    		
    
    vas's avatar
    vas committed
    		render(label) {
    
    vas's avatar
    vas committed
    			const elem = document.createElement("div");
    			const lelem = document.createElement("em");
    			lelem.innerText = label + ": ";
    			elem.appendChild(lelem);
    
    vas's avatar
    vas committed
    			return elem;
    
    vas's avatar
    vas committed
    		}
    
    vas's avatar
    vas committed
    
    
    vas's avatar
    vas committed
    		appendChild(child) {
    
    vas's avatar
    vas committed
    			super.appendChild(child);
    			child.parent = this.parent;
    			this.parent.children.push(child);
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	// similar to list, but is just a collection of buttons
    
    vas's avatar
    vas committed
    	class Options extends Element {
    		constructor(elements=[]) {
    
    vas's avatar
    vas committed
    			super();
    
    vas's avatar
    vas committed
    			elements.forEach(element => { this.appendChild(element); });
    
    vas's avatar
    vas committed
    		}
    
    		render() {
    
    vas's avatar
    vas committed
    			const elem = document.createElement("div");
    			elem.classList.add("rajs-list");
    			return elem;
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	// options equivalent of ListItem
    
    vas's avatar
    vas committed
    	class OptionsItem extends Element {
    		constructor(label, onclick) {
    
    vas's avatar
    vas committed
    			super(label);
    			this.label = label;
    			this.onclick = onclick;
    
    vas's avatar
    vas committed
    		}
    		render(label, onclick) {
    
    vas's avatar
    vas committed
    			const elem = document.createElement("span");
    			elem.classList.add("rajs-listitem");
    			elem.innerHTML = label;
    			elem.onclick = () => { return this.onclick(this); };
    			return elem;
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	class ButtonList extends Element {
    		render(label) {
    
    vas's avatar
    vas committed
    			const elem = document.createElement("div");
    			const labelel = document.createElement("span");
    			labelel.innerhTML = label += ":";
    			elem.appendChild(labelel);
    			return elem;
    
    vas's avatar
    vas committed
    		}
    
    		getSelection() {
    			return (this.children
    				.filter(child => child.selected)
    				.map(child => child.setvalue)
    
    vas's avatar
    vas committed
    			);
    
    vas's avatar
    vas committed
    		}
    
    
    vas's avatar
    vas committed
    		onchange() { return; }
    
    vas's avatar
    vas committed
    	}
    
    	class ButtonItem extends Element {
    		constructor(label, setvalue, selected=false) {
    
    vas's avatar
    vas committed
    			super(label, selected);
    			this.selected = selected;
    			this.setvalue = setvalue ? setvalue : label;
    
    vas's avatar
    vas committed
    		}
    
    		render(label, selected) {
    
    vas's avatar
    vas committed
    			const container = document.createElement("div");
    			container.classList.add("rajs-listitem");
    
    vas's avatar
    vas committed
    
    
    vas's avatar
    vas committed
    			const labelel = document.createElement("span");
    			labelel.innerHTML = label;
    
    vas's avatar
    vas committed
    
    
    vas's avatar
    vas committed
    			const button = document.createElement("input");
    			button.setAttribute("type", "checkbox");
    			button.checked = selected;
    			button.onchange = () => this.onchange(button.checked);
    
    vas's avatar
    vas committed
    
    
    vas's avatar
    vas committed
    			container.appendChild(labelel);
    			container.appendChild(button);
    
    vas's avatar
    vas committed
    
    
    vas's avatar
    vas committed
    			return container;
    
    vas's avatar
    vas committed
    		}
    
    		onchange(value) {
    
    vas's avatar
    vas committed
    			this.selected = value;
    			parent.onchange(this);
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	// rule import field
    
    vas's avatar
    vas committed
    	class NewRuleField extends Element {
    		constructor(root) {
    
    vas's avatar
    vas committed
    			super();
    			this.root = root;
    
    vas's avatar
    vas committed
    		}
    
    		render() {
    
    vas's avatar
    vas committed
    			const container = document.createElement("div");
    
    vas's avatar
    vas committed
    			const textarea = document.createElement("textarea");
    
    vas's avatar
    vas committed
    			textarea.placeholder = "Paste your rule here";
    			container.appendChild(textarea);
    			this.textarea = textarea;
    			const button = document.createElement("button");
    			button.name = "Load";
    
    vas's avatar
    vas committed
    			button.innerHTML = "Load";
    
    vas's avatar
    vas committed
    			button.onclick = () => { this.loadNewRule(); };
    			container.appendChild(button);
    			return container;
    
    vas's avatar
    vas committed
    		}
    
    		loadNewRule() {
    
    vas's avatar
    vas committed
    			const text = this.textarea.value;
    
    vas's avatar
    vas committed
    			try {
    
    vas's avatar
    vas committed
    				const rule = JSON.parse(text);
    				if (!rule.ID) rule.ID = generateNewID();
    
    vas's avatar
    vas committed
    				V.defaultRules.push(rule)
    
    vas's avatar
    vas committed
    				reload(this.root);
    
    vas's avatar
    vas committed
    			} catch (e) {
    
    vas's avatar
    vas committed
    				alert("Couldn't import that rule:\n" + e.message);
    
    vas's avatar
    vas committed
    			}
    		}
    	}
    
    
    vas's avatar
    vas committed
    	// the base element, parent of all elements
    
    vas's avatar
    vas committed
    	class Root extends Element {
    
    vas's avatar
    vas committed
    		constructor(element) {
    			super(element);
    
    vas's avatar
    vas committed
    			if(V.defaultRules.length === 0) {
    
    vas's avatar
    vas committed
    				const paragraph = document.createElement("p");
    				paragraph.innerHTML = "<strong>No rules</strong>";
    				this.appendChild(new Element(paragraph));
    				this.appendChild(new NoRules(this));
    				return;
    
    vas's avatar
    vas committed
    			}
    
    vas's avatar
    vas committed
    			this.appendChild(new RuleSelector(this));
    			this.appendChild(new RuleOptions(this));
    
    vas's avatar
    vas committed
    			this.appendChild(new ConditionEditor(this));
    
    vas's avatar
    vas committed
    			this.appendChild(new EffectEditor(this));
    
    vas's avatar
    vas committed
    		}
    
    		render(element) {
    
    vas's avatar
    vas committed
    			const greeting = document.createElement("p");
    			greeting.innerHTML = `<em>${properTitle()}, 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.</em>`;
    			element.appendChild(greeting);
    			return element;
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	// optoins displayed when there are no rules
    
    vas's avatar
    vas committed
    	class NoRules extends Options {
    		constructor(root) {
    
    vas's avatar
    vas committed
    			super();
    			this.root = root;
    			const newrule = new OptionsItem("Add a new rule", () => { newRule(this.root); });
    			this.appendChild(newrule);
    
    vas's avatar
    vas committed
    			const importrule = new OptionsItem("Import a rule", () => { this.root.appendChild(new NewRuleField(this.root)); });
    
    vas's avatar
    vas committed
    			this.appendChild(importrule);
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	// buttons for selecting the current rule
    	class RuleSelector extends List {
    		constructor(root) {
    
    vas's avatar
    vas committed
    			super("Current rule", V.defaultRules.map(i => [i.name, i]));
    
    vas's avatar
    vas committed
    			this.setValue(current_rule.name)
    
    vas's avatar
    vas committed
    			this.onchange = function (rule) {
    
    				V.currentRule = rule.ID;
    
    vas's avatar
    vas committed
    				reload(root);
    			};
    
    vas's avatar
    vas committed
    		}
    	}
    
    	// buttons for doing transformations on rules
    	class RuleOptions extends Options {
    		constructor(root) {
    
    vas's avatar
    vas committed
    			super();
    			this.appendChild(new OptionsItem("New Rule", () => newRule(root)));
    			this.appendChild(new OptionsItem("Remove Rule", () => removeRule(root)));
    			this.appendChild(new OptionsItem("Apply rules", () => this.appendChild(new ApplicationLog())));
    			this.appendChild(new OptionsItem("Lower Priotity", () => lowerPriority(root)));
    			this.appendChild(new OptionsItem("Higher Priority", () => higherPriority(root)));
    			this.appendChild(new OptionsItem("Rename", () => this.appendChild(new RenameField(root))));
    
    vas's avatar
    vas committed
    			this.appendChild(new OptionsItem("Export this rule", () => this.appendChild(new ExportField(current_rule))));
    			this.appendChild(new OptionsItem("Export all rules", () => this.appendChild(new ExportField(...V.defaultRules))));
    			this.appendChild(new OptionsItem("Import a rule", () => this.appendChild(new NewRuleField(root))));
    
    vas's avatar
    vas committed
    		}
    	}
    
    	class ApplicationLog extends Element {
    		render() {
    
    vas's avatar
    vas committed
    			const elem = document.createElement("div");
    			elem.innerHTML = DefaultRules();
    			return elem;
    
    vas's avatar
    vas committed
    		}
    	}
    
    	class RenameField extends Element {
    		constructor(root) {
    
    vas's avatar
    vas committed
    			super();
    			this.element.onfocusout = () => changeName(this.element.value, root);
    			this.element.onkeypress = (e) => onreturn(e, () => changeName(this.element.value, root));
    
    vas's avatar
    vas committed
    		}
    
    		render() {
    
    vas's avatar
    vas committed
    			const elem = document.createElement("input");
    
    vas's avatar
    vas committed
    			elem.setAttribute("type", "text");
    
    vas's avatar
    vas committed
    			elem.setAttribute("value", current_rule.name);
    			return elem;
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	class ExportField extends Element {
    
    vas's avatar
    vas committed
    		render(...args) {
    			let element = document.getElementById("exportfield");
    			if (element === null) {
    				element = document.getElementById("exportfield") || document.createElement("textarea");
    				element.id = "exportfield";
    			}
    			element.value = args.map(i => JSON.stringify(i, null, 2)).join("\n\n")
    
    vas's avatar
    vas committed
    			return element;
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	// parent section for condition editing
    
    vas's avatar
    vas committed
    	class ConditionEditor extends Section {
    
    vas's avatar
    vas committed
    		constructor() {
    
    vas's avatar
    vas committed
    			super("Activation Condition");
    
    vas's avatar
    vas committed
    			this.appendChild(new ConditionFunction());
    			this.appendChild(new AssignmentInclusion());
    			this.appendChild(new FacilityInclusion());
    			this.appendChild(new SpecialExclusion());
    			this.appendChild(new SpecificInclusionExclusion());
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	class ConditionFunction extends Element {
    		constructor() {
    
    vas's avatar
    vas committed
    			super();
    
    vas's avatar
    vas committed
    			const items = [
    				["Never", false],
    				["Always", true],
    				["Custom", "custom"],
    				["Devotion", "devotion"],
    				["Trust", "trust"],
    				["Health", "health"],
    				["Sex drive", "energy"],
    				["Weight", "weight"],
    				["Age", "actualAge"],
    				["Body Age", "physicalAge"],
    				["Visible Age", "visualAge"],
    				["Muscles", "muscles"],
    				["Lactation", "lactation"],
    				["Pregnancy", "preg"],
    				["Pregnancy Multiples", "pregType"],
    				["Belly Implant", "bellyImplant"],
    				["Belly Size", "belly"],
    			];
    			this.fnlist = new List("Activation function", items);
    			this.fnlist.setValue(current_rule.condition.function === "between" ? current_rule.condition.data.attribute : current_rule.condition.function)
    
    vas's avatar
    vas committed
    			this.fnlist.onchange = (value) => this.fnchanged(value);
    
    vas's avatar
    vas committed
    			this.appendChild(this.fnlist);
    
    vas's avatar
    vas committed
    			this.fneditor = null;
    
    vas's avatar
    vas committed
    
    
    vas's avatar
    vas committed
    			switch(current_rule.condition.function) {
    				case false:
    				case true:
    
    vas's avatar
    vas committed
    					break;
    
    vas's avatar
    vas committed
    				case "custom":
    
    					this.show_custom_editor(CustomEditor, current_rule.condition.data);
    
    vas's avatar
    vas committed
    					break;
    
    vas's avatar
    vas committed
    				default:
    
    					this.show_custom_editor(RangeEditor, current_rule.condition.function, current_rule.condition.data);
    
    vas's avatar
    vas committed
    					break;
    
    vas's avatar
    vas committed
    			}
    		}
    
    
    		show_custom_editor(what, ...args) {
    			if (this.custom_editor !== null) this.hide_custom_editor();
    			this.custom_editor = new what(...args);
    			this.appendChild(this.custom_editor);
    		}
    
    		hide_custom_editor() {
    			if (this.custom_editor) {
    				this.custom_editor.remove();
    				this.custom_editor = null;
    			}
    		}
    
    
    vas's avatar
    vas committed
    		render() {
    
    vas's avatar
    vas committed
    			const elem = document.createElement("div");
    			return elem;
    
    vas's avatar
    vas committed
    		}
    
    		fnchanged(value) {
    			if (this.fneditor !== null) {
    
    vas's avatar
    vas committed
    				this.fneditor.element.remove();
    				this.fneditor = null;
    
    vas's avatar
    vas committed
    			}
    			switch(value) {
    
    vas's avatar
    vas committed
    				case true:
    					current_rule.condition.function = false;
    					current_rule.condition.data = {};
    
    					this.hide_custom_editor();
    
    vas's avatar
    vas committed
    					break;
    
    vas's avatar
    vas committed
    				case false:
    					current_rule.condition.function = true;
    					current_rule.condition.data = {};
    
    					this.hide_custom_editor();
    
    vas's avatar
    vas committed
    					break;
    
    vas's avatar
    vas committed
    				case "custom":
    					current_rule.condition.function = "custom";
    
    					current_rule.condition.data = "";
    					this.show_custom_editor(CustomEditor, current_rule.condition.data);
    
    vas's avatar
    vas committed
    					break;
    
    vas's avatar
    vas committed
    				default:
    
    vas's avatar
    vas committed
    					current_rule.condition.function = "between";
    					current_rule.condition.data = { attribute: value, value: [null, null] };
    
    					this.show_custom_editor(RangeEditor, current_rule.condition.function, current_rule.condition.data);
    
    vas's avatar
    vas committed
    					break;
    
    vas's avatar
    vas committed
    			}
    		}
    	}
    
    	class CustomEditor extends Element {
    		constructor(data) {
    
    			console.log(current_rule.condition, data);
    
    vas's avatar
    vas committed
    			if (data.length === 0) data = "function(slave) { return slave.slaveName === 'Fancy Name'; }";
    			super(data);
    
    vas's avatar
    vas committed
    		}
    
    		render(data) {
    
    vas's avatar
    vas committed
    			const elem = document.createElement("textarea");
    
    			elem.innerHTML = data;
    			elem.onfocusout = () => current_rule.condition.data = elem.value
    
    vas's avatar
    vas committed
    			return elem;
    
    vas's avatar
    vas committed
    		}
    	}
    
    	class RangeEditor extends Element {
    
    vas's avatar
    vas committed
    		render(fn, data) {
    
    vas's avatar
    vas committed
    			const elem = document.createElement("div");
    
    vas's avatar
    vas committed
    
    
    vas's avatar
    vas committed
    			const minlabel = document.createElement("label");
    			minlabel.innerHTML = "Lower bound: ";
    			elem.appendChild(minlabel);
    
    
    vas's avatar
    vas committed
    			const min = document.createElement("input");
    			min.setAttribute("type", "text");
    
    			min.value = "" + data.value[0];
    
    vas's avatar
    vas committed
    			min.onkeypress = e => onreturn(e, () => this.setmin(min.value));
    			min.onfocusout = e => this.setmin(min.value);
    
    			this.min = min;
    
    vas's avatar
    vas committed
    			elem.appendChild(min);
    
    vas's avatar
    vas committed
    
    
    vas's avatar
    vas committed
    			elem.appendChild(document.createElement("br"));
    
    			const maxlabel = document.createElement("label");
    			maxlabel.innerHTML = "Upper bound: ";
    			elem.appendChild(maxlabel);
    
    
    vas's avatar
    vas committed
    			const max = document.createElement("input");
    			max.setAttribute("type", "text");
    
    			max.value = "" + data.value[1];
    
    vas's avatar
    vas committed
    			max.onkeypress = e => onreturn(e, () => this.setmax(max.value));
    			max.onfocusout = e => this.setmax(max.value);
    
    			this.max = max;
    
    vas's avatar
    vas committed
    			elem.appendChild(max);
    
    vas's avatar
    vas committed
    
    
    vas's avatar
    vas committed
    			const infobar = document.createElement("div");
    			infobar.innerHTML = this.info(data.attribute);
    			elem.appendChild(infobar);
    
    vas's avatar
    vas committed
    
    
    vas's avatar
    vas committed
    			return elem;
    
    vas's avatar
    vas committed
    		}
    
    		parse(value) {
    
    			value = value.trim();
    
    vas's avatar
    vas committed
    			if (value === "null") value = null;
    
    vas's avatar
    vas committed
    			else {
    
    vas's avatar
    vas committed
    				value = parseInt(value);
    
    				if (isNaN(value)) value = null;
    
    vas's avatar
    vas committed
    			}
    
    vas's avatar
    vas committed
    			return value;
    
    vas's avatar
    vas committed
    		}
    
    		setmin(value) {
    
    			current_rule.condition.data.value[0] = this.parse(value);
    			this.min.value = ""+current_rule.condition.data.value[0];
    
    vas's avatar
    vas committed
    		}
    
    		setmax(value) {
    
    			current_rule.condition.data.value[1] = this.parse(value);
    			this.max.value = ""+current_rule.condition.data.value[1];
    
    vas's avatar
    vas committed
    		}
    
    		info(attribute) {
    
    vas's avatar
    vas committed
    			return "TODO";
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	class AssignmentInclusion extends ButtonList {
    
    vas's avatar
    vas committed
    		constructor() {
    
    vas's avatar
    vas committed
    			super("Apply to assignments");
    
    vas's avatar
    vas committed
    			["Rest", "Fucktoy", "Subordinate Slave", "House Servant", "Confined", "Whore", "Public Servant", "Classes", "Milked", "Gloryhole"].forEach(
    
    vas's avatar
    vas committed
    				i => this.appendChild(new ButtonItem(i, this.getAttribute(i), current_rule.condition.assignment.includes(i))));
    
    vas's avatar
    vas committed
    		}
    
    		onchange() {
    
    vas's avatar
    vas committed
    			current_rule.condition.assignment = this.getSelection();
    
    vas's avatar
    vas committed
    		}
    
    		getAttribute(what) {
    			return {
    				"Rest": "rest",
    				"Fucktoy": "please you",
    				"Subordinate Slave": "be a subordinate slave",
    				"House Servant": "be a servant",
    				"Confined": "stay confined",
    				"Whore": "whore",
    				"Public Servant": "serve the public",
    				"Classes": "take classes",
    				"Milked": "get milked",
    				"Gloryhole": "work a glory hole",
    
    vas's avatar
    vas committed
    			}[what];
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	class FacilityInclusion extends ButtonList {
    
    vas's avatar
    vas committed
    		constructor() {
    
    vas's avatar
    vas committed
    			super("Apply to assignments");
    			const facilities = [];
    			if (V.HGSuite > 0) facilities.push("Head Girl Suite");
    			if (V.brothel > 0) facilities.push("Brothel");
    			if (V.club > 0) facilities.push("Club");
    			if (V.arcade > 0) facilities.push("Arcade");
    			if (V.dairy > 0) facilities.push("Dairy");
    			if (V.servantQuarters > 0) facilities.push("Servant Quarters");
    			if (V.masterSuite > 0) facilities.push("Master Suite");
    			if (V.schoolroom > 0) facilities.push("Schoolroom");
    			if (V.spa > 0) facilities.push("Spa");
    			if (V.clinic > 0) facilities.push("Clinic");
    			if (V.cellblock > 0) facilities.push("Cellblock");
    
    vas's avatar
    vas committed
    			facilities.forEach(
    
    vas's avatar
    vas committed
    				i => this.appendChild(new ButtonItem(i, this.getAttribute(i), current_rule.condition.facility.includes(i))));
    
    vas's avatar
    vas committed
    		}
    
    		onchange(value) {
    
    vas's avatar
    vas committed
    			current_rule.condition.facility = this.getSelection();
    
    vas's avatar
    vas committed
    		}
    
    		getAttribute(what) {
    			return {
    				"Head Girl Suite": "live with your Head Girl",
    				"Brothel": "work in the brothel",
    				"Club": "serve in the club",
    				"Arcade": "be confined in the arcade",
    				"Dairy": "work in the dairy",
    				"Servant Quarters": "work as a servant",
    				"Master Suite": "serve in the master suite",
    				"Schoolroom": "learn in the schoolroom",
    				"Spa": "rest in the spa",
    				"Clinic": "get treatment in the clinic",
    				"Cellblock": "be confined in the cellblock",
    
    vas's avatar
    vas committed
    			}[what];
    
    vas's avatar
    vas committed
    		}
    	}
    
    	class SpecialExclusion extends List {
    		constructor() {
    
    vas's avatar
    vas committed
    			const items = [
    				["Yes", true],
    				["No", false]
    
    vas's avatar
    vas committed
    			];
    
    vas's avatar
    vas committed
    			super("Exclude special slaves", items);
    
    vas's avatar
    vas committed
    			this.setValue(current_rule.condition.excludeSpecialSlaves);
    			this.onchange = (value) => current_rule.condition.excludeSpecialSlaves = value;
    
    vas's avatar
    vas committed
    		}
    	}
    
    	class SpecificInclusionExclusion extends Options {
    		constructor() {
    
    vas's avatar
    vas committed
    			super();
    			this.appendChild(new OptionsItem("Limit to specific slaves", () => Engine.display("Rules Slave Select")));
    
    vas's avatar
    vas committed
    			this.appendChild(new OptionsItem("Exclude specific slaves", () => Engine.display("Rules Slave Exclude")));
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	// parent section for effect editing
    	class EffectEditor extends Element {
    		constructor() {
    
    vas's avatar
    vas committed
    			super();
    			this.appendChild(new AppearanceSection());
    			this.appendChild(new CosmeticSection());
    			this.appendChild(new BodyModSection());
    			this.appendChild(new AutosurgerySection());
    			this.appendChild(new RegimenSection());
    			this.appendChild(new BehaviourSection());
    
    vas's avatar
    vas committed
    		}
    
    		render() {
    
    vas's avatar
    vas committed
    			const element = document.createElement("div");
    			return element;
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	class AppearanceSection extends Section {
    
    		constructor() {
    
    vas's avatar
    vas committed
    			super("Appearance Settings");
    
    vas's avatar
    vas committed
    			this.appendChild(new ClothesList());
    			this.appendChild(new CollarList());
    			this.appendChild(new ShoeList());
    			this.appendChild(new CorsetList());
    			this.appendChild(new VagAccVirginsList());
    			this.appendChild(new VagAccAVirginsList());
    			this.appendChild(new VagAccOtherList());
    
    vas's avatar
    vas committed
    			if (V.seeDicks !== 0 || V.makeDicks !== 0) {
    
    vas's avatar
    vas committed
    				this.appendChild(new DickAccVirginsList());
    				this.appendChild(new DickAccOtherList());
    
    vas's avatar
    vas committed
    			}
    
    vas's avatar
    vas committed
    			this.appendChild(new ButtplugsVirginsList());
    			this.appendChild(new ButtplugsOtherList());
    			this.appendChild(new ImplantVolumeList());
    			this.appendChild(new AutosurgerySwitch());
    
    vas's avatar
    vas committed
    	class RegimenSection extends Section {
    
    vas's avatar
    vas committed
    		constructor() {
    
    vas's avatar
    vas committed
    			super("Physical Regimen Settings");
    
    vas's avatar
    vas committed
    			this.appendChild(new GrowthList());
    			this.appendChild(new CurrativesList());
    			this.appendChild(new AphrodisiacList());
    			this.appendChild(new ContraceptiveList());
    
    vas's avatar
    vas committed
    			if (V.pregSpeedControl)
    
    vas's avatar
    vas committed
    				this.appendChild(new PregDrugsList());
    			this.appendChild(new FemaleHormonesList());
    			this.appendChild(new ShemaleHormonesList());
    			this.appendChild(new GeldingHormonesList());
    			this.appendChild(new OtherDrugsList());
    			this.appendChild(new DietList());
    			this.appendChild(new DietGrowthList());
    			this.appendChild(new DietBaseList());
    			this.appendChild(new MuscleList());
    			this.appendChild(new BraceList());
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	class BehaviourSection extends Section {
    
    vas's avatar
    vas committed
    		constructor() {
    
    vas's avatar
    vas committed
    			super("Behavior Settings");
    
    vas's avatar
    vas committed
    			this.appendChild(new LivingStandardList());
    			this.appendChild(new PunishmentList());
    			this.appendChild(new RewardList());
    			this.appendChild(new ReleaseList());
    			this.appendChild(new SmartFetishList());
    			this.appendChild(new SmartXYAttractionList());
    			this.appendChild(new SmartXXAttractionList());
    			this.appendChild(new SmartEnergyList());
    			this.appendChild(new SpeechList());
    			this.appendChild(new RelationshipList());
    
    vas's avatar
    vas committed
    			if (V.studio === 1)
    
    vas's avatar
    vas committed
    				this.appendChild(new PornList());
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	class CosmeticSection extends Section {
    
    vas's avatar
    vas committed
    		constructor() {
    
    vas's avatar
    vas committed
    			super("Cosmetic Settings", true);
    
    vas's avatar
    vas committed
    			this.appendChild(new EyewearList());
    			this.appendChild(new LensesList());
    			this.appendChild(new MakeupList());
    			this.appendChild(new NailsList());
    			this.appendChild(new HairLengthList());
    			this.appendChild(new HairColourList());
    			this.appendChild(new HairStyleList());
    			this.appendChild(new PubicHairColourList());
    			this.appendChild(new PubicHairStyleList());
    			this.appendChild(new ArmpitHairColourList());
    			this.appendChild(new ArmpitHairStyleList());
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	class BodyModSection extends Section {
    
    vas's avatar
    vas committed
    		constructor() {
    
    vas's avatar
    vas committed
    			super("Body Mod Settings", true);
    
    vas's avatar
    vas committed
    			this.appendChild(new EarPiercingList());
    			this.appendChild(new NosePiercingList());
    			this.appendChild(new EyebrowPiercingList());
    			this.appendChild(new NavelPiercingList());
    			this.appendChild(new NipplePiercingList());
    			this.appendChild(new AreolaPiercingList());
    			this.appendChild(new LipPiercingList());
    			this.appendChild(new TonguePiercingList());
    			this.appendChild(new ClitPiercingList());
    			this.appendChild(new LabiaPiercingList());
    			this.appendChild(new ShaftPiercingList());
    			this.appendChild(new PerineumPiercingList());
    			this.appendChild(new CorsetPiercingList());
    
    			this.appendChild(new AutoBrandingList());
    			this.appendChild(new BrandingLocationList());
    			this.appendChild(new BrandDesignList());
    
    			this.appendChild(new FaceTattooList());
    			this.appendChild(new ShoulderTattooList());
    			this.appendChild(new ChestTattooList());
    			this.appendChild(new ArmTattooList());
    			this.appendChild(new UpperBackTattooList());
    			this.appendChild(new LowerBackTattooList());
    			this.appendChild(new AbdomenTattooList());
    
    vas's avatar
    vas committed
    			if (V.seeDicks || V.makeDicks)
    
    vas's avatar
    vas committed
    				this.appendChild(new DickTattooList());
    			this.appendChild(new ButtockTattooList());
    			this.appendChild(new AnalTattooList());
    			this.appendChild(new LegTattooList());
    
    vas's avatar
    vas committed
    		}
    	}
    
    
    vas's avatar
    vas committed
    	class AutosurgerySection extends Section {
    
    vas's avatar
    vas committed
    		constructor() {
    
    vas's avatar
    vas committed
    			super("Autosurgery Settings", true);
    
    vas's avatar
    vas committed
    			this.appendChild(new VisionSurgeryList());
    			this.appendChild(new LactationSurgeryList());
    
    vas's avatar
    vas committed
    			if (V.seeDicks || V.makeDicks)
    
    vas's avatar
    vas committed
    				this.appendChild(new SemenSurgeryList());
    			this.appendChild(new CosmeticSurgeryList());
    			this.appendChild(new LipSurgeryList());
    			this.appendChild(new ButtSurgeryList());
    			this.appendChild(new BreastSurgeryList());
    			this.appendChild(new TighteningSurgeryList());
    			this.appendChild(new BodyHairSurgeryList());
    			this.appendChild(new HairSurgeryList());
    
    vas's avatar
    vas committed
    		}
    
    vas's avatar
    vas committed
    	}
    
    
    vas's avatar
    vas committed
    	class ClothesList extends List {
    		constructor() {
    			const items = [
    				["Select her own outfit", "choosing her own clothes"]
    			];
    			super("Clothes", items);
    
    			const nclothes = [
    				["No default clothes setting", "no default setting"],
    				["Bangles", "slutty jewelry"],
    				["Bodysuit", "a comfortable bodysuit"],
    				["Cheerleader outfit", "a cheerleader outfit"],
    				["Clubslut netting", "clubslut netting"],
    				["Cutoffs and a t-shirt", "cutoffs and a t-shirt"],
    				["Fallen nun", "a fallen nuns habit"],
    				["Halter top", "a halter top dress"],
    				["Hijab and abaya", "a hijab and abaya"],
    				["Latex catsuit", "a latex catsuit"],
    				["Leotard", "a leotard"],
    				["Maid (nice)", "a nice maid outfit"],
    				["Maid (slutty)", "a slutty maid outfit"],
    				["Military uniform", "a military uniform"],
    				["Mini dress", "a mini dress"],
    				["Nice lingerie", "attractive lingerie"],
    				["Nurse (nice)", "a nice nurse outfit"],
    				["Schoolgirl", "a schoolgirl outfit"],
    				["Silken ballgown", "a ball gown"],
    				["Skimpy battledress", "battledress"],
    				["Slave gown", "a slave gown"],
    				["Slutty outfit", "a slutty outfit"],
    				["String bikini", "a stirng bikini"],
    				["Scalemail bikini", "a scalemail bikini"],
    				["Succubus costume", "a succubus outfit"],
    				["Suit (nice)", "nice business sattire"],
    				["Suit (slutty", "slutty business attire"],
    				["Spats and tank top", "spats and a tank top"]
    			];
    			const fsnclothes = [
    				["Body oil (FS)", "body oil"],
    				["Bunny outfit (FS)", "a bunny outfit"],
    				["Chattel habit (FS)", "a chattel habit"],
    				["Conservative clothing (FS)", "conservative clothing"],
    				["Harem gauze (FS)", "harem gauze"],
    				["Huipil (FS)", "a huipil"],
    				["Kimono (FS)", "a kimono"],
    				["Maternity dress (FS)", "a maternity dress"],
    				["Maternity lingerie (FS)", "attractive lingerie for a pregnant woman"],
    				["Slutty qipao (FS)", "a slutty qipao"],
    				["Stretch pants and a crop-top (FS)", "stretch pants and a crop-top"],
    				["Toga (FS)", "a toga"],
    				["Western clothing (FS)", "Western clothing"],
    			];
    			fsnclothes.forEach(pair => { if (isItemAccessible(pair[1])) nclothes.push(pair); });
    
    vas's avatar
    vas committed
    			const nice = new ListSubSection(this, "Nice", nclothes);
    
    vas's avatar
    vas committed
    			this.appendChild(nice);
    
    			const hclothes = [
    				["Nude", "no clothing"],
    				["Penitent nun", "a penitent nuns habit"],
    				["Restrictive latex", "restrictive latex"],
    				["Shibari ropes", "shibari ropes"],
    				["Uncomfortable straps", "uncomfortable straps"]
    			];
    			const fshclothes = [
    				["Chains (FS)", "chains"],
    			];
    			fshclothes.forEach(pair => { if (isItemAccessible(pair[1])) hclothes.push(pair); });
    
    
    vas's avatar
    vas committed
    			const harsh = new ListSubSection(this, "Harsh", hclothes);
    
    vas's avatar
    vas committed
    			this.appendChild(harsh);
    
    
    vas's avatar
    vas committed
    			this.setValue(current_rule.set.clothes);
    			this.onchange = (data) => current_rule.set.clothes = value;
    
    vas's avatar
    vas committed
    		}
    	}
    
    	class CollarList extends List {
    		constructor() {
    			const items = [
    				["No default collar setting", "no default setting"],
    				["No collar", "none"],
    			];
    			super("Collar", items);
    
    			const ncollars = [
    				["Stylish leather", "stylish leather"],