mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 03:51:23 +01:00
Add loadMapFromUrl
This commit is contained in:
parent
f5c507a94b
commit
13ad4f941c
3 changed files with 41 additions and 2 deletions
7
package.json
Normal file
7
package.json
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "azgaars-map-generator",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"scripts": {
|
||||||
|
"start": "npx serve ."
|
||||||
|
}
|
||||||
|
}
|
||||||
16
script.js
16
script.js
|
|
@ -19,9 +19,19 @@
|
||||||
// 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";
|
"use strict";
|
||||||
|
|
||||||
|
function loadScript(path) {
|
||||||
|
const script = document.createElement("script");
|
||||||
|
script.addEventListener("load", () => {
|
||||||
fantasyMap();
|
fantasyMap();
|
||||||
|
});
|
||||||
|
script.src = path;
|
||||||
|
document.body.appendChild(script);
|
||||||
|
}
|
||||||
|
|
||||||
|
loadScript("./src/loadMapFromUrl.js");
|
||||||
|
|
||||||
function fantasyMap() {
|
function fantasyMap() {
|
||||||
// Version control
|
// Version control
|
||||||
const version = "0.60b";
|
const version = "0.60b";
|
||||||
|
|
@ -272,6 +282,8 @@ function fantasyMap() {
|
||||||
focusOn(); // based on searchParams focus on point, cell or burg from MFCG
|
focusOn(); // based on searchParams focus on point, cell or burg from MFCG
|
||||||
invokeActiveZooming(); // to hide what need to be hidden
|
invokeActiveZooming(); // to hide what need to be hidden
|
||||||
|
|
||||||
|
loadMapFromUrl(uploadFile);
|
||||||
|
|
||||||
function generate() {
|
function generate() {
|
||||||
console.group("Random map");
|
console.group("Random map");
|
||||||
console.time("TOTAL");
|
console.time("TOTAL");
|
||||||
|
|
@ -6819,6 +6831,7 @@ 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) {
|
||||||
|
|
@ -6840,6 +6853,7 @@ 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();}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
18
src/loadMapFromUrl.js
Normal file
18
src/loadMapFromUrl.js
Normal 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;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue