From 021e378c591261f7017ffe8662cc0c33e5e2fe17 Mon Sep 17 00:00:00 2001 From: Svornost <11434-svornost@users.noreply.gitgud.io> Date: Sun, 4 Apr 2021 20:55:05 -0700 Subject: [PATCH] Simplify nesting of EventResults --- src/events/PE/UnderageConcubine.js | 2 +- src/events/RE/reNickname.js | 4 +-- src/events/RESS/hotPC.js | 2 +- src/events/eventUtils.js | 30 +++++++++++------------ src/events/scheduled/murderAttempt.js | 6 ++--- src/events/scheduled/sePCBirthday.desc.js | 21 ++++++---------- 6 files changed, 27 insertions(+), 38 deletions(-) diff --git a/src/events/PE/UnderageConcubine.js b/src/events/PE/UnderageConcubine.js index ad69c6ccae9..c4bbfa2739d 100644 --- a/src/events/PE/UnderageConcubine.js +++ b/src/events/PE/UnderageConcubine.js @@ -154,7 +154,7 @@ App.Events.PEUnderageConcubine = class PEUnderageConcubine extends App.Events.Ba new App.Events.Result(`Slaves should always see to their ${getWrittenTitle(concubine)}'s happiness, regardless of age`, slavesDuty), puberty ? new App.Events.Result(`Sex with teens is common, as it has been historically`, ephebephile) : new App.Events.Result(), new App.Events.Result(`We encourage everyone to explore their sexuality, even children`, pedophile) - ], "result2"); + ]); return frag; diff --git a/src/events/RE/reNickname.js b/src/events/RE/reNickname.js index fe7d82f6da0..132577a8feb 100644 --- a/src/events/RE/reNickname.js +++ b/src/events/RE/reNickname.js @@ -324,7 +324,6 @@ App.Events.RENickname = class RENickname extends App.Events.BaseEvent { const qualifiedNicknames = this.getQualifiedNicknames(slave); let seed = Array.from(qualifiedNicknames).random(); - let regen = 0; App.Events.drawEventArt(node, slave); const intro = App.UI.DOM.makeElement("div"); @@ -347,7 +346,6 @@ App.Events.RENickname = class RENickname extends App.Events.BaseEvent { App.Events.addResponses(el, [ new App.Events.Result("Encourage use of the nickname", encourage), new App.Events.Result("Disapprove, but encourage the other slaves to come up with a better nickname", () => { - regen++; seed = Array.from(qualifiedNicknames).random(); jQuery(intro).empty().append(introPassage()); return ``; @@ -361,7 +359,7 @@ App.Events.RENickname = class RENickname extends App.Events.BaseEvent { V.nicknamesAllowed = 0; return `You make it known that the power to name slaves is yours and yours alone.`; }) - ], `result-${regen}`); + ]); return el; function disableCheats() { diff --git a/src/events/RESS/hotPC.js b/src/events/RESS/hotPC.js index 2165783bf38..45f6f499040 100644 --- a/src/events/RESS/hotPC.js +++ b/src/events/RESS/hotPC.js @@ -161,7 +161,7 @@ App.Events.RESSHotPC = class RESSHotPC extends App.Events.BaseEvent { ? new App.Events.Result(`Fuck ${him} right here`, fuck, virginityWarning()) : new App.Events.Result(virginityWarning()), new App.Events.Result(`Have ${him} lick you clean`, lick), - ], "result2"); + ]); function fuck() { t = []; diff --git a/src/events/eventUtils.js b/src/events/eventUtils.js index 790a6e6213a..266b71f7a1c 100644 --- a/src/events/eventUtils.js +++ b/src/events/eventUtils.js @@ -162,10 +162,11 @@ App.Events.addNode = function(node, sentences, element, classNames) { */ /** a response to an event, and its result */ App.Events.Result = class { - /** @param {string} [text] - the link text for the response - * @param {resultHandler} [handler] - the function to call to generate the result when the link is clicked - * @param {string} [note] - a note to provide alongside the link (for example, a cost or virginity loss warning) - * To mark an option as disabled, construct the result with only the note. + /** + * @param {string} [text] - the link text for the response + * @param {resultHandler} [handler] - the function to call to generate the result when the link is clicked + * @param {string} [note] - a note to provide alongside the link (for example, a cost or virginity loss warning) + * To mark an option as disabled, construct the result with only the note. */ constructor(text, handler, note) { this.text = text; @@ -173,18 +174,17 @@ App.Events.Result = class { this.note = note; } - /** call the result handler, replacing the contents of the given span ID - * @param {string} resultSpanID + /** call the result handler, replacing the contents of the node + * @param {HTMLElement} node */ - handle(resultSpanID) { - let frag = document.createDocumentFragment(); + handle(node) { + let dest = $(node).empty(); let contents = this.handler(); if (Array.isArray(contents)) { - $(frag).append(...App.Events.spaceSentences(contents)); + dest.append(...App.Events.spaceSentences(contents)); } else { - $(frag).append(contents); + dest.append(contents); } - App.UI.DOM.replace(`#${resultSpanID}`, frag); } /** build the response DOM (for use by addResponses) @@ -194,7 +194,7 @@ App.Events.Result = class { makeResponse(node) { let wrote = false; if (this.text && this.handler) { - node.appendChild(App.UI.DOM.link(this.text, () => this.handle(node.id))); + node.appendChild(App.UI.DOM.link(this.text, () => this.handle(node))); wrote = true; } if (wrote && this.note) { @@ -211,11 +211,9 @@ App.Events.Result = class { /** add a list of results for an event * @param {Node} node * @param {Array<App.Events.Result>} results - * @param {string} [elementID="result"] */ -App.Events.addResponses = function(node, results, elementID = "result") { +App.Events.addResponses = function(node, results) { let resultSpan = document.createElement("span"); - resultSpan.id = elementID; for (const result of results) { if (result.makeResponse(resultSpan)) { resultSpan.appendChild(document.createElement("br")); @@ -223,8 +221,8 @@ App.Events.addResponses = function(node, results, elementID = "result") { } node.appendChild(resultSpan); }; + /** - * * @param {App.Entity.SlaveState} slave * @param {string} fetish * @returns {Node} diff --git a/src/events/scheduled/murderAttempt.js b/src/events/scheduled/murderAttempt.js index 5bd3ddf4471..01ee3609352 100644 --- a/src/events/scheduled/murderAttempt.js +++ b/src/events/scheduled/murderAttempt.js @@ -106,7 +106,7 @@ App.Events.MurderAttempt = class MurderAttempt extends App.Events.BaseEvent { App.Events.addResponses(fragment, [ new App.Events.Result(`${yesText}; invite them to a private meeting.`, invite), new App.Events.Result(`You are not going to waste your time on something as vague as a "${noText}".`, endEvent) - ], "invite"); + ]); } function invite() { @@ -150,7 +150,7 @@ App.Events.MurderAttempt = class MurderAttempt extends App.Events.BaseEvent { new App.Events.Result(`Order ${him} to leave for making such a request.`, endEvent), new App.Events.Result(`${S.Bodyguard.slaveName} goes everywhere and does everything with you. ${HeBG} stays.`, bgStaysRoute), new App.Events.Result(`This better be worth it. Order ${S.Bodyguard.slaveName} to leave.`, bgLeavesRoute) - ], "bodyguard"); + ]); } else { noSlaveRoute(fragment, r, false); } @@ -329,7 +329,7 @@ App.Events.MurderAttempt = class MurderAttempt extends App.Events.BaseEvent { break; } App.Events.addParagraph(fragment, paragraphStart); - App.Events.addResponses(fragment, options, "deal"); + App.Events.addResponses(fragment, options); } /** diff --git a/src/events/scheduled/sePCBirthday.desc.js b/src/events/scheduled/sePCBirthday.desc.js index 22f4aa6efb5..d4825e0c153 100644 --- a/src/events/scheduled/sePCBirthday.desc.js +++ b/src/events/scheduled/sePCBirthday.desc.js @@ -53,8 +53,7 @@ App.Events.pcBirthday.Desc = (function(bday) { new App.Events.Result("Engage in your business matters with focus and resolve", () => this.renderChoice_Business(data)), new App.Events.Result("Find a slave and spend the day relaxed and naked", () => this.renderChoice_Relaxed_Assistant(data)), new App.Events.Result(`Tell ${V.assistant.name} to get things ready: today there's going to be a party!`, () => this.renderChoice_Party_Assistant(data)) - ], - "bday-plans" + ] ); return frag; @@ -122,8 +121,7 @@ App.Events.pcBirthday.Desc = (function(bday) { [ new App.Events.Result("See just exactly what, or who, will go down at this event", () => this.renderChoice_Party_Planner(data)), new App.Events.Result("Enjoy the gift already sitting on your bed", () => this.renderChoice_Relaxed_Planner(data)) - ], - "bday-plans" + ] ); return frag; @@ -149,8 +147,7 @@ App.Events.pcBirthday.Desc = (function(bday) { new App.Events.Result("Engage in your business matters with focus and resolve", () => this.renderChoice_Business(data)), new App.Events.Result("Find a slave and spend the day relaxed and naked", () => this.renderChoice_Relaxed_Assistant(data)), new App.Events.Result(`Tell ${V.assistant.name} to get things ready: today there's going to be a party!`, () => this.renderChoice_Party_Assistant(data)) - ], - "bday-plans" + ] ); return frag; @@ -328,8 +325,7 @@ App.Events.pcBirthday.Desc = (function(bday) { </p> ` + this.renderPlannerScene(data); }) - ], - "bday-wish" + ] ); return frag; @@ -361,8 +357,7 @@ App.Events.pcBirthday.Desc = (function(bday) { frag, [ new App.Events.Result("Approach the girl on the bench", () => this.renderStrangerScene(data)) - ], - "bday-prey" + ] ); return frag; @@ -740,8 +735,7 @@ App.Events.pcBirthday.Desc = (function(bday) { <p>There's no need to waste time – and cleaning costs – putting on clothes that are just going to come off again.</p> ` + this.renderPartyScene_Arrival(data) + afterParty; }), - ], - "bday-wear" + ] ); return frag; @@ -1051,8 +1045,7 @@ App.Events.pcBirthday.Desc = (function(bday) { return this.renderStrangerScene_PCGetsBoned(data); } }), - ], - "bday-romp" + ] ); return frag; -- GitLab