From 4c0abf466a303a7f8a6d8479b007948d0c9b729c Mon Sep 17 00:00:00 2001
From: Empress Sela <empresssela@cock.li>
Date: Tue, 7 Jul 2020 23:19:57 -0400
Subject: [PATCH] Fixes

- Fix reference to genePool
- Prioritize genePool records over slave records when reusing CoI
- Don't automatically store values to genepool; do this elsewhere
---
 src/js/ibcJS.js | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/src/js/ibcJS.js b/src/js/ibcJS.js
index 95129e4b9c0..b34126251aa 100644
--- a/src/js/ibcJS.js
+++ b/src/js/ibcJS.js
@@ -1,7 +1,7 @@
-window.ibc = (() => {
+globalThis.ibc = (() => {
     // These IDs are considered to be unknown parents
     let or_null = (s) => specificCharacterID(s) ? s : null;
-    let find_gp = (id) => (slaveStateById(id) || genePool.find((s) => s.ID == id) || null);
+    let find_gp = (id) => (SugarCube.State.variables.genePool.find((s) => s.ID == id) || slaveStateById(id) || null);
 
     // Create a node for the given ID
     let create_node = (id) => ({
@@ -253,7 +253,8 @@ window.ibc = (() => {
             nodes[s.ID].father = (f === null) ? f : nodes[f];
 
             let sg = find_gp(s.ID);
-            if ("inbreedingCoeff" in sg && sg.inbreedingCoeff !== -1) {
+            if (sg !== null && "inbreedingCoeff" in sg && sg.inbreedingCoeff !== -1) {
+                console.log("Found "+s.ID);
                 nodes[s.ID]._coeff = sg.inbreedingCoeff;
             }
         };
@@ -278,16 +279,6 @@ window.ibc = (() => {
             ret[s.ID] = coeff(nodes[s.ID]);
         });
 
-        Object.keys(nodes).forEach(s => {
-            let n = nodes[s];
-            if (n.id in SugarCube.State.variables.slaveIndices) {
-                let slave = find_gp(n.id);
-                if (!("inbreedingCoeff" in slave) || slave.inbreedingCoeff === -1) {
-                    slave.inbreedingCoeff = n._coeff;
-                }
-            }
-        });
-
         return ret;
     };
 
-- 
GitLab