mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-21 19:41:23 +01:00
Load map before generation
This commit is contained in:
parent
13ad4f941c
commit
b9831bcf45
2 changed files with 26 additions and 39 deletions
45
script.js
45
script.js
|
|
@ -19,19 +19,8 @@
|
||||||
// Use typed arrays instead of array of objects
|
// Use typed arrays instead of array of objects
|
||||||
// Get rid of jQuery as d3.js can almost all the same and more
|
// Get rid of jQuery as d3.js can almost all the same and more
|
||||||
// Re-build UI on reactive approach, vue.js
|
// Re-build UI on reactive approach, vue.js
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function loadScript(path) {
|
|
||||||
const script = document.createElement("script");
|
|
||||||
script.addEventListener("load", () => {
|
|
||||||
fantasyMap();
|
|
||||||
});
|
|
||||||
script.src = path;
|
|
||||||
document.body.appendChild(script);
|
|
||||||
}
|
|
||||||
|
|
||||||
loadScript("./src/loadMapFromUrl.js");
|
|
||||||
|
|
||||||
|
fantasyMap();
|
||||||
function fantasyMap() {
|
function fantasyMap() {
|
||||||
// Version control
|
// Version control
|
||||||
const version = "0.60b";
|
const version = "0.60b";
|
||||||
|
|
@ -276,13 +265,24 @@ function fantasyMap() {
|
||||||
}
|
}
|
||||||
|
|
||||||
getSeed(); // get and set random generator seed
|
getSeed(); // get and set random generator seed
|
||||||
applyNamesData(); // apply default namesbase on load
|
|
||||||
generate(); // generate map on load
|
|
||||||
applyDefaultStyle(); // apply style on load
|
|
||||||
focusOn(); // based on searchParams focus on point, cell or burg from MFCG
|
|
||||||
invokeActiveZooming(); // to hide what need to be hidden
|
|
||||||
|
|
||||||
loadMapFromUrl(uploadFile);
|
const mapLink = params.get("maplink");
|
||||||
|
if (mapLink) {
|
||||||
|
// set up global state
|
||||||
|
applyMapSize();
|
||||||
|
placePoints();
|
||||||
|
calculateVoronoi(points);
|
||||||
|
|
||||||
|
makeFileFromUrl(decodeURIComponent(mapLink)).then(blob => {
|
||||||
|
uploadFile(blob);
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
applyNamesData(); // apply default namesbase on load
|
||||||
|
generate(); // generate map on load
|
||||||
|
applyDefaultStyle(); // apply style on load
|
||||||
|
focusOn(); // based on searchParams focus on point, cell or burg from MFCG
|
||||||
|
invokeActiveZooming(); // to hide what need to be hidden
|
||||||
|
}
|
||||||
|
|
||||||
function generate() {
|
function generate() {
|
||||||
console.group("Random map");
|
console.group("Random map");
|
||||||
|
|
@ -6820,6 +6820,13 @@ function fantasyMap() {
|
||||||
uploadFile(fileToLoad);
|
uploadFile(fileToLoad);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function makeFileFromUrl(mapLink) {
|
||||||
|
return fetch(mapLink, {
|
||||||
|
method: 'GET',
|
||||||
|
mode: 'cors',
|
||||||
|
}).then(response => response.blob());
|
||||||
|
}
|
||||||
|
|
||||||
function uploadFile(file, callback) {
|
function uploadFile(file, callback) {
|
||||||
console.time("loadMap");
|
console.time("loadMap");
|
||||||
const fileReader = new FileReader();
|
const fileReader = new FileReader();
|
||||||
|
|
@ -6831,7 +6838,6 @@ function fantasyMap() {
|
||||||
const params = data[0].split("|");
|
const params = data[0].split("|");
|
||||||
const mapVersion = params[0] || data[0];
|
const mapVersion = params[0] || data[0];
|
||||||
if (mapVersion !== version) {
|
if (mapVersion !== version) {
|
||||||
console.warn("mea culpa", {mapVersion, version})
|
|
||||||
let message = `The Map version `;
|
let message = `The Map version `;
|
||||||
// mapVersion reference was not added to downloaded map before v. 0.52b, so I cannot support really old files
|
// mapVersion reference was not added to downloaded map before v. 0.52b, so I cannot support really old files
|
||||||
if (mapVersion.length <= 10) {
|
if (mapVersion.length <= 10) {
|
||||||
|
|
@ -6853,7 +6859,6 @@ function fantasyMap() {
|
||||||
} else {loadDataFromMap(data);}
|
} else {loadDataFromMap(data);}
|
||||||
if (mapVersion.length > 10) {console.error("Cannot load map"); }
|
if (mapVersion.length > 10) {console.error("Cannot load map"); }
|
||||||
};
|
};
|
||||||
console.warn("mea culpa", {file})
|
|
||||||
fileReader.readAsText(file, "UTF-8");
|
fileReader.readAsText(file, "UTF-8");
|
||||||
if (callback) {callback();}
|
if (callback) {callback();}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
function makeFileFromUrl(mapLink, callback) {
|
|
||||||
fetch(mapLink, {
|
|
||||||
method: 'GET',
|
|
||||||
mode: 'cors',
|
|
||||||
})
|
|
||||||
.then(response => response.blob())
|
|
||||||
.then(blob => callback(blob));
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadMapFromUrl(uploadFile) {
|
|
||||||
const url = new URL(location.href);
|
|
||||||
const mapLink = url.searchParams.get('maplink');
|
|
||||||
if (mapLink) {
|
|
||||||
makeFileFromUrl(decodeURIComponent(mapLink), uploadFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
window.loadMapFromUrl = loadMapFromUrl;
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue