mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
v1.3.48
This commit is contained in:
parent
12a96938d2
commit
d7a12fe97e
5 changed files with 69 additions and 37 deletions
|
|
@ -7,9 +7,9 @@
|
|||
let chains = [];
|
||||
|
||||
// calculate Markov chain for a namesbase
|
||||
const calculateChain = function(b) {
|
||||
const calculateChain = function(string) {
|
||||
const chain = [];
|
||||
const d = nameBases[b].b.toLowerCase().replace(/,/g, " ");
|
||||
const d = string.toLowerCase().replace(/,/g, " ");
|
||||
|
||||
for (let i = -1, str = ""; i < d.length - 2; i += str.length, str = "") {
|
||||
let v = 0, f = " ";
|
||||
|
|
@ -33,7 +33,7 @@
|
|||
}
|
||||
|
||||
// update chain for specific base
|
||||
const updateChain = (i) => chains[i] = nameBases[i] || nameBases[i].b ? calculateChain(i) : null;
|
||||
const updateChain = (i) => chains[i] = nameBases[i] || nameBases[i].b ? calculateChain(nameBases[i].b) : null;
|
||||
|
||||
// update chains for all used bases
|
||||
const clearChains = () => chains = [];
|
||||
|
|
@ -67,7 +67,7 @@
|
|||
cur = "";
|
||||
v = data[" "];
|
||||
} else {
|
||||
v = data[cur.slice(-1)];
|
||||
v = data[cur.slice(-1)] || data[" "];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -255,5 +255,5 @@
|
|||
];
|
||||
}
|
||||
|
||||
return {getBase, getCulture, getCultureShort, getBaseShort, getState, updateChain, clearChains, getNameBases, getMapName};
|
||||
return {getBase, getCulture, getCultureShort, getBaseShort, getState, updateChain, clearChains, getNameBases, getMapName, calculateChain};
|
||||
})));
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ function editNamesbase() {
|
|||
document.getElementById("namesbaseDouble").addEventListener("input", updateBaseDublication);
|
||||
document.getElementById("namesbaseMulti").addEventListener("input", updateBaseMiltiwordRate);
|
||||
document.getElementById("namesbaseAdd").addEventListener("click", namesbaseAdd);
|
||||
document.getElementById("namesbaseAnalize").addEventListener("click", analizeNamesbase);
|
||||
document.getElementById("namesbaseDefault").addEventListener("click", namesbaseRestoreDefault);
|
||||
document.getElementById("namesbaseDownload").addEventListener("click", namesbaseDownload);
|
||||
document.getElementById("namesbaseUpload").addEventListener("click", () => namesbaseToLoad.click());
|
||||
|
|
@ -105,7 +106,63 @@ function editNamesbase() {
|
|||
const base = +document.getElementById("namesbaseSelect").value;
|
||||
nameBases[base].m = +this.value;
|
||||
}
|
||||
|
||||
|
||||
function analizeNamesbase() {
|
||||
const string = document.getElementById("namesbaseTextarea").value;
|
||||
if (!string) {tip("Names data field should not be empty", false, "error"); return;}
|
||||
const base = string.toLowerCase();
|
||||
const array = base.split(",");
|
||||
const l = array.length;
|
||||
if (!l) {tip("Names data should not be empty", false, "error"); return;}
|
||||
|
||||
const wordsLength = array.map(n => n.length);
|
||||
const multi = rn(d3.mean(array.map(n => (n.match(/ /i)||[]).length)) * 100, 2);
|
||||
const geminate = array.map(name => name.match(/[^\w\s]|(.)(?=\1)/g)||[]).flat();
|
||||
const doubled = ([...new Set(geminate)].filter(l => geminate.filter(d => d === l).length > 3)||["none"]).join("");
|
||||
const chain = Names.calculateChain(string);
|
||||
const depth = rn(d3.mean(Object.keys(chain).map(key => chain[key].filter(c => c !== " ").length)));
|
||||
const nonLatin = (string.match(/[^\u0000-\u007f]/g)||["none"]).join("");
|
||||
|
||||
const lengthStat =
|
||||
l < 30 ? "<span style='color:red'>[not enough]</span>" :
|
||||
l < 150 ? "<span style='color:darkred'>[low]</span>" :
|
||||
l < 150 ? "<span style='color:orange'>[low]</span>" :
|
||||
l < 400 ? "<span style='color:green'>[good]</span>" :
|
||||
l < 600 ? "<span style='color:orange'>[overmuch]</span>" :
|
||||
"<span style='color:darkred'>[overmuch]</span>";
|
||||
|
||||
const rangeStat =
|
||||
l < 10 ? "<span style='color:red'>[low]</span>" :
|
||||
l < 15 ? "<span style='color:darkred'>[low]</span>" :
|
||||
l < 20 ? "<span style='color:orange'>[low]</span>" :
|
||||
"<span style='color:green'>[good]</span>";
|
||||
|
||||
const depthStat =
|
||||
l < 15 ? "<span style='color:red'>[low]</span>" :
|
||||
l < 20 ? "<span style='color:darkred'>[low]</span>" :
|
||||
l < 25 ? "<span style='color:orange'>[low]</span>" :
|
||||
"<span style='color:green'>[good]</span>";
|
||||
|
||||
alertMessage.innerHTML = `<div style="line-height: 1.6em; max-width: 20em">
|
||||
<div>Namesnase length: ${l} ${lengthStat}</div>
|
||||
<div>Namesbase range: ${Object.keys(chain).length-1} ${rangeStat}</div>
|
||||
<div>Namesbase depth: ${depth} ${depthStat}</div>
|
||||
<div>Non-basic chars: ${nonLatin}</div>
|
||||
<hr>
|
||||
<div>Min name length: ${d3.min(wordsLength)}</div>
|
||||
<div>Max name length: ${d3.max(wordsLength)}</div>
|
||||
<div>Mean name length: ${rn(d3.mean(wordsLength), 1)}</div>
|
||||
<div>Median name length: ${d3.median(wordsLength)}</div>
|
||||
<div>Doubled chars: ${doubled}</div>
|
||||
<div>Multi-word names: ${multi}%</div>
|
||||
</div>`;
|
||||
$("#alert").dialog({
|
||||
resizable: false, title: "Data Analysis",
|
||||
position: {my: "left top-30", at: "right+10 top", of: "#namesbaseEditor"},
|
||||
buttons: {OK: function() {$(this).dialog("close");}}
|
||||
});
|
||||
}
|
||||
|
||||
function namesbaseAdd() {
|
||||
const base = nameBases.length;
|
||||
const b = "This,is,an,example,of,name,base,showing,correct,format,It,should,have,at,least,one,hundred,names,separated,with,comma";
|
||||
|
|
|
|||
|
|
@ -470,34 +470,6 @@ function getNumberInRange(r) {
|
|||
return count;
|
||||
}
|
||||
|
||||
// helper function non-used for the generation
|
||||
function analizeNamesbase() {
|
||||
const result = [];
|
||||
nameBases.forEach((b,i) => {
|
||||
const string = nameBases[i].b;
|
||||
const d = string.split(",");
|
||||
const size = d.length;
|
||||
const ar = d.map(n => n.length);
|
||||
const min = d3.min(ar);
|
||||
const max = d3.max(ar);
|
||||
const mean = rn(d3.mean(ar), 1);
|
||||
const median = d3.median(ar);
|
||||
const lengths = new Uint8Array(max);
|
||||
ar.forEach(l => lengths[l]++);
|
||||
const common = d3.scan(lengths, (a,b) => b-a);
|
||||
const doubleArray = [];
|
||||
let double = "";
|
||||
for (let i=0; i<string.length; i++) {
|
||||
if (!doubleArray[string[i]]) doubleArray[string[i]] = 0;
|
||||
if (string[i] === string[i-1]) doubleArray[string[i]]++;
|
||||
}
|
||||
for (const l in doubleArray) {if(doubleArray[l] > size/35) double += l;}
|
||||
const multi = rn(d3.mean(d.map(n => (n.match(/ /g)||[]).length-1)),2);
|
||||
result.push({name:b.name, size, min, max, mean, median, common, double, multi});
|
||||
});
|
||||
console.table(result);
|
||||
}
|
||||
|
||||
// helper function non-used for the generation
|
||||
function drawCellsValue(data) {
|
||||
debug.selectAll("text").remove();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue