diff --git a/devNotes/Useful JS Function Documentation.txt b/devNotes/Useful JS Function Documentation.txt index b51924b0d311744fbea9a488ca648782825fc94a..e42c5767a488d8498aceb5965356fb54c3115448 100644 --- a/devNotes/Useful JS Function Documentation.txt +++ b/devNotes/Useful JS Function Documentation.txt @@ -173,6 +173,16 @@ relationshipChecks [script] All work as expected with <<if X.rivalryTarget == $s relationshipTermShort(id) Prints the short form of the above. e.g. line 321 of slaveInteract. `"Fuck $him with $his <<print relationshipTermShort($activeSlave)>> <<= SlaveFullName($slaves[_si])>>"` Would print 'Fuck $him with $his BFF <<= SlaveFullName($slaves[_si])>>' + + PCrelationshipTerm(id) Prints the relationship term for the input (relative to the PC) if the relationship is < -1. + <<if $slaves[$i].relationship < -1>> + $He loves being your <<print PCrelationshipTerm($slaves[$i])>>. + Would print '$He loves being your wife.' + + contextualIntro(context, actor, insertComma=false) - Introduces an actor by using any meaningful relationship(s) with an already on-screen actor, and their name. + Returns strings like: "your husband John", "his mother and growing rival Alice", or "her twin sister and best friend Carla". + If there is no known relationship between them, retuns the name alone. If insertComma is true, it will generate "her father, Dave" instead of "her father Dave". + Use this function instead of just printing the slave's name when you'd like to let the player to know if two actors are related, even though it's not going to have any mechanical impact on the scene. bellyAdjective(slave) - Returns a string describing her belly size. diff --git a/src/js/relationshipChecks.js b/src/js/relationshipChecks.js index 284e052c6676cef93d5fa91ec696178b362a0a38..54ec0490609a6fda550fc3d049053e67de59dfe2 100644 --- a/src/js/relationshipChecks.js +++ b/src/js/relationshipChecks.js @@ -47,3 +47,58 @@ window.relationshipTermShort = function(id) { return `${getPronouns(id).wife}`; } }; + +/** + * @param {{ relationship: number; }} id + * @returns {string} + */ +window.PCrelationshipTerm = function(id) { + if (id.relationship === -2) { + return "lover"; + } else if (id.relationship === -3) { + return `${getPronouns(id).wife}`; + } +}; + +/** + * Introduces an actor by using any meaningful relationship(s) with an already on-screen actor, and their name. + * Returns strings like: "your husband John", "his mother and growing rival Alice", or "her twin sister and best friend Carla". + * If there is no known relationship between them, retuns the name alone. + * Use this function instead of just printing the slave's name when you'd like to let the player to know if two actors are related, + * even though it's not going to have any mechanical impact on the scene. + * @param {App.Entity.SlaveState|App.Entity.PlayerState} context + * @param {App.Entity.SlaveState|App.Entity.PlayerState} actor + * @param {boolean} [insertComma=false] - when true, if a relationship is found, it will be separated from the actor's name by a comma ("her father, Dave" instead of "her father Dave") + * @returns {string} + */ +window.contextualIntro = function(context, actor, insertComma=false) { + let first = true; + let r = ``; + const firstPreamble = (context === V.PC) ? "your" : getPronouns(context).possessive; + let preamble = () => { + let s = first ? `${firstPreamble} ` : ` and `; + first = false; + return s; + }; + + const _relative = relativeTerm(context, actor); + if (_relative) { + r += preamble() + _relative; + } + + if (context.relationship > 0 && context.relationshipTarget === actor.ID) { + r += preamble() + relationshipTerm(context); + } else if (context === V.PC && actor.relationship < -1) { + r += preamble() + PCrelationshipTerm(actor); + } else if (actor === V.PC && context.relationship < -1) { + r += preamble() + PCrelationshipTerm(context); + } else if (context.rivalry > 0 && context.rivalryTarget === actor.ID) { + r += preamble() + rivalryTerm(context); + } + + if (r !== ``) { + r += (insertComma || actor === V.PC) ? ", " : " "; + } + r += actor === V.PC ? "you" : actor.slaveName; + return r; +}; diff --git a/src/js/slaveSummaryWidgets.js b/src/js/slaveSummaryWidgets.js index 8d7236d2f770f35847ae504d430b1191546ebd73..48258a7302a7ea4023aba9654043296269d3bc4e 100644 --- a/src/js/slaveSummaryWidgets.js +++ b/src/js/slaveSummaryWidgets.js @@ -3831,11 +3831,8 @@ window.SlaveSummaryUncached = (function() { } } else if (slave.mother === -1) { addText(block, `Your `); - if (slave.relationship === -3) { - makeSpan(block, `${getPronouns(slave).daughter} and ${getPronouns(slave).wife}.`, "lightgreen"); - handled = 1; - } else if (slave.relationship === -2) { - makeSpan(block, `${getPronouns(slave).daughter} and lover.`, "lightgreen"); + if (slave.relationship < -1) { + makeSpan(block, `${getPronouns(slave).daughter} and ${PCrelationshipTerm(slave)}.`, "lightgreen"); handled = 1; } else { makeSpan(block, `${getPronouns(slave).daughter}.`, "lightgreen"); @@ -3858,11 +3855,8 @@ window.SlaveSummaryUncached = (function() { } } else if (slave.father === -1 && slave.father !== slave.mother) { addText(block, `Your `); - if (slave.relationship === -3) { - makeSpan(block, `${getPronouns(slave).daughter} and ${getPronouns(slave).wife}.`, "lightgreen"); - handled = 1; - } else if (slave.relationship === -2) { - makeSpan(block, `${getPronouns(slave).daughter} and lover.`, "lightgreen"); + if (slave.relationship < -1) { + makeSpan(block, `${getPronouns(slave).daughter} and ${PCrelationshipTerm(slave)}.`, "lightgreen"); handled = 1; } else { makeSpan(block, `${getPronouns(slave).daughter}.`, "lightgreen"); @@ -3873,11 +3867,8 @@ window.SlaveSummaryUncached = (function() { } if (areSisters(V.PC, slave) > 0) { addText(block, `Your `); - if (slave.relationship === -3) { - makeSpan(block, `${relativeTerm(V.PC, slave)} and ${getPronouns(slave).wife}.`, "lightgreen"); - handled = 1; - } else if (slave.relationship === -2) { - makeSpan(block, `${relativeTerm(V.PC, slave)} and lover.`, "lightgreen"); + if (slave.relationship < -1) { + makeSpan(block, `${relativeTerm(V.PC, slave)} and ${PCrelationshipTerm(slave)}.`, "lightgreen"); handled = 1; } else { makeSpan(block, `${relativeTerm(V.PC, slave)}.`, "lightgreen");