diff --git a/src/facilities/pit/pit.js b/src/facilities/pit/pit.js index 8bd4de5cb97e336637c62ab330910fcd24cd90cf..1c223828f429244a4a2c7109c28663516a57c740 100644 --- a/src/facilities/pit/pit.js +++ b/src/facilities/pit/pit.js @@ -76,12 +76,12 @@ App.Facilities.Pit.pit = function() { App.UI.DOM.link("Open them for free", () => { V.pit.audience = "free"; - refresh(mainDiv, audience); + App.UI.DOM.replace(mainDiv, audience); }), App.UI.DOM.link("Open them and charge admission", () => { V.pit.audience = "paid"; - refresh(mainDiv, audience); + App.UI.DOM.replace(mainDiv, audience); }) ); } else if (V.pit.audience === "free") { @@ -91,12 +91,12 @@ App.Facilities.Pit.pit = function() { App.UI.DOM.link("Close them", () => { V.pit.audience = "none"; - refresh(mainDiv, audience); + App.UI.DOM.replace(mainDiv, audience); }), App.UI.DOM.link("Charge admission", () => { V.pit.audience = "paid"; - refresh(mainDiv, audience); + App.UI.DOM.replace(mainDiv, audience); }) ); } else { @@ -106,12 +106,12 @@ App.Facilities.Pit.pit = function() { App.UI.DOM.link("Close them", () => { V.pit.audience = "none"; - refresh(mainDiv, audience); + App.UI.DOM.replace(mainDiv, audience); }), App.UI.DOM.link("Stop charging admission", () => { V.pit.audience = "free"; - refresh(mainDiv, audience); + App.UI.DOM.replace(mainDiv, audience); }) ); } @@ -140,7 +140,7 @@ App.Facilities.Pit.pit = function() { V.pit.fighterIDs.delete(V.BodyguardID); } - refresh(mainDiv, fighters); + App.UI.DOM.replace(mainDiv, fighters); })); // if (V.activeCanine || V.activeHooved || V.activeFeline) { @@ -152,7 +152,7 @@ App.Facilities.Pit.pit = function() { // V.pit.fighterIDs.delete(V.BodyguardID); // } - // refresh(mainDiv, fighters); + // App.UI.DOM.replace(mainDiv, fighters); // })); // } } else { @@ -164,13 +164,13 @@ App.Facilities.Pit.pit = function() { V.pit.bodyguardFights = false; V.pit.animal = null; - refresh(mainDiv, fighters); + App.UI.DOM.replace(mainDiv, fighters); }), App.UI.DOM.link("Have them fight your bodyguard", () => { V.pit.bodyguardFights = true; V.pit.animal = null; - refresh(mainDiv, fighters); + App.UI.DOM.replace(mainDiv, fighters); })); } else { mainDiv.append(`Two fighters will be selected from the pool at random.`); @@ -181,7 +181,7 @@ App.Facilities.Pit.pit = function() { V.pit.bodyguardFights = true; V.pit.animal = null; - refresh(mainDiv, fighters); + App.UI.DOM.replace(mainDiv, fighters); }) ); } @@ -192,7 +192,7 @@ App.Facilities.Pit.pit = function() { // V.pit.bodyguardFights = false; // V.pit.animal = new FC.Facilities.Animal(); - // refresh(mainDiv, fighters); + // App.UI.DOM.replace(mainDiv, fighters); // }) // ); // } @@ -220,7 +220,7 @@ App.Facilities.Pit.pit = function() { App.UI.DOM.link("Nonlethal", () => { V.pit.lethal = false; - refresh(mainDiv, lethality); + App.UI.DOM.replace(mainDiv, lethality); }) ); } else { @@ -230,7 +230,7 @@ App.Facilities.Pit.pit = function() { App.UI.DOM.link("Nonlethal", () => { V.pit.lethal = false; - refresh(mainDiv, lethality); + App.UI.DOM.replace(mainDiv, lethality); }) ); } @@ -242,7 +242,7 @@ App.Facilities.Pit.pit = function() { App.UI.DOM.link("Lethal", () => { V.pit.lethal = true; - refresh(mainDiv, lethality); + App.UI.DOM.replace(mainDiv, lethality); }) ); } else { @@ -252,7 +252,7 @@ App.Facilities.Pit.pit = function() { App.UI.DOM.link("Lethal", () => { V.pit.lethal = true; - refresh(mainDiv, lethality); + App.UI.DOM.replace(mainDiv, lethality); }) ); } @@ -281,17 +281,17 @@ App.Facilities.Pit.pit = function() { App.UI.DOM.link("Vaginal", () => { V.pit.virginities = "vaginal"; - refresh(mainDiv, virginities); + App.UI.DOM.replace(mainDiv, virginities); }), App.UI.DOM.link("Anal", () => { V.pit.virginities = "anal"; - refresh(mainDiv, virginities); + App.UI.DOM.replace(mainDiv, virginities); }), App.UI.DOM.link("All", () => { V.pit.virginities = "all"; - refresh(mainDiv, virginities); + App.UI.DOM.replace(mainDiv, virginities); }) ); } else if (V.pit.virginities === "vaginal") { @@ -302,17 +302,17 @@ App.Facilities.Pit.pit = function() { App.UI.DOM.link("Neither", () => { V.pit.virginities = "neither"; - refresh(mainDiv, virginities); + App.UI.DOM.replace(mainDiv, virginities); }), App.UI.DOM.link("Anal", () => { V.pit.virginities = "anal"; - refresh(mainDiv, virginities); + App.UI.DOM.replace(mainDiv, virginities); }), App.UI.DOM.link("All", () => { V.pit.virginities = "all"; - refresh(mainDiv, virginities); + App.UI.DOM.replace(mainDiv, virginities); }) ); } else if (V.pit.virginities === "anal") { @@ -323,17 +323,17 @@ App.Facilities.Pit.pit = function() { App.UI.DOM.link("Neither", () => { V.pit.virginities = "neither"; - refresh(mainDiv, virginities); + App.UI.DOM.replace(mainDiv, virginities); }), App.UI.DOM.link("Vaginal", () => { V.pit.virginities = "vaginal"; - refresh(mainDiv, virginities); + App.UI.DOM.replace(mainDiv, virginities); }), App.UI.DOM.link("All", () => { V.pit.virginities = "all"; - refresh(mainDiv, virginities); + App.UI.DOM.replace(mainDiv, virginities); }) ); } else { @@ -344,17 +344,17 @@ App.Facilities.Pit.pit = function() { App.UI.DOM.link("Neither", () => { V.pit.virginities = "neither"; - refresh(mainDiv, virginities); + App.UI.DOM.replace(mainDiv, virginities); }), App.UI.DOM.link("Vaginal", () => { V.pit.virginities = "vaginal"; - refresh(mainDiv, virginities); + App.UI.DOM.replace(mainDiv, virginities); }), App.UI.DOM.link("Anal", () => { V.pit.virginities = "anal"; - refresh(mainDiv, virginities); + App.UI.DOM.replace(mainDiv, virginities); }) ); } @@ -377,7 +377,7 @@ App.Facilities.Pit.pit = function() { linkSpan.append(App.UI.DOM.link("Cancel it", () => { V.pit.slaveFightingBodyguard = null; - refresh(mainDiv, scheduled); + App.UI.DOM.replace(mainDiv, scheduled); })); mainDiv.appendChild(linkSpan); @@ -404,10 +404,6 @@ App.Facilities.Pit.pit = function() { return frag; } - - function refresh(el, handler) { - $(el).empty().append(handler()); - } }; App.Facilities.Pit.init = function() { diff --git a/src/interaction/killSlave.js b/src/interaction/killSlave.js index 6bdfbcbf389c5a9a6bb413dbb299ced62f5b5d8b..a3e1c9a02963809001cd63722e1f997b604898b9 100644 --- a/src/interaction/killSlave.js +++ b/src/interaction/killSlave.js @@ -1,8 +1,4 @@ -// putting this here because it's somewhat related to the Pit and because I don't know where else to put it -// the current filing system is an absolute mess - /** - * * @param {App.Entity.SlaveState} slave */ App.UI.SlaveInteract.killSlave = function(slave) { @@ -42,6 +38,7 @@ App.UI.SlaveInteract.killSlave = function(slave) { return frag; + // MARK: Text Functions function intro() { @@ -88,7 +85,7 @@ App.UI.SlaveInteract.killSlave = function(slave) { introDiv.append(`You tell ${him} that you've gotten tired of having ${him} around and that you decided it is time to get rid of ${him}. `); if (slave.fuckdoll) { - introDiv.append(`${He} simply nods, not being able to see `); // can fuckdolls nod their heads? + introDiv.append(`${He} simply nods, not being able to see `); } else { if (slave.fetish !== "mindbroken") { introDiv.append(`${His} expression changes to one of `); @@ -134,10 +131,10 @@ App.UI.SlaveInteract.killSlave = function(slave) { links.push( App.UI.DOM.link(`Kill ${him}`, () => { - refresh(linksDiv, kill); + App.UI.DOM.replace(linksDiv, kill); }), App.UI.DOM.link(`Have mercy on ${him}`, () => { - refresh(linksDiv, mercy); + App.UI.DOM.replace(linksDiv, mercy); }), ); @@ -165,7 +162,7 @@ App.UI.SlaveInteract.killSlave = function(slave) { links.push(App.UI.DOM.disabledLink(combatLinkText, disableReasons)); } else { links.push(App.UI.DOM.link(combatLinkText, () => { - refresh(linksDiv, combat); + App.UI.DOM.replace(linksDiv, combat); })); } @@ -202,7 +199,7 @@ App.UI.SlaveInteract.killSlave = function(slave) { const mercyDiv = document.createElement("div"); if (!slave.fuckdoll && slave.fetish !== "mindbroken") { - mercyDiv.append(`You make a show of considering sparing ${his} life, then, with a heavy sigh, unbuckle your pants and sit down at your desk. You beckon to ${him}, and ${he} just about trips over ${himself} as ${he} hastily makes ${his} way over to you. ${His} blowjob isn't the best you've ever had, ${him} `, App.UI.DOM.makeElement("span", `thanking you again`, ["devotion", "inc"]), ` as much as ${he} is; but ${his} enthusiasm more than makes up for it. After you finish deep in ${his} throat, ${he} sits back and wipes away ${his} tears, sniffling and `, App.UI.DOM.makeElement("span", `sobbing`, ["trust", "dec"]), ` for giving ${him} another chance.`); + mercyDiv.append(`You make a show of considering sparing ${his} life, then, with a heavy sigh, unbuckle your pants and sit down at your desk. You beckon to ${him}, and ${he} just about trips over ${himself} as ${he} hastily makes ${his} way over to you. ${His} blowjob isn't the best you've ever had, ${him} `, App.UI.DOM.makeElement("span", `sobbing`, ["trust", "dec"]), ` as much as ${he} is; but ${his} enthusiasm more than makes up for it. After you finish deep in ${his} throat, ${he} sits back and wipes away ${his} tears, sniffling and `, App.UI.DOM.makeElement("span", `thanking you again`, ["devotion", "inc"]), ` for giving ${him} another chance.`); } else { mercyDiv.append(`You change your mind, and with a wave of your hand, send ${slave.slaveName} back to ${his} duties. Maybe some other time.`); } @@ -466,7 +463,7 @@ App.UI.SlaveInteract.killSlave = function(slave) { } if (relationshipTarget) { - if (getSlave(relationshipTarget).fetish !== "mindbroken") { // TODO: can mindbroken slaves have relationships? + if (getSlave(relationshipTarget).fetish !== "mindbroken") { const subDiv = document.createElement("div"); const target = getSlave(relationshipTarget); @@ -515,11 +512,4 @@ App.UI.SlaveInteract.killSlave = function(slave) { return plannedFightsDiv; } - - - // MARK: Helper Functions - - function refresh(el, handler) { - $(el).empty().append(handler()); - } }; diff --git a/src/js/utilsDOM.js b/src/js/utilsDOM.js index 05071b4e5e5f62643629860846dfc192e68ecb7b..e8fc2a1033753282a251d1c6d230141192ed43ea 100644 --- a/src/js/utilsDOM.js +++ b/src/js/utilsDOM.js @@ -172,11 +172,39 @@ App.UI.DOM.linkReplace = function(linkText, newContent) { }; /** - * @param {string} selector for jQuery - * @param {JQuery.Node} newContent + * Replaces a given element with the given text or node. + * + * @param {HTMLElement|DocumentFragment} el The element to be replaced. + * @param {string|HTMLElement|DocumentFragment|function():HTMLElement} newContent The text or node to replace with. Can be a function returning a node. + * + * @example + * const div = document.createElement("div"); + * const text = `Any text, including template literals`; + * div.append(App.UI.DOM.link("Link text", () => { // this link will be replaced with the given text + * App.UI.DOM.replace(div, text); + * })); + * + * function example() { + * const div = document.createElement("div"); + * let condition = false; + * if (condition) { + * div.append(App.UI.DOM.link("Link text", () => { // this link will then be replaced with second link + * let text = `Some text`; + * App.UI.DOM.replace(div, example); + * })); + * } else { + * div.append(App.UI.DOM.link("Different link text", () => { // this link will be replaced with first link + let text = `Some other text`; + * App.UI.DOM.replace(div, example); + * })); + * } + * return div; + * } + * + * @see For more examples, see killSlave.js and pit.js */ -App.UI.DOM.replace = function(selector, newContent) { - $(selector).empty().append(newContent); +App.UI.DOM.replace = function(el, newContent) { + $(el).empty().append(newContent); }; /**