mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
v1.3.48
This commit is contained in:
parent
12a96938d2
commit
d7a12fe97e
5 changed files with 69 additions and 37 deletions
|
|
@ -44,6 +44,8 @@ input:read-only {
|
||||||
textarea {
|
textarea {
|
||||||
padding: 2px;
|
padding: 2px;
|
||||||
text-indent: 1px;
|
text-indent: 1px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#map {
|
#map {
|
||||||
|
|
|
||||||
|
|
@ -2964,7 +2964,7 @@
|
||||||
|
|
||||||
<div id="namesbaseBody">
|
<div id="namesbaseBody">
|
||||||
<span>Names data:</span><br>
|
<span>Names data:</span><br>
|
||||||
<textarea id="namesbaseTextarea" data-base="0" cols=70 rows=12 data-tip="Names data: a comma separated list of source names used for names generation" placeholder="Provide a names data: a comma separated list of source names" autocorrect="off" spellcheck="false"></textarea>
|
<textarea id="namesbaseTextarea" data-base="0" rows=12 data-tip="Names data: a comma separated list of source names used for names generation" placeholder="Provide a names data: a comma separated list of source names" autocorrect="off" spellcheck="false"></textarea>
|
||||||
<br>
|
<br>
|
||||||
<div>
|
<div>
|
||||||
<span>Name: </span>
|
<span>Name: </span>
|
||||||
|
|
@ -2985,6 +2985,7 @@
|
||||||
|
|
||||||
<div id="namesbaseBottom">
|
<div id="namesbaseBottom">
|
||||||
<button id="namesbaseUpdateExamples" data-tip="Re-generate examples based on provided data" class="icon-arrows-cw"></button>
|
<button id="namesbaseUpdateExamples" data-tip="Re-generate examples based on provided data" class="icon-arrows-cw"></button>
|
||||||
|
<button id="namesbaseAnalize" data-tip="Analize namesbase to get a validity and quality overview" class="icon-flask"></button>
|
||||||
<button id="namesbaseAdd" data-tip="Add new namesbase" class="icon-plus"></button>
|
<button id="namesbaseAdd" data-tip="Add new namesbase" class="icon-plus"></button>
|
||||||
<button id="namesbaseDefault" data-tip="Restore default namesbase" class="icon-cancel"></button>
|
<button id="namesbaseDefault" data-tip="Restore default namesbase" class="icon-cancel"></button>
|
||||||
<button id="namesbaseDownload" data-tip="Download namesbase to PC" class="icon-download"></button>
|
<button id="namesbaseDownload" data-tip="Download namesbase to PC" class="icon-download"></button>
|
||||||
|
|
@ -3041,7 +3042,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span>Legend:</span><br>
|
<span>Legend:</span><br>
|
||||||
<textarea id="notesText" cols="70" rows="7" data-tip="Type object description" placeholder="Type object description"></textarea>
|
<textarea id="notesText" rows="7" data-tip="Type object description" placeholder="Type object description"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button id="notesFocus" data-tip="Focus on selected object" class="icon-target"></button>
|
<button id="notesFocus" data-tip="Focus on selected object" class="icon-target"></button>
|
||||||
|
|
@ -3350,7 +3351,7 @@
|
||||||
|
|
||||||
<div id="styleSaverBody" style="padding:2px 0">
|
<div id="styleSaverBody" style="padding:2px 0">
|
||||||
<span>Style JSON:</span>
|
<span>Style JSON:</span>
|
||||||
<textarea id="styleSaverJSON" cols="40" rows="18" data-tip="Style JSON is getting formed based the current settings, but can be entered manually" placeholder="Paste any valid style data in JSON format" autocorrect="off" spellcheck="false"></textarea>
|
<textarea id="styleSaverJSON" rows="18" data-tip="Style JSON is getting formed based the current settings, but can be entered manually" placeholder="Paste any valid style data in JSON format" autocorrect="off" spellcheck="false"></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="styleSaverBottom">
|
<div id="styleSaverBottom">
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@
|
||||||
let chains = [];
|
let chains = [];
|
||||||
|
|
||||||
// calculate Markov chain for a namesbase
|
// calculate Markov chain for a namesbase
|
||||||
const calculateChain = function(b) {
|
const calculateChain = function(string) {
|
||||||
const chain = [];
|
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 = "") {
|
for (let i = -1, str = ""; i < d.length - 2; i += str.length, str = "") {
|
||||||
let v = 0, f = " ";
|
let v = 0, f = " ";
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// update chain for specific base
|
// 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
|
// update chains for all used bases
|
||||||
const clearChains = () => chains = [];
|
const clearChains = () => chains = [];
|
||||||
|
|
@ -67,7 +67,7 @@
|
||||||
cur = "";
|
cur = "";
|
||||||
v = data[" "];
|
v = data[" "];
|
||||||
} else {
|
} 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("namesbaseDouble").addEventListener("input", updateBaseDublication);
|
||||||
document.getElementById("namesbaseMulti").addEventListener("input", updateBaseMiltiwordRate);
|
document.getElementById("namesbaseMulti").addEventListener("input", updateBaseMiltiwordRate);
|
||||||
document.getElementById("namesbaseAdd").addEventListener("click", namesbaseAdd);
|
document.getElementById("namesbaseAdd").addEventListener("click", namesbaseAdd);
|
||||||
|
document.getElementById("namesbaseAnalize").addEventListener("click", analizeNamesbase);
|
||||||
document.getElementById("namesbaseDefault").addEventListener("click", namesbaseRestoreDefault);
|
document.getElementById("namesbaseDefault").addEventListener("click", namesbaseRestoreDefault);
|
||||||
document.getElementById("namesbaseDownload").addEventListener("click", namesbaseDownload);
|
document.getElementById("namesbaseDownload").addEventListener("click", namesbaseDownload);
|
||||||
document.getElementById("namesbaseUpload").addEventListener("click", () => namesbaseToLoad.click());
|
document.getElementById("namesbaseUpload").addEventListener("click", () => namesbaseToLoad.click());
|
||||||
|
|
@ -105,7 +106,63 @@ function editNamesbase() {
|
||||||
const base = +document.getElementById("namesbaseSelect").value;
|
const base = +document.getElementById("namesbaseSelect").value;
|
||||||
nameBases[base].m = +this.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() {
|
function namesbaseAdd() {
|
||||||
const base = nameBases.length;
|
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";
|
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;
|
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
|
// helper function non-used for the generation
|
||||||
function drawCellsValue(data) {
|
function drawCellsValue(data) {
|
||||||
debug.selectAll("text").remove();
|
debug.selectAll("text").remove();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue