diff --git a/src/facilities/nursery/nurseryWidgets.js b/src/facilities/nursery/nurseryWidgets.js index e520d8d2c0affa6ec7083bb66e0ce930bef1fc3c..a0ec1e2cfa4d354b72d2178b075087eaae907342 100644 --- a/src/facilities/nursery/nurseryWidgets.js +++ b/src/facilities/nursery/nurseryWidgets.js @@ -2165,133 +2165,80 @@ App.Facilities.Nursery.LongInfantDescription = function(child) { } } - // aunts - for (let i = 0; i < V.slaves.length; i++) { - if (V.slaves[i] === mother || V.slaves[i] === father) { - for (let j = 0; j < V.slaves.length; j++) { - if (V.slaves[j].genes === "XX") { - if (areSisters(V.slaves[i], V.slaves[j]) === 1 || areSisters(V.slaves[i], V.slaves[j] === 2)) { - V.children.push(V.slaves[j]); - } - } - } + // aunts and uncles + let aunts = [], uncles = []; + let momsiblings = V.slaves.filter((s) => { const sis = areSisters(s, child.mother); return sis === 1 || sis === 2; }); + let dadsiblings = V.slaves.filter((s) => { const sis = areSisters(s, child.father); return sis === 1 || sis === 2; }); + for (let i = 0; i < momsiblings.length; i++) { + if (momsiblings[i].genes === "XX") { + aunts.push(momsiblings[i]); + } else { + uncles.push(momsiblings[i]); } } - - if (V.children.length > 0) { - r += `${He} `; - if (V.children.length > 2) { - r += `has <span class="lightgreen">many aunts, `; - for (j = 0; j < V.children.length; j++) { - if (j < V.children.length - 1) { - r += `${V.children[j].slaveName}, `; - } else { - r += `and ${V.children[j].slaveName}.</span> `; - } - } - } else if (V.children.length === 2) { - r += `has <span class="lightgreen">two aunts, ${V.children[0].slaveName}, and ${V.children[1].slaveName}.</span> `; + for (let i = 0; i < dadsiblings.length; i++) { + if (dadsiblings[i].genes === "XX") { + aunts.push(dadsiblings[i]); } else { - r += `has <span class="lightgreen">an aunt, ${V.children[0].slaveName}.</span> `; + uncles.push(dadsiblings[i]); } } - V.children = []; - // uncles - for (let i = 0; i < V.slaves.length; i++) { - if (V.slaves[i] === mother || V.slaves[i] === father) { - for (let j = 0; j < V.slaves.length; j++) { - if (V.slaves[j].genes === "XY") { - if (areSisters(V.slaves[i], V.slaves[j]) === 1 || areSisters(V.slaves[i], V.slaves[j] === 2)) { - V.children.push(V.slaves[j]); - } - } - } + if (aunts.length > 0) { + r += `${He} `; + if (aunts.length > 2) { + r += `has <span class="lightgreen">many aunts, ${aunts.reduce(function(res, ch, i, arr) { + return (res.slaveName || res) + (i === arr.length - 1 ? ` and ` : `, `) + ch.slaveName; + })}</span> `; + } else if (aunts.length === 2) { + r += `has <span class="lightgreen">two aunts, ${aunts[0].slaveName}, and ${aunts[1].slaveName}.</span> `; + } else { + r += `has <span class="lightgreen">an aunt, ${aunts[0].slaveName}.</span> `; } } - if (V.children.length > 0) { + if (uncles.length > 0) { r += `${He} `; - if (V.children.length > 2) { - r += `has <span class="lightgreen">many uncles, `; - for (j = 0; j < V.children.length; j++) { - if (j < V.children.length - 1) { - r += `${V.children[j].slaveName}, `; - } else { - r += `and ${V.children[j].slaveName}.</span> `; - } - } - } else if (V.children.length === 2) { - r += `has <span class="lightgreen">two uncles, ${V.children[0].slaveName}, and ${V.children[1].slaveName}.</span> `; + if (uncles.length > 2) { + r += `has <span class="lightgreen">many uncles, ${uncles.reduce(function(res, ch, i, arr) { + return (res.slaveName || res) + (i === arr.length - 1 ? ` and ` : `, `) + ch.slaveName; + })}</span> `; + } else if (uncles.length === 2) { + r += `has <span class="lightgreen">two uncles, ${uncles[0].slaveName}, and ${uncles[1].slaveName}.</span> `; } else { - r += `has <span class="lightgreen">an uncle, ${V.children[0].slaveName}.</span> `; + r += `has <span class="lightgreen">an uncle, ${uncles[0].slaveName}.</span> `; } } - V.children = []; - // nieces - for (let i = 0; i < V.slaves.length; i++) { - if (areSisters(V.slaves[i], child) === 1 || areSisters(V.slaves[i], child) === 2) { - for (let j = 0; j < V.slaves.length; j++) { - if (V.slaves[i].ID !== V.slaves[j].ID && V.slaves[j].genes === "XX") { - if (V.slaves[i].ID === V.slaves[j].mother || V.slaves[i].ID === V.slaves[j].father) { - V.children.push(V.slaves[j]); - } - } - } - } - } + // nieces and nephews + let nieces = $slaves.filter((s) => { return (isAunt(s, $activeSlave) && (s.genes === "XX")); }); + let nephews = $slaves.filter((s) => { return (isAunt(s, $activeSlave) && (s.genes === "XY")); }); - if (V.children.length > 0) { + if (nieces.length > 0) { r += `${He} `; - if (V.children.length > 2) { - r += `has <span class="lightgreen">many nieces, `; - for (j = 0; j < V.children.length; j++) { - if (j < V.children.length - 1) { - r += `${V.children[j].slaveName}, `; - } else { - r += `and ${V.children[j].slaveName}.</span> `; - } - } - } else if (V.children.length === 2) { - r += `has <span class="lightgreen">two nieces, ${V.children[0].slaveName}, and ${V.children[1].slaveName}.</span> `; + if (nieces.length > 2) { + r += `has <span class="lightgreen">many nieces, ${nieces.reduce(function(res, ch, i, arr) { + return (res.slaveName || res) + (i === arr.length - 1 ? ` and ` : `, `) + ch.slaveName; + })}</span> `; + } else if (nieces.length === 2) { + r += `has <span class="lightgreen">two nieces, ${nieces[0].slaveName}, and ${nieces[1].slaveName}.</span> `; } else { - r += `has <span class="lightgreen">a niece, ${V.children[0].slaveName}.</span> `; + r += `has <span class="lightgreen">a niece, ${nieces[0].slaveName}.</span> `; } } - V.children = []; - // nephews - for (let i = 0; i < V.slaves.length; i++) { - if (areSisters(V.slaves[i], child) === 1 || areSisters(V.slaves[i], child) === 2) { - for (let j = 0; j < V.slaves.length; j++) { - if (V.slaves[i].ID !== V.slaves[j].ID && V.slaves[j].genes === "XY") { - if (V.slaves[i].ID === V.slaves[j].mother || V.slaves[i].ID === V.slaves[j].father) { - V.children.push(V.slaves[j]); - } - } - } - } - } - - if (V.children.length > 0) { + if (nephews.length > 0) { r += `${He} `; - if (V.children.length > 2) { - r += `has <span class="lightgreen">many nephews, `; - for (j = 0; j < V.children.length; j++) { - if (j < V.children.length - 1) { - r += `${V.children[j].slaveName}, `; - } else { - r += `and ${V.children[j].slaveName}.</span> `; - } - } - } else if (V.children.length === 2) { - r += `has <span class="lightgreen">two nephews, ${V.children[0].slaveName}, and ${V.children[1].slaveName}.</span> `; + if (nephews.length > 2) { + r += `has <span class="lightgreen">many nephews, ${nephews.reduce(function(res, ch, i, arr) { + return (res.slaveName || res) + (i === arr.length - 1 ? ` and ` : `, `) + ch.slaveName; + })}</span> `; + } else if (nephews.length === 2) { + r += `has <span class="lightgreen">two nephews, ${nephews[0].slaveName}, and ${nephews[1].slaveName}.</span> `; } else { - r += `has <span class="lightgreen">a nephew, ${V.children[0].slaveName}.</span> `; + r += `has <span class="lightgreen">a nephew, ${nephews[0].slaveName}.</span> `; } } - V.children = []; let twins = [],