mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 12:01:23 +01:00
Basic gzip an gunzip on load and save.
This commit is contained in:
parent
c3a385b2c9
commit
3f205cd499
5 changed files with 73 additions and 30 deletions
|
|
@ -116,14 +116,23 @@ function getMapData() {
|
|||
].join("\r\n");
|
||||
return mapData;
|
||||
}
|
||||
async function compressMapData(mapData){
|
||||
const compressedStream = new Blob([mapData]).stream().pipeThrough(new CompressionStream("gzip"));
|
||||
let compressedData = [];
|
||||
for await (const chunk of compressedStream){
|
||||
compressedData = compressedData.concat(Array.from(chunk));
|
||||
}
|
||||
return new Uint8Array(compressedData);
|
||||
}
|
||||
|
||||
|
||||
// Download .map file
|
||||
function dowloadMap() {
|
||||
async function downloadMap() {
|
||||
if (customization)
|
||||
return tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error");
|
||||
closeDialogs("#alert");
|
||||
|
||||
const mapData = getMapData();
|
||||
const mapData = await compressMapData(getMapData());
|
||||
const blob = new Blob([mapData], {type: "text/plain"});
|
||||
const URL = window.URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
|
|
@ -138,7 +147,7 @@ async function saveToDropbox() {
|
|||
if (customization)
|
||||
return tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error");
|
||||
closeDialogs("#alert");
|
||||
const mapData = getMapData();
|
||||
const mapData = await compressMapData(getMapData());
|
||||
const filename = getFileName() + ".map";
|
||||
try {
|
||||
await Cloud.providers.dropbox.save(filename, mapData);
|
||||
|
|
@ -162,7 +171,7 @@ async function initiateAutosave() {
|
|||
if (customization) return tip("Autosave: map cannot be saved in edit mode", false, "warning", 2000);
|
||||
|
||||
tip("Autosave: saving map...", false, "warning", 3000);
|
||||
const mapData = getMapData();
|
||||
const mapData = await compressMapData(getMapData());
|
||||
const blob = new Blob([mapData], {type: "text/plain"});
|
||||
await ldb.set("lastMap", blob);
|
||||
INFO && console.log("Autosaved at", new Date().toLocaleTimeString());
|
||||
|
|
@ -176,7 +185,7 @@ async function quickSave() {
|
|||
if (customization)
|
||||
return tip("Map cannot be saved when edit mode is active, please exit the mode first", false, "error");
|
||||
|
||||
const mapData = getMapData();
|
||||
const mapData = await compressMapData(getMapData());
|
||||
const blob = new Blob([mapData], {type: "text/plain"});
|
||||
await ldb.set("lastMap", blob); // auto-save map
|
||||
tip("Map is saved to browser memory. Please also save as .map file to secure progress", true, "success", 2000);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue