Add loadMapFromUrl

This commit is contained in:
hasparus 2018-10-17 11:31:11 +02:00
parent f5c507a94b
commit 13ad4f941c
No known key found for this signature in database
GPG key ID: 199946486FC7B0AC
3 changed files with 41 additions and 2 deletions

7
package.json Normal file
View file

@ -0,0 +1,7 @@
{
"name": "azgaars-map-generator",
"version": "1.0.0",
"scripts": {
"start": "npx serve ."
}
}

View file

@ -19,9 +19,19 @@
// Use typed arrays instead of array of objects
// Get rid of jQuery as d3.js can almost all the same and more
// Re-build UI on reactive approach, vue.js
"use strict";
fantasyMap();
function loadScript(path) {
const script = document.createElement("script");
script.addEventListener("load", () => {
fantasyMap();
});
script.src = path;
document.body.appendChild(script);
}
loadScript("./src/loadMapFromUrl.js");
function fantasyMap() {
// Version control
const version = "0.60b";
@ -272,6 +282,8 @@ function fantasyMap() {
focusOn(); // based on searchParams focus on point, cell or burg from MFCG
invokeActiveZooming(); // to hide what need to be hidden
loadMapFromUrl(uploadFile);
function generate() {
console.group("Random map");
console.time("TOTAL");
@ -6819,6 +6831,7 @@ function fantasyMap() {
const params = data[0].split("|");
const mapVersion = params[0] || data[0];
if (mapVersion !== version) {
console.warn("mea culpa", {mapVersion, 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
if (mapVersion.length <= 10) {
@ -6840,6 +6853,7 @@ function fantasyMap() {
} else {loadDataFromMap(data);}
if (mapVersion.length > 10) {console.error("Cannot load map"); }
};
console.warn("mea culpa", {file})
fileReader.readAsText(file, "UTF-8");
if (callback) {callback();}
}

18
src/loadMapFromUrl.js Normal file
View file

@ -0,0 +1,18 @@
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;