mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
* bioms shouldn't be masked or the style selection box is useless * fix: misleading comment * experimental submapping feature * burg remapping * Submap with options * Fix: calculating absolute flux from precipitation normal-value. * effective distanceScale * updated resampler * fix: missing cell * Fix: River automatic rerender on regeneration. * FIX: wrong culture migration * fixed 0 index burg bug, more accurate coast detection for burgs * FIX: wrong burg cell id * fix invalid feature number at burg.ports, option to disable regenerations * Relocate submap * update height model and scale parameters * new menu * Dropbox OAuth implementation and Cloud framework * add some space * removing uneccesary logs, defer script load * map position on planet, fix wrong riverbed generation * fix:riverbed generation * better cell sampler * Auto-Smoothing,dist fix * FIX: incorrect province copy and minor fix of rebels * Cleanup * FIX: water detection bug * Recompute centers (states, cultures, provinces) * activating forwardmap * FIX: port burg relocation algo * FIX: coast detection (for burgs) * Fix: invalid html id * add dot * update for FMG 1.73 * Update submap gui * refactored submap ui options * Copy all visible military units from the old map. * add info text * Add Markers.deleteMarker API. * Lock markers and lock burgs options * better comment * submapper gui updates, remove feature mapping on/off * Fix typo (thx evolvedexperiment) * fix ugly GUI (2 digit roundoff) * resample dialog * Town Promotion to largetown * don't promote to capitals. * Fix typo * round style settings * do not draw removed burgs * Fix port cell search algo * Fix: robust error handling, no error for 0. * submap: projection moved to options, fix double burg error * complete rewrite of burg relocation * findcell by coordinates * prepare to merge, add comments, remove fluff * replacing lodash with deepCopy implementation Co-authored-by: Mészáros Gergely <monk@geotronic.hu>
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
"use strict";
|
|
// FMG utils related to arrays
|
|
|
|
// return the last element of array
|
|
function last(array) {
|
|
return array[array.length - 1];
|
|
}
|
|
|
|
// return array of values common for both array a and array b
|
|
function common(a, b) {
|
|
const setB = new Set(b);
|
|
return [...new Set(a)].filter(a => setB.has(a));
|
|
}
|
|
|
|
function unique(array) {
|
|
return [...new Set(array)];
|
|
}
|
|
|
|
// deep copy for Arrays (and other objects)
|
|
function deepCopy(obj) {
|
|
const id = x=>x;
|
|
const dcTArray = a => a.map(id);
|
|
const dcObject = x => Object.fromEntries(Object.entries(x).map(([k,d])=>[k,dcAny(d)]));
|
|
const dcAny = x => x instanceof Object ? (cf.get(x.constructor)||id)(x) : x;
|
|
// don't map keys, probably this is what we would expect
|
|
const dcMapCore = m => [...m.entries()].map(([k,v])=>[k, dcAny(v)]);
|
|
|
|
const cf = new Map([
|
|
[Int8Array, dcTArray],
|
|
[Uint8Array, dcTArray],
|
|
[Uint8ClampedArray, dcTArray],
|
|
[Int16Array, dcTArray],
|
|
[Uint16Array, dcTArray],
|
|
[Int32Array, dcTArray],
|
|
[Uint32Array, dcTArray],
|
|
[Float32Array, dcTArray],
|
|
[Float64Array, dcTArray],
|
|
[BigInt64Array, dcTArray],
|
|
[BigUint64Array, dcTArray],
|
|
[Map, m => new Map(dcMapCore(m))],
|
|
[WeakMap, m => new WeakMap(dcMapCore(m))],
|
|
[Array, a => a.map(dcAny)],
|
|
[Set, s => [...s.values()].map(dcAny)],
|
|
[Date, d => new Date(d.getTime())],
|
|
[Object, dcObject],
|
|
// other types will be referenced
|
|
// ... extend here to implement their custom deep copy
|
|
]);
|
|
|
|
return dcAny(obj);
|
|
}
|