Newer
Older
// 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
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];
}
const rule = emptyDefaultRule();
V.defaultRules.push(rule);
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;
} else V.currentRule = null;
const idx = V.defaultRules.findIndex(rule => rule.ID === current_rule.ID);
if (idx === 0) return; // no lower rule
arraySwap(V.defaultRules, idx, idx-1);
reload(root);
const idx = V.defaultRules.findIndex(rule => rule.ID === current_rule.ID);
if (idx === V.defaultRules.length - 1) return; // no higher rule
arraySwap(V.defaultRules, idx, idx+1);
reload(root);
if (name === current_rule.name) return;
current_rule.name = name;
const elem = root.element;
elem.innerHTML = ""
rulesAssistantOptions(elem);
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);
},
};
// 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 = [];
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) {
remove() {
const idx = this.parent.children.findIndex(child => child === this);
this.parent.children.slice(idx, 1);
this.element.remove();
}
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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;
}
}
}
// 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 {
const elem = document.createElement("div");
const label = document.createElement("span");
label.innerHTML = prefix;
let value;
// call the variable binding when the input field is no longer being edited, and when the enter key is pressed
value.onfocusout = () => { this.inputEdited(); };
value.onkeypress = (e) => { onreturn(e, () => { this.inputEdited(); }); };
elem.appendChild(label);
elem.appendChild(value);
elem.classList.add("rajs-list");
return elem;
if (this.selectedItem) this.selectedItem.deselect();
this.propagateChange();
if (this.selectedItem) this.selectedItem.deselect();
this.selectedItem = item;
}
setValue(what) {
if (this.value.tagName === "input")
return (this.value.tagName === "input" ? this.parse(this.value.value) : this.selectedItem.data);
propagateChange() {
if (this.onchange instanceof Function)
}
}
// a clickable item of a list
class ListItem extends Element {
super(displayvalue);
this.data = data !== undefined ? data: displayvalue;
this.selected = false;
const elem = document.createElement("span");
elem.classList.add("rajs-listitem");
elem.innerHTML = displayvalue;
elem.onclick = () => { return this.select(); };
return elem;
}
}
// a way to organise lists with too many elements in subsections
// children are bound to the master list
class ListSubSection extends Element {
const elem = document.createElement("div");
const lelem = document.createElement("em");
lelem.innerText = label + ": ";
elem.appendChild(lelem);
super.appendChild(child);
child.parent = this.parent;
this.parent.children.push(child);
const elem = document.createElement("div");
elem.classList.add("rajs-list");
return elem;
class OptionsItem extends Element {
constructor(label, onclick) {
const elem = document.createElement("span");
elem.classList.add("rajs-listitem");
elem.innerHTML = label;
elem.onclick = () => { return this.onclick(this); };
return elem;
const elem = document.createElement("div");
const labelel = document.createElement("span");
labelel.innerhTML = label += ":";
elem.appendChild(labelel);
return elem;
}
getSelection() {
return (this.children
.filter(child => child.selected)
.map(child => child.setvalue)
}
class ButtonItem extends Element {
constructor(label, setvalue, selected=false) {
super(label, selected);
this.selected = selected;
this.setvalue = setvalue ? setvalue : label;
const container = document.createElement("div");
container.classList.add("rajs-listitem");
const labelel = document.createElement("span");
labelel.innerHTML = label;
const button = document.createElement("input");
button.setAttribute("type", "checkbox");
button.checked = selected;
button.onchange = () => this.onchange(button.checked);
textarea.placeholder = "Paste your rule here";
container.appendChild(textarea);
this.textarea = textarea;
const button = document.createElement("button");
button.name = "Load";
button.onclick = () => { this.loadNewRule(); };
container.appendChild(button);
return container;
const rule = JSON.parse(text);
if (!rule.ID) rule.ID = generateNewID();
const paragraph = document.createElement("p");
paragraph.innerHTML = "<strong>No rules</strong>";
this.appendChild(new Element(paragraph));
this.appendChild(new NoRules(this));
return;
this.appendChild(new RuleSelector(this));
this.appendChild(new RuleOptions(this));
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;
super();
this.root = root;
const newrule = new OptionsItem("Add a new rule", () => { newRule(this.root); });
this.appendChild(newrule);
const importrule = new OptionsItem("Import a rule", () => { this.root.appendChild(new NewRuleField(this.root)); });
// buttons for selecting the current rule
class RuleSelector extends List {
constructor(root) {
}
}
// buttons for doing transformations on rules
class RuleOptions extends Options {
constructor(root) {
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))));
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))));
const elem = document.createElement("div");
elem.innerHTML = DefaultRules();
return elem;
}
}
class RenameField extends Element {
constructor(root) {
super();
this.element.onfocusout = () => changeName(this.element.value, root);
this.element.onkeypress = (e) => onreturn(e, () => changeName(this.element.value, root));
elem.setAttribute("value", current_rule.name);
return elem;
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")
this.appendChild(new ConditionFunction());
this.appendChild(new AssignmentInclusion());
this.appendChild(new FacilityInclusion());
this.appendChild(new SpecialExclusion());
this.appendChild(new SpecificInclusionExclusion());
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)
switch(current_rule.condition.function) {
case false:
case true:
this.show_custom_editor(CustomEditor, current_rule.condition.data);
this.show_custom_editor(RangeEditor, current_rule.condition.function, current_rule.condition.data);
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;
}
}
const elem = document.createElement("div");
return elem;
case true:
current_rule.condition.function = false;
current_rule.condition.data = {};
case false:
current_rule.condition.function = true;
current_rule.condition.data = {};
case "custom":
current_rule.condition.function = "custom";
current_rule.condition.data = "";
this.show_custom_editor(CustomEditor, current_rule.condition.data);
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);
}
}
}
class CustomEditor extends Element {
constructor(data) {
if (data.length === 0) data = "function(slave) { return slave.slaveName === 'Fancy Name'; }";
super(data);
elem.innerHTML = data;
elem.onfocusout = () => current_rule.condition.data = elem.value
const minlabel = document.createElement("label");
minlabel.innerHTML = "Lower bound: ";
elem.appendChild(minlabel);
const min = document.createElement("input");
min.setAttribute("type", "text");
min.onkeypress = e => onreturn(e, () => this.setmin(min.value));
min.onfocusout = e => this.setmin(min.value);
elem.appendChild(document.createElement("br"));
const maxlabel = document.createElement("label");
maxlabel.innerHTML = "Upper bound: ";
elem.appendChild(maxlabel);
const max = document.createElement("input");
max.setAttribute("type", "text");
max.onkeypress = e => onreturn(e, () => this.setmax(max.value));
max.onfocusout = e => this.setmax(max.value);
const infobar = document.createElement("div");
infobar.innerHTML = this.info(data.attribute);
elem.appendChild(infobar);
current_rule.condition.data.value[0] = this.parse(value);
this.min.value = ""+current_rule.condition.data.value[0];
current_rule.condition.data.value[1] = this.parse(value);
this.max.value = ""+current_rule.condition.data.value[1];
["Rest", "Fucktoy", "Subordinate Slave", "House Servant", "Confined", "Whore", "Public Servant", "Classes", "Milked", "Gloryhole"].forEach(
i => this.appendChild(new ButtonItem(i, this.getAttribute(i), current_rule.condition.assignment.includes(i))));
current_rule.condition.assignment = this.getSelection();
}
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",
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");
i => this.appendChild(new ButtonItem(i, this.getAttribute(i), current_rule.condition.facility.includes(i))));
current_rule.condition.facility = this.getSelection();
}
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",
}
}
class SpecialExclusion extends List {
constructor() {
this.setValue(current_rule.condition.excludeSpecialSlaves);
this.onchange = (value) => current_rule.condition.excludeSpecialSlaves = value;
}
}
class SpecificInclusionExclusion extends Options {
constructor() {
super();
this.appendChild(new OptionsItem("Limit to specific slaves", () => Engine.display("Rules Slave Select")));
this.appendChild(new OptionsItem("Exclude specific slaves", () => Engine.display("Rules Slave Exclude")));
// parent section for effect editing
class EffectEditor extends Element {
constructor() {
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());
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());
this.appendChild(new DickAccVirginsList());
this.appendChild(new DickAccOtherList());
this.appendChild(new ButtplugsVirginsList());
this.appendChild(new ButtplugsOtherList());
this.appendChild(new ImplantVolumeList());
this.appendChild(new AutosurgerySwitch());
this.appendChild(new GrowthList());
this.appendChild(new CurrativesList());
this.appendChild(new AphrodisiacList());
this.appendChild(new ContraceptiveList());
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());
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());
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());
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());
this.appendChild(new DickTattooList());
this.appendChild(new ButtockTattooList());
this.appendChild(new AnalTattooList());
this.appendChild(new LegTattooList());
this.appendChild(new VisionSurgeryList());
this.appendChild(new LactationSurgeryList());
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());
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
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); });
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); });
this.setValue(current_rule.set.clothes);
this.onchange = (data) => current_rule.set.clothes = value;
}
}
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"],