mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
fix: uploadCulturesData
This commit is contained in:
parent
4e884b10ee
commit
14ac83e6f5
5 changed files with 32 additions and 41 deletions
|
|
@ -8063,7 +8063,7 @@
|
||||||
|
|
||||||
<script defer src="modules/relief-icons.js"></script>
|
<script defer src="modules/relief-icons.js"></script>
|
||||||
<script defer src="modules/ui/style.js?v=1.96.00"></script>
|
<script defer src="modules/ui/style.js?v=1.96.00"></script>
|
||||||
<script defer src="modules/ui/editors.js?v=1.96.00"></script>
|
<script defer src="modules/ui/editors.js?v=1.96.01"></script>
|
||||||
<script defer src="modules/ui/tools.js?v=1.95.01"></script>
|
<script defer src="modules/ui/tools.js?v=1.95.01"></script>
|
||||||
<script defer src="modules/ui/world-configurator.js?v=1.91.05"></script>
|
<script defer src="modules/ui/world-configurator.js?v=1.91.05"></script>
|
||||||
<script defer src="modules/ui/heightmap-editor.js?v=1.96.00"></script>
|
<script defer src="modules/ui/heightmap-editor.js?v=1.96.00"></script>
|
||||||
|
|
|
||||||
|
|
@ -857,8 +857,19 @@ function closeCulturesEditor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadCulturesData() {
|
async function uploadCulturesData() {
|
||||||
const csv = await Formats.csvParser(this.files[0]);
|
const file = this.files[0];
|
||||||
this.value = "";
|
this.value = "";
|
||||||
|
const csv = await file.text();
|
||||||
|
const data = d3.csvParse(csv, d => ({
|
||||||
|
i: +d.Id,
|
||||||
|
name: d.Name,
|
||||||
|
color: d.Color,
|
||||||
|
expansionism: +d.Expansionism,
|
||||||
|
type: d.Type,
|
||||||
|
population: +d.Population,
|
||||||
|
emblemsShape: d["Emblems Shape"],
|
||||||
|
origins: d.Origins
|
||||||
|
}));
|
||||||
|
|
||||||
const {cultures, cells} = pack;
|
const {cultures, cells} = pack;
|
||||||
const shapes = Object.keys(COA.shields.types)
|
const shapes = Object.keys(COA.shields.types)
|
||||||
|
|
@ -870,20 +881,26 @@ async function uploadCulturesData() {
|
||||||
if (item.i) item.removed = true;
|
if (item.i) item.removed = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const c of csv.iterator((a, b) => +a[0] > +b[0])) {
|
for (const culture of data) {
|
||||||
let current;
|
let current;
|
||||||
if (+c.id < cultures.length) {
|
if (culture.i < cultures.length) {
|
||||||
current = cultures[c.id];
|
current = cultures[culture.i];
|
||||||
|
|
||||||
const ratio = current.urban / (current.rural + current.urban);
|
const ratio = current.urban / (current.rural + current.urban);
|
||||||
applyPopulationChange(current.rural, current.urban, c.population * (1 - ratio), c.population * ratio, +c.id);
|
applyPopulationChange(
|
||||||
|
current.rural,
|
||||||
|
current.urban,
|
||||||
|
culture.population * (1 - ratio),
|
||||||
|
culture.population * ratio,
|
||||||
|
culture.i
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
current = {i: cultures.length, center: ra(populated), area: 0, cells: 0, origin: 0, rural: 0, urban: 0};
|
current = {i: cultures.length, center: ra(populated), area: 0, cells: 0, origin: 0, rural: 0, urban: 0};
|
||||||
cultures.push(current);
|
cultures.push(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
current.removed = false;
|
current.removed = false;
|
||||||
current.name = c.name;
|
current.name = culture.name;
|
||||||
|
|
||||||
if (current.i) {
|
if (current.i) {
|
||||||
current.code = abbreviate(
|
current.code = abbreviate(
|
||||||
|
|
@ -891,10 +908,10 @@ async function uploadCulturesData() {
|
||||||
cultures.map(c => c.code)
|
cultures.map(c => c.code)
|
||||||
);
|
);
|
||||||
|
|
||||||
current.color = c.color;
|
current.color = culture.color;
|
||||||
current.expansionism = +c.expansionism;
|
current.expansionism = +culture.expansionism;
|
||||||
|
|
||||||
if (cultureTypes.includes(c.type)) current.type = c.type;
|
if (cultureTypes.includes(culture.type)) current.type = culture.type;
|
||||||
else current.type = "Generic";
|
else current.type = "Generic";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -913,13 +930,11 @@ async function uploadCulturesData() {
|
||||||
current.origins = originIds.filter(id => id !== null);
|
current.origins = originIds.filter(id => id !== null);
|
||||||
if (!current.origins.length) current.origins = [0];
|
if (!current.origins.length) current.origins = [0];
|
||||||
}
|
}
|
||||||
c.origins = current.i ? restoreOrigins(c.origins) : [null];
|
|
||||||
|
|
||||||
const shieldShape = c["emblems shape"].toLowerCase();
|
culture.origins = current.i ? restoreOrigins(culture.origins || "") : [null];
|
||||||
if (shapes.includes(shieldShape)) current.shield = shieldShape;
|
current.shield = shapes.includes(culture.emblemsShape) ? culture.emblemsShape : "heater";
|
||||||
else current.shield = "heater";
|
|
||||||
|
|
||||||
const nameBaseIndex = nameBases.findIndex(n => n.name == c.namesbase);
|
const nameBaseIndex = nameBases.findIndex(n => n.name == culture.namesbase);
|
||||||
current.base = nameBaseIndex === -1 ? 0 : nameBaseIndex;
|
current.base = nameBaseIndex === -1 ? 0 : nameBaseIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
"use strict";
|
|
||||||
|
|
||||||
window.Formats = (function () {
|
|
||||||
async function csvParser(file, separator = ",") {
|
|
||||||
const txt = await file.text();
|
|
||||||
const rows = txt.split("\n");
|
|
||||||
const headers = rows
|
|
||||||
.shift()
|
|
||||||
.split(separator)
|
|
||||||
.map(x => x.toLowerCase());
|
|
||||||
const data = rows.filter(a => a.trim() !== "").map(r => r.split(separator));
|
|
||||||
|
|
||||||
return {
|
|
||||||
headers,
|
|
||||||
data,
|
|
||||||
iterator: function* (sortf) {
|
|
||||||
const dataset = sortf ? this.data.sort(sortf) : this.data;
|
|
||||||
for (const d of dataset) yield Object.fromEntries(d.map((a, i) => [this.headers[i], a]));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {csvParser};
|
|
||||||
})();
|
|
||||||
|
|
@ -1182,7 +1182,7 @@ async function editStates() {
|
||||||
|
|
||||||
async function editCultures() {
|
async function editCultures() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
const Editor = await import("../dynamic/editors/cultures-editor.js?v=1.96.00");
|
const Editor = await import("../dynamic/editors/cultures-editor.js?v=1.96.01");
|
||||||
Editor.open();
|
Editor.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// version and caching control
|
// version and caching control
|
||||||
const version = "1.96.00"; // generator version, update each time
|
const version = "1.96.01"; // generator version, update each time
|
||||||
|
|
||||||
{
|
{
|
||||||
document.title += " v" + version;
|
document.title += " v" + version;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue