diff --git a/src/data/backwardsCompatibility/backwardsCompatibility.js b/src/data/backwardsCompatibility/backwardsCompatibility.js index 7017a55f1d9922dfd1c1f204678703fb8d7e3bec..64ed155782408677cfc8c1b7f75ffe62b9be8d78 100644 --- a/src/data/backwardsCompatibility/backwardsCompatibility.js +++ b/src/data/backwardsCompatibility/backwardsCompatibility.js @@ -1280,6 +1280,8 @@ App.Update.slaveRecords = function(node) { }; App.Update.genePoolRecords = function(node) { + V.slaveIndices = slaves2indices(); // we're going to need to compare to active slaves, if they exist + for (let bci = 0; bci < V.genePool.length; bci++) { App.Update.Slave(V.genePool[bci], true); let slave = V.genePool[bci]; @@ -1358,6 +1360,17 @@ App.Update.genePoolRecords = function(node) { App.Entity.Utils.GenePoolRecordCleanup(slave); V.genePool[bci] = slave; + + // if a genepool entry doesn't have specific parent information, but the "live" copy of the same slave does, copy it into the genepool + const liveSlave = getSlave(V.genePool[bci].ID); + if (liveSlave) { + if (liveSlave.mother && V.genePool[bci].mother === 0) { + V.genePool[bci].mother = liveSlave.mother; + } + if (liveSlave.father && V.genePool[bci].father === 0) { + V.genePool[bci].father = liveSlave.father; + } + } } node.append(`Done!`); }; diff --git a/src/events/reRelativeRecruiter.js b/src/events/reRelativeRecruiter.js index 07957119502fbeff4b069c7b23e37d87c4cefca6..19d758bbabba2f9caf7d9d179c1c3ffa3ad0b706 100644 --- a/src/events/reRelativeRecruiter.js +++ b/src/events/reRelativeRecruiter.js @@ -576,6 +576,29 @@ App.Events.RERelativeRecruiter = class RERelativeRecruiter extends App.Events.Ba return newSlave; } + /** we need to record any new parent information for existing slaves into the genepool as well as directly into the slave in question + * @param {App.Entity.SlaveState} slave + * @param {object} parentIDs + * @param {number} [parentIDs.mother] + * @param {number} [parentIDs.father] + */ + function setUnknownParents(slave, parentIDs = {}) { + const gp = V.genePool.find(s => s.ID === slave.ID); + + if (parentIDs.mother && slave.mother === 0) { + slave.mother = parentIDs.mother; + if (gp) { + gp.mother = parentIDs.mother; + } + } + if (parentIDs.father && slave.father === 0) { + slave.father = parentIDs.father; + if (gp) { + gp.father = parentIDs.father; + } + } + } + function buySlave() { // kill the cheat div (no going back now!) $(cheatDiv).empty(); @@ -583,19 +606,19 @@ App.Events.RERelativeRecruiter = class RERelativeRecruiter extends App.Events.Ba // the new slave is already set up to be related to the exising slave, but we're responsible for making sure the existing slave (and any others in our stable) gets *their* relatives set correctly switch (_this.params.relative) { case "mother": { - eventSlave.mother = V.activeSlave.ID; + setUnknownParents(eventSlave, {mother: V.activeSlave.ID} ); for (const slave of V.slaves) { - if (sameDad(eventSlave, slave) && slave.mother === 0) { - slave.mother = V.activeSlave.ID; + if (sameDad(eventSlave, slave)) { + setUnknownParents(slave, {mother: V.activeSlave.ID} ); } } break; } case "father": { - eventSlave.father = V.activeSlave.ID; + setUnknownParents(eventSlave, {father: V.activeSlave.ID} ); for (const slave of V.slaves) { - if (sameMom(eventSlave, slave) && slave.father === 0) { - slave.father = V.activeSlave.ID; + if (sameMom(eventSlave, slave)) { + setUnknownParents(slave, {father: V.activeSlave.ID} ); } } break; @@ -607,22 +630,21 @@ App.Events.RERelativeRecruiter = class RERelativeRecruiter extends App.Events.Ba case "twin": { // siblings if (eventSlave.father === 0 && eventSlave.mother === 0) { setMissingParents(eventSlave); - V.activeSlave.mother = eventSlave.mother; - V.activeSlave.father = eventSlave.father; + setUnknownParents(V.activeSlave, {mother: eventSlave.mother, father: eventSlave.father}); } else if (eventSlave.father === 0) { setMissingParents(eventSlave); - V.activeSlave.father = eventSlave.father; + setUnknownParents(V.activeSlave, {father: eventSlave.father}); for (const slave of V.slaves) { - if (sameMom(eventSlave, slave) && slave.father === 0) { - slave.father = eventSlave.father; + if (sameMom(eventSlave, slave)) { + setUnknownParents(slave, {father: eventSlave.father}); } } } else if (eventSlave.mother === 0) { setMissingParents(eventSlave); - V.activeSlave.mother = eventSlave.mother; + setUnknownParents(V.activeSlave, {mother: eventSlave.mother}); for (const slave of V.slaves) { - if (sameDad(eventSlave, slave) && slave.mother === 0) { - slave.mother = eventSlave.mother; + if (sameDad(eventSlave, slave)) { + setUnknownParents(slave, {mother: eventSlave.mother}); } } } diff --git a/src/js/extendedFamilyModeJS.js b/src/js/extendedFamilyModeJS.js index 9ab734dfd28864e16f266cb1827f00fe78e56243..295089ca36ed41c110c7b6d556642c55cc3b1c29 100644 --- a/src/js/extendedFamilyModeJS.js +++ b/src/js/extendedFamilyModeJS.js @@ -514,12 +514,19 @@ globalThis.resetFamilyCounters = function() { * @param {Relative} slave */ globalThis.setMissingParents = function(slave) { + const gp = V.genePool.find(s => s.ID === slave.ID); if (!specificMom(slave)) { slave.mother = V.missingParentID; + if (gp) { + gp.mother = slave.mother; + } V.missingParentID--; } if (!specificDad(slave)) { slave.father = V.missingParentID; + if (gp) { + gp.mother = slave.mother; + } V.missingParentID--; } };