diff --git a/src/descriptions/familySummaries.js b/src/descriptions/familySummaries.js index d59f952dc45cfa50792a1f10b748f1a1b828fe89..7aa316de819147d93b2276476471889d3846232d 100644 --- a/src/descriptions/familySummaries.js +++ b/src/descriptions/familySummaries.js @@ -7,15 +7,25 @@ App.Desc.family = (function() { return slaveList.map(s => s.slaveName).reduce((res, ch, i, arr) => res + (i === arr.length - 1 ? ' and ' : ', ') + ch); } + /** See if an ID refers to a valid, active slave. This will return false for slaves that no longer exist or have not yet been created. + * @param {number} slaveID + * @returns {boolean} + */ + function validSlaveID(slaveID) { + return slaveID > 0 && _.isObject(getSlave(slaveID)); + } + /** From a slave ID, return text describing that slave (even if they aren't currently your slave) to use in place of their name * @param {number} slaveID * @returns {string} */ function knownSlave(slaveID) { - if (slaveID > 0) { + if (validSlaveID(slaveID)) { return getSlave(slaveID).slaveName; - } else { + } else if (slaveID in V.missingTable) { return "your former slave " + V.missingTable[slaveID].slaveName; + } else { + return "another slave"; } } diff --git a/src/gui/multipleInspect.js b/src/gui/multipleInspect.js new file mode 100644 index 0000000000000000000000000000000000000000..1abd7a86b0d7691d773d153d345dc44ba7226ddd --- /dev/null +++ b/src/gui/multipleInspect.js @@ -0,0 +1,68 @@ +App.UI.MultipleInspect = (function() { + function _LSDDOM(slave, saleDescription, applyLaw) { + // LSD will reset these globals, so we have to set them every single time + V.saleDescription = (saleDescription ? 1 : 0); + V.applyLaw = (applyLaw ? 1 : 0); + + // embedded sugarcube sucks but that's just how LSD works right now + const oldAS = V.activeSlave; + V.activeSlave = slave; + const frag = document.createDocumentFragment(); + $(frag).wiki(`<<include "Long Slave Description">>`); + V.activeSlave = oldAS; + return frag; + } + + /** + * Provide a mechanism to inspect multiple slaves at once (for example, for Household Liquidators and recETS). + * Intended for use from DOM passages. + * @param {Array<App.Entity.SlaveState>} slaves + * @param {boolean} showFamilyTree + * @param {boolean} saleDescription + * @param {boolean} applyLaw + * @returns {DocumentFragment} + */ + function MultipleInspectDOM(slaves, showFamilyTree, saleDescription, applyLaw) { + const frag = document.createDocumentFragment(); + const tabbar = App.UI.DOM.appendNewElement("div", "", frag, "tabbar"); + + for (const slave of slaves) { + tabbar.append(App.UI.tabbar.tabButtonDOM(`slave${slave.ID}`, slave.slaveName)); + frag.append(App.UI.tabbar.makeTabDOM(`slave${slave.ID}`, _LSDDOM(slave, saleDescription, applyLaw))); + } + + if (slaves.length > 1 && showFamilyTree) { + const button = App.UI.tabbar.tabButtonDOM(`familyTreeTab`, "Family Tree"); + button.addEventListener('click', event => { + renderFamilyTree(slaves, slaves[0].ID); + }); + tabbar.append(button); + const ftTarget = document.createElement("div"); + ftTarget.setAttribute("id", "familyTree"); + frag.append(App.UI.tabbar.makeTabDOM(`familyTreeTab`, ftTarget)); + } + + App.UI.tabbar.handlePreSelectedTab(`slave${slaves[0].ID}`); + + return frag; + } + + /** + * Provide a mechanism to inspect multiple slaves at once (for example, for Household Liquidators and recETS). + * Usable directly from SugarCube passages. + * @param {Array<App.Entity.SlaveState>} slaves + * @param {boolean} showFamilyTree + * @param {boolean} saleDescription + * @param {boolean} applyLaw + * @returns {string} + */ + function MultipleInspectSugarcube(slaves, showFamilyTree, saleDescription, applyLaw) { + const frag = MultipleInspectDOM(slaves, showFamilyTree, saleDescription, applyLaw); + return App.UI.DOM.includeDOM(frag, "MultipleInspect", "div"); + } + + return { + DOM: MultipleInspectDOM, + SC: MultipleInspectSugarcube + }; +})(); diff --git a/src/uncategorized/householdLiquidator.tw b/src/uncategorized/householdLiquidator.tw index 8cd6509ffc7b07651f3c290405331e0b3a56b79a..b6f34c76c8a5568e4e60cb1c471d16d1c46082c3 100644 --- a/src/uncategorized/householdLiquidator.tw +++ b/src/uncategorized/householdLiquidator.tw @@ -23,7 +23,7 @@ <<set _oppositeSex = 1>> <</if>> -The household liquidator is offering a set of siblings for sale. As usual, you will only be permitted to inspect the older, but there is a guarantee that the younger will be similar. +The household liquidator is offering a set of siblings for sale. You are permitted to inspect both slaves. <br><br> <<set _relativeSlave = generateRelatedSlave($activeSlave, "younger sibling", _oppositeSex)>> @@ -61,7 +61,7 @@ The household liquidator is offering a set of siblings for sale. As usual, you w <</if>> <<setLocalPronouns $activeSlave>> -The household liquidator is offering a $mother and $his <<if $activeSlave.genes == "XX" && _oppositeSex == 1>>son<<elseif $activeSlave.genes == "XY" && _oppositeSex == 1>>daughter<<else>>$daughter<</if>> for sale. As usual, you will only be permitted to inspect the $mother, but there is a guarantee that the <<if $activeSlave.genes == "XX" && _oppositeSex == 1>>son<<elseif $activeSlave.genes == "XY" && _oppositeSex == 1>>daughter<<else>>$daughter<</if>> will be similar. +The household liquidator is offering a $mother and $his <<if $activeSlave.genes == "XX" && _oppositeSex == 1>>son<<elseif $activeSlave.genes == "XY" && _oppositeSex == 1>>daughter<<else>>$daughter<</if>> for sale. You are permitted to inspect both slaves. <br><br> <<set _relativeSlave = generateRelatedSlave($activeSlave, "child", _oppositeSex)>> @@ -107,5 +107,4 @@ The price is <<print cashFormatColor(_totalCost)>>. <<if $slavesSeen > $slaveMar <br>[[Decline to purchase them and check out another set of slaves|Household Liquidator][$slavesSeen += 2]] <br><br> -<<set $saleDescription = 1, $applyLaw = 1>> -<<include "Long Slave Description">> +<<= App.UI.MultipleInspect.SC(_newSlaves, true, true, true)>>