diff --git a/src/js/ibcJS.js b/src/js/ibcJS.js index 80321e2341c459042c0f665e85e2857a5c98d99e..95129e4b9c0de365a85edd8a3b61effd23334238 100644 --- a/src/js/ibcJS.js +++ b/src/js/ibcJS.js @@ -1,7 +1,7 @@ window.ibc = (() => { // These IDs are considered to be unknown parents - let null_ids = [0, -2, -4, -5, -6, -7, -9]; - let or_null = (s) => (null_ids.contains(s)) ? null : s; + let or_null = (s) => specificCharacterID(s) ? s : null; + let find_gp = (id) => (slaveStateById(id) || genePool.find((s) => s.ID == id) || null); // Create a node for the given ID let create_node = (id) => ({ @@ -242,7 +242,7 @@ window.ibc = (() => { } else if (p < 0) { nodes[p] = create_node(p); } else { - create_node_rec(SugarCube.State.variables.slaves[SugarCube.State.variables.slaveIndices[p]]); + create_node_rec(find_gp(p)); } } }); @@ -252,8 +252,9 @@ window.ibc = (() => { nodes[s.ID].mother = (m === null) ? m : nodes[m]; nodes[s.ID].father = (f === null) ? f : nodes[f]; - if ("inbreedingCoeff" in s && s.inbreedingCoeff !== -1) { - nodes[s.ID]._coeff = s.inbreedingCoeff; + let sg = find_gp(s.ID); + if ("inbreedingCoeff" in sg && sg.inbreedingCoeff !== -1) { + nodes[s.ID]._coeff = sg.inbreedingCoeff; } }; @@ -280,7 +281,7 @@ window.ibc = (() => { Object.keys(nodes).forEach(s => { let n = nodes[s]; if (n.id in SugarCube.State.variables.slaveIndices) { - let slave = SugarCube.State.variables.slaves[SugarCube.State.variables.slaveIndices[n.id]]; + let slave = find_gp(n.id); if (!("inbreedingCoeff" in slave) || slave.inbreedingCoeff === -1) { slave.inbreedingCoeff = n._coeff; }