From 652be117ff667691df4b52f351baf8b0a41a2657 Mon Sep 17 00:00:00 2001 From: Svornost <11434-svornost@users.noreply.gitgud.io> Date: Sat, 7 Aug 2021 16:03:16 -0700 Subject: [PATCH] 1. Improve consistency between brothel and club advertisement passages. 2. Fix stray HTML tag output in club ads page. 3. Mark Brothel Advertisement, Club Advertisement, and Coursing Association passages as `jump-from-safe`. 4. Fix `cashFormatColor` and `App.UI.DOM.cashFormatColor` so that the invert parameter does what it was originally supposed to (i.e. represents an explicit cost or expense, rather than an income or flux: displaying positive numbers as red, without a negative sign, and negative numbers as green, with a negative sign). I'm not sure how this turned into "just negate the number"...`forceNeg` does that job just fine. --- src/005-passages/managePassages.js | 7 ++-- src/Mods/SpecialForce/Proposal.js | 2 +- src/facilities/brothel/brothelAds.js | 14 ++++---- src/facilities/club/clubAdvertisement.js | 33 +++++++++---------- .../policies/coursingAssociation.js | 1 - src/js/utilsDOM.js | 20 ++++++++--- src/js/utilsUnits.js | 21 +++++------- 7 files changed, 51 insertions(+), 47 deletions(-) diff --git a/src/005-passages/managePassages.js b/src/005-passages/managePassages.js index 461a50c97cc..4b1f337a91d 100644 --- a/src/005-passages/managePassages.js +++ b/src/005-passages/managePassages.js @@ -94,22 +94,21 @@ new App.DomPassage("Elective Surgery", new App.DomPassage("Brothel Advertisement", () => { return App.Facilities.Brothel.ads(); - } + }, ["jump-from-safe"] ); new App.DomPassage("Club Advertisement", () => { return App.Facilities.Club.ads(); - } + }, ["jump-from-safe"] ); new App.DomPassage("Coursing Association", () => { V.nextButton = "Back to Main"; V.nextLink = "Main"; - V.returnTo = "Coursing Association"; return App.UI.coursingAssociation(); - } + }, ["jump-from-safe"] ); new App.DomPassage("Personal assistant options", diff --git a/src/Mods/SpecialForce/Proposal.js b/src/Mods/SpecialForce/Proposal.js index 76cd75e0120..b82e8581b09 100644 --- a/src/Mods/SpecialForce/Proposal.js +++ b/src/Mods/SpecialForce/Proposal.js @@ -33,7 +33,7 @@ App.Events.SecurityForceProposal = class SecurityForceProposal extends App.Event choices.push(new App.Events.Result(`Prepare for an announcement`, announce, App.Events.makeNode([ `Initial costs are`, - App.UI.DOM.makeElement("span", cashFormat(price), ["cash", "inc"]), + App.UI.DOM.cashFormat(price), `and upon establishment the force will have significant support costs until it is self-sufficient.` ]) )); diff --git a/src/facilities/brothel/brothelAds.js b/src/facilities/brothel/brothelAds.js index ffe8b39335f..1be152743ce 100644 --- a/src/facilities/brothel/brothelAds.js +++ b/src/facilities/brothel/brothelAds.js @@ -174,15 +174,15 @@ App.Facilities.Brothel.ads = function() { function spending() { const div = App.UI.DOM.makeElement("div", null, ['margin-bottom']); - const text = []; + let text = []; const links = []; if (V.brothelAdsSpending >= 5000) { - text.push(`Advertisements based on these scenes run constantly in media across the arcology, and there's an active merchandising campaign underway to promote your whores.`); + text.push(`Advertisements based on these scenes run constantly in media across ${V.arcologies[0].name}, and there's an active merchandising campaign underway to promote your whores.`); } else if (V.brothelAdsSpending >= 4000) { - text.push(`Advertisements based on these scenes run constantly in media across the arcology.`); + text.push(`Advertisements based on these scenes run constantly in media across ${V.arcologies[0].name}.`); } else if (V.brothelAdsSpending >= 3000) { - text.push(`Advertisements based on these scenes are run in media across the arcology.`); + text.push(`Advertisements based on these scenes are run in media across ${V.arcologies[0].name}.`); } else if (V.brothelAdsSpending >= 2000) { text.push(`Advertisements based on these scenes run regularly in arcology media.`); } else if (V.brothelAdsSpending >= 1000) { @@ -190,8 +190,10 @@ App.Facilities.Brothel.ads = function() { } else { text.push(`${V.arcologies[0].name} has a robust internal media that could be used to bring customers into the brothel.`); } + App.Events.addNode(div, text, "p", "scene-intro"); - text.push(`You are spending ${cashFormatColor(V.brothelAdsSpending)} each week to advertise ${V.brothelName}.`); + text = []; + text.push(`You are spending ${cashFormatColor(V.brothelAdsSpending, true)} each week to advertise ${V.brothelName}.`); if (V.lastWeeksCashIncome.brothelAds > 0) { text.push(`Last week's ads increased profits by ${cashFormatColor(V.lastWeeksCashIncome.brothelAds)}${App.Entity.facilities.brothel.hostedSlaves > 1 ? ` and increased business for your whores` : ``}, and cost ${cashFormatColor(V.lastWeeksCashExpenses.brothelAds)}.`); @@ -202,7 +204,6 @@ App.Facilities.Brothel.ads = function() { if (V.brothelAdsSpending >= 1000) { links.push(App.UI.DOM.link(`Decrease`, () => { V.brothelAdsSpending -= 1000; - App.UI.reload(); })); } else { @@ -211,7 +212,6 @@ App.Facilities.Brothel.ads = function() { if (V.brothelAdsSpending < 5000) { links.push(App.UI.DOM.link(`Increase`, () => { V.brothelAdsSpending += 1000; - App.UI.reload(); })); } else { diff --git a/src/facilities/club/clubAdvertisement.js b/src/facilities/club/clubAdvertisement.js index 429ae6fa901..a0646b53b2c 100644 --- a/src/facilities/club/clubAdvertisement.js +++ b/src/facilities/club/clubAdvertisement.js @@ -167,29 +167,28 @@ App.Facilities.Club.ads = function() { } App.Events.addNode(node, r, "p", "scene-intro"); - App.UI.DOM.appendNewElement("div", node, `You are spending ${cashFormatColor(forceNeg(V.clubAdsSpending))} each week to advertise ${V.clubName}.`); + App.Events.addNode(node, [`You are spending ${cashFormatColor(V.clubAdsSpending, true)} each week to advertise ${V.clubName}.`]); const linkArray = []; - if (V.clubAdsSpending > 900) { - linkArray.push(App.UI.DOM.link( - "Decrease", - () => { - V.clubAdsSpending -= 1000; - App.UI.reload(); - } - )); + if (V.clubAdsSpending >= 1000) { + linkArray.push(App.UI.DOM.link(`Decrease`, () => { + V.clubAdsSpending -= 1000; + App.UI.reload(); + })); + } else { + linkArray.push(App.UI.DOM.disabledLink(`Decrease`, [`Minimum reached`])); } if (V.clubAdsSpending < 5000) { - linkArray.push(App.UI.DOM.link( - "Increase", - () => { - V.clubAdsSpending += 1000; - App.UI.reload(); - } - )); + linkArray.push(App.UI.DOM.link(`Increase`, () => { + V.clubAdsSpending += 1000; + App.UI.reload(); + })); + } else { + linkArray.push(App.UI.DOM.disabledLink(`Increase`, [`Maximum reached`])); } - App.UI.DOM.appendNewElement("div", node, App.UI.DOM.generateLinksStrip(linkArray)); + + App.UI.DOM.appendNewElement("div", node, App.UI.DOM.generateLinksStrip(linkArray), ['indent']); App.UI.DOM.appendNewElement("h2", node, `Design ${clubNameCaps} Ad Campaign`); diff --git a/src/interaction/policies/coursingAssociation.js b/src/interaction/policies/coursingAssociation.js index e91237452fd..aaa780153aa 100644 --- a/src/interaction/policies/coursingAssociation.js +++ b/src/interaction/policies/coursingAssociation.js @@ -1,5 +1,4 @@ App.UI.coursingAssociation = function() { - // :: Coursing Association [nobr] const node = new DocumentFragment(); App.Events.addParagraph(node, [`You are a member of ${V.arcologies[0].name}'s Coursing Association. Coursing is a Free Cities revival of the old sport of hunting rabbits and hares with sighthounds, with the typically Free Cities amendments that the hares are replaced by newly enslaved people, the sighthounds are replaced by trained slaves, and the killing of the hare is replaced by rape. Truly, a sport of gentlemen.`]); diff --git a/src/js/utilsDOM.js b/src/js/utilsDOM.js index 1e6b0f99e6e..9dc8690bcae 100644 --- a/src/js/utilsDOM.js +++ b/src/js/utilsDOM.js @@ -425,12 +425,22 @@ Macro.add("includeDOM", { } }); -App.UI.DOM.cashFormat = function(s) { +/** + * Formats the given number as currency. + * + * Positive values returns in green, negative values return in red, unless the invert parameter is set. + * @param {number} s The number to format. + * @param {boolean} [invert] Whether or not to invert the numbers (i.e. display positive numbers in red, and negative numbers in green). + * @returns {HTMLSpanElement} + */ +App.UI.DOM.cashFormat = function(s, invert) { const span = document.createElement("span"); - if (s < 0) { // Display red if the value is negative, unless invert is true - span.classList.add("red"); - } else if (s !== 0) { // Yellow for positive - span.classList.add("cash"); + if ((invert && s > 0) || s < 0) { + // Display in red (WITHOUT a negative sign) if the value is negative, unless invert is true + span.classList.add("cash", "dec"); + } else if (s !== 0) { + // Yellow for positive + span.classList.add("cash", "inc"); } span.textContent = cashFormat(Math.trunc(s)); return span; diff --git a/src/js/utilsUnits.js b/src/js/utilsUnits.js index 5e5932b1d5d..3c952e3e581 100644 --- a/src/js/utilsUnits.js +++ b/src/js/utilsUnits.js @@ -334,24 +334,21 @@ globalThis.cashFormat = function(s = 0) { /** * Formats the given number as currency. * - * Positive values returns in green, negative values return in red. + * Positive values returns in green, negative values return in red, unless the invert parameter is set. * @param {number} s The number to format. - * @param {boolean} invert Whether or not to invert the numbers. - * @returns {string} Returns a string of the number formatted as a currency with different colors depending on the amount. + * @param {boolean} invert Whether or not to invert the numbers (i.e. display positive numbers in red, and negative numbers in green). + * @returns {string} */ globalThis.cashFormatColor = function(s = 0, invert = false) { - if (invert) { - s = -1 * s; - } - // Display red if the value is negative, unless invert is true - if (s < 0) { - return `<span class='red'>${cashFormat(s)}</span>`; - // White for exactly zero + if ((invert && s > 0) || s < 0) { + // Display in red (WITHOUT a negative sign) if the value is negative, unless invert is true + return `<span class='cash dec'>${cashFormat(s)}</span>`; } else if (s === 0) { + // White for exactly zero return `<span>${cashFormat(s)}</span>`; - // Yellow for positive } else { - return `<span class='cash'>${cashFormat(s)}</span>`; + // Yellow for positive + return `<span class='cash inc'>${cashFormat(s)}</span>`; } }; -- GitLab