diff --git a/index.html b/index.html index 3d7f4b33..cb428e3a 100644 --- a/index.html +++ b/index.html @@ -7845,7 +7845,7 @@ - + diff --git a/modules/cultures-generator.js b/modules/cultures-generator.js index 90f93d69..271fa055 100644 --- a/modules/cultures-generator.js +++ b/modules/cultures-generator.js @@ -127,6 +127,27 @@ window.Cultures = (function () { pack.cultures?.forEach(function (culture) { if (culture.lock) cultures.push(culture); }); + if(pack.religions?.length){ + const religMap=[]; + pack.religions.forEach(r => religMap.push(r.type === "Folk" ? 0 : r.i)); // remove folk religions in general + for(const j = 0; j < cultures.length; j++) { // locked cultures save their folk religions, at the new id + const k = j+1; + religMap[cultures[j].i] = k; + }); + for(const i of cells.i){ + cells.religion[i] = religMap[cells.religion[i]]; + } + for(const i = 0; i < religMap.length; i++){ + // update origin heirarchy to the new ids + pack.religions[i].origins = pack.religions[i].origins.map(i => religMap[i]).filter(i => i); + if(religMap[i] !== i){ + if(religMap[i] !== 0) + pack.religions[religMap[i]] = pack.religions[i]; + // folk religions for unlocked cultures are removed pending regeneration + pack.religions[i].removed = true; + } + } + } for (let culture, rnd, i = 0; cultures.length < count && i < 200; i++) { do { diff --git a/modules/dynamic/editors/religions-editor.js b/modules/dynamic/editors/religions-editor.js index 5e525c55..bf36e3d5 100644 --- a/modules/dynamic/editors/religions-editor.js +++ b/modules/dynamic/editors/religions-editor.js @@ -536,7 +536,7 @@ function drawReligionCenters() { .attr("stroke", "#444444") .style("cursor", "move"); - const data = pack.religions.filter(r => r.i && r.center && r.cells && !r.removed); + const data = pack.religions.filter(r => r.i && r.center && !r.type==="Folk" && !r.removed); religionCenters .selectAll("circle") .data(data) diff --git a/modules/religions-generator.js b/modules/religions-generator.js index 78ce1f16..dfe6a902 100644 --- a/modules/religions-generator.js +++ b/modules/religions-generator.js @@ -758,25 +758,26 @@ window.Religions = (function () { code }; - if(religions[c.i]){ - let rCargo = religions[c.i]; - if(rCargo.type === "Folk") return; - const newId = religions.length; - rCargo.i = newId; - for(const i of cells.i) { - if(cells.religion[i] = c.i) { - cells.religion[i] = newId; - } - } - religions.forEach(r => { - for(let j = 0; j < r.origins.length; j++) { - if(r.origins[j] === c.i) { - r.origins[j] === newid; - return; + if(c.i < religions.length){ + const rCargo = religions[c.i]; + if(!rCargo.removed) { + const newId = religions.length; + rCargo.i = newId; + for(const i of cells.i) { + if(cells.religion[i] = c.i) { + cells.religion[i] = newId; } } - }); - religions.push(rCargo); + religions.forEach(r => { + for(let j = 0; j < r.origins.length; j++) { + if(r.origins[j] === c.i) { + r.origins[j] === newid; + return; + } + } + }); + religions.push(rCargo); + } religions[c.i] = newFolk; } else { religions.push(newFolk); @@ -785,11 +786,14 @@ window.Religions = (function () { function updateCultures() { TIME && console.time("updateCulturesForReligions"); - pack.religions = pack.religions.map((religion, index) => { - if (index === 0) { - return religion; + pack.religions.forEach(r => { + if(r.i === 0) return; + if(!r.origins.length) r.origins = [0]; + if(r.type === "Folk"){ + if(r.removed) addFolk(pack.cultures[r.i].center); // regnerate folk religions for the regenerated cultures + else r.center = pack.cultures[r.i].center; } - return {...religion, culture: pack.cells.culture[religion.center]}; + else r.culture = pack.cells.culture[r.center]; }); TIME && console.timeEnd("updateCulturesForReligions"); }