collect statistics for a short period

This commit is contained in:
Azgaar 2021-09-24 01:00:03 +03:00 committed by Peter
parent b3e0d5e7b1
commit 83fa6a13e6
7 changed files with 48 additions and 866 deletions

View file

@ -4,6 +4,7 @@
// download map as SVG
async function saveSVG() {
TIME && console.time("saveSVG");
track("export", "svg");
const url = await getMapURL("svg");
const link = document.createElement("a");
link.download = getFileName() + ".svg";
@ -17,6 +18,7 @@ async function saveSVG() {
// download map as PNG
async function savePNG() {
TIME && console.time("savePNG");
track("export", "png");
const url = await getMapURL("png");
const link = document.createElement("a");
@ -47,6 +49,7 @@ async function savePNG() {
// download map as JPEG
async function saveJPEG() {
TIME && console.time("saveJPEG");
track("export", "jpg");
const url = await getMapURL("png");
const canvas = document.createElement("canvas");
@ -264,7 +267,11 @@ async function getMapURL(type, options = {}) {
if (!cloneEl.getElementById("labels")) cloneEl.getElementById("textPaths")?.remove(); // removed unused textPaths
// add armies style
if (cloneEl.getElementById("armies")) cloneEl.insertAdjacentHTML("afterbegin", "<style>#armies text {stroke: none; fill: #fff; text-shadow: 0 0 4px #000; dominant-baseline: central; text-anchor: middle; font-family: Helvetica; fill-opacity: 1;}#armies text.regimentIcon {font-size: .8em;}</style>");
if (cloneEl.getElementById("armies"))
cloneEl.insertAdjacentHTML(
"afterbegin",
"<style>#armies text {stroke: none; fill: #fff; text-shadow: 0 0 4px #000; dominant-baseline: central; text-anchor: middle; font-family: Helvetica; fill-opacity: 1;}#armies text.regimentIcon {font-size: .8em;}</style>"
);
// add xlink: for href to support svg1.1
if (type === "svg") {
@ -372,6 +379,7 @@ function inlineStyle(clone) {
}
function saveGeoJSON_Cells() {
track("export", "getJSON cells");
const json = {type: "FeatureCollection", features: []};
const cells = pack.cells;
const getPopulation = i => {
@ -402,6 +410,7 @@ function saveGeoJSON_Cells() {
}
function saveGeoJSON_Routes() {
track("export", "getJSON routes");
const json = {type: "FeatureCollection", features: []};
routes.selectAll("g > path").each(function () {
@ -418,6 +427,7 @@ function saveGeoJSON_Routes() {
}
function saveGeoJSON_Rivers() {
track("export", "getJSON rivers");
const json = {type: "FeatureCollection", features: []};
rivers.selectAll("path").each(function () {
@ -440,6 +450,8 @@ function saveGeoJSON_Rivers() {
}
function saveGeoJSON_Markers() {
// TODO: rework for new markers
track("export", "getJSON markers");
const json = {type: "FeatureCollection", features: []};
markers.selectAll("use").each(function () {

View file

@ -67,7 +67,8 @@ function loadMapPrompt(blob) {
});
function loadLastSavedMap() {
WARN && console.warn('Load last saved map');
WARN && console.warn("Load last saved map");
track("load", `from browser storage`);
try {
uploadMap(blob);
} catch (error) {
@ -78,6 +79,7 @@ function loadMapPrompt(blob) {
}
function loadMapFromURL(maplink, random) {
track("load", `from url`);
const URL = decodeURIComponent(maplink);
fetch(URL, {method: "GET", mode: "cors"})
@ -93,6 +95,7 @@ function loadMapFromURL(maplink, random) {
}
function showUploadErrorMessage(error, URL, random) {
track("error", `map load from url`);
ERROR && console.error(error);
alertMessage.innerHTML = `Cannot load map from the ${link(URL, "link provided")}.
${random ? `A new random map is generated. ` : ""}
@ -433,14 +436,29 @@ function parseLoadedData(data) {
// 1.0 adds a legend box
legend = svg.append("g").attr("id", "legend");
legend.attr("font-family", "Almendra SC").attr("font-size", 13).attr("data-size", 13).attr("data-x", 99).attr("data-y", 93).attr("stroke-width", 2.5).attr("stroke", "#812929").attr("stroke-dasharray", "0 4 10 4").attr("stroke-linecap", "round");
legend
.attr("font-family", "Almendra SC")
.attr("font-size", 13)
.attr("data-size", 13)
.attr("data-x", 99)
.attr("data-y", 93)
.attr("stroke-width", 2.5)
.attr("stroke", "#812929")
.attr("stroke-dasharray", "0 4 10 4")
.attr("stroke-linecap", "round");
// 1.0 separated drawBorders fron drawStates()
stateBorders = borders.append('g').attr('id', 'stateBorders');
provinceBorders = borders.append('g').attr('id', 'provinceBorders');
borders.attr('opacity', null).attr('stroke', null).attr('stroke-width', null).attr('stroke-dasharray', null).attr('stroke-linecap', null).attr('filter', null);
stateBorders.attr('opacity', 0.8).attr('stroke', '#56566d').attr('stroke-width', 1).attr('stroke-dasharray', '2').attr('stroke-linecap', 'butt');
provinceBorders.attr('opacity', 0.8).attr('stroke', '#56566d').attr('stroke-width', 0.5).attr('stroke-dasharray', '1').attr('stroke-linecap', 'butt');
stateBorders = borders.append("g").attr("id", "stateBorders");
provinceBorders = borders.append("g").attr("id", "provinceBorders");
borders
.attr("opacity", null)
.attr("stroke", null)
.attr("stroke-width", null)
.attr("stroke-dasharray", null)
.attr("stroke-linecap", null)
.attr("filter", null);
stateBorders.attr("opacity", 0.8).attr("stroke", "#56566d").attr("stroke-width", 1).attr("stroke-dasharray", "2").attr("stroke-linecap", "butt");
provinceBorders.attr("opacity", 0.8).attr("stroke", "#56566d").attr("stroke-width", 0.5).attr("stroke-dasharray", "1").attr("stroke-linecap", "butt");
// 1.0 adds state relations, provinces, forms and full names
provs = viewbox.insert('g', '#borders').attr('id', 'provs').attr('opacity', 0.6);
@ -986,9 +1004,9 @@ function parseLoadedData(data) {
$(this).dialog('close');
mapToLoad.click();
},
'New map': function () {
$(this).dialog('close');
regenerateMap();
"New map": function () {
$(this).dialog("close");
regenerateMap("loading error");
},
Cancel: function () {
$(this).dialog('close');

View file

@ -1,33 +1,4 @@
<<<<<<< HEAD
"use strict";
=======
'use strict';
function editHeightmap() {
void (function selectEditMode() {
alertMessage.innerHTML = `Heightmap is a core element on which all other data (rivers, burgs, states etc) is based.
So the best edit approach is to <i>erase</i> the secondary data and let the system automatically regenerate it on edit completion.
<p><i>Erase</i> mode also allows you Convert an Image into a heightmap or use Template Editor.</p>
<p>You can <i>keep</i> the data, but you won't be able to change the coastline.</p>
<p>Try <i>risk</i> mode to change the coastline and keep the data. The data will be restored as much as possible, but it can cause unpredictable errors.</p>
<p>Please <span class="pseudoLink" onclick=dowloadMap(); editHeightmap();>save the map</span> before editing the heightmap!</p>
<p style="margin-bottom: 0">Check out ${link("https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Heightmap-customization", "wiki")} for guidance.</p>`;
$('#alert').dialog({
resizable: false,
title: 'Edit Heightmap',
width: '28em',
buttons: {
Erase: () => enterHeightmapEditMode('erase'),
Keep: () => enterHeightmapEditMode('keep'),
Risk: () => enterHeightmapEditMode('risk'),
Cancel: function () {
$(this).dialog('close');
}
}
});
})();
>>>>>>> f557701e (dropbox - import changes from alpha)
function editHeightmap(options) {
const {mode, tool} = options || {};
@ -1089,7 +1060,8 @@ function editHeightmap(options) {
}
function openImageConverter() {
if ($('#imageConverter').is(':visible')) return;
if ($("#imageConverter").is(":visible")) return;
track("edit", "convert image");
imageToLoad.click();
closeDialogs('#imageConverter');

View file

@ -665,7 +665,7 @@ function restoreDefaultOptions() {
// Sticked menu Options listeners
document.getElementById("sticked").addEventListener("click", function (event) {
const id = event.target.id;
if (id === "newMapButton") regeneratePrompt();
if (id === "newMapButton") regeneratePrompt("sticky button");
else if (id === "saveButton") showSavePane();
else if (id === "exportButton") showExportPane();
else if (id === "loadButton") showLoadPane();
@ -931,8 +931,9 @@ function enterStandardView() {
}
async function enter3dView(type) {
const canvas = document.createElement('canvas');
canvas.id = 'canvas3d';
track("click", `3d mode: ${type}`);
const canvas = document.createElement("canvas");
canvas.id = "canvas3d";
canvas.dataset.type = type;
if (type === 'heightmap3DView') {