allow to reset ls world from console, chat

rename exported worlds
rm unused util method
This commit is contained in:
Vitaly 2023-09-27 19:33:45 +03:00
commit 7b93d0bb69
3 changed files with 15 additions and 25 deletions

View file

@ -270,20 +270,12 @@ export const openWorldZip = async (...args: Parameters<typeof openWorldZipInner>
}
}
export async function generateAndDownloadWorldZip() {
const zip = new JSZip()
zip.folder('world')
// Generate the ZIP archive content
const zipContent = await zip.generateAsync({ type: 'blob' })
// Create a download link and trigger the download
const downloadLink = document.createElement('a')
downloadLink.href = URL.createObjectURL(zipContent)
downloadLink.download = 'prismarine-world.zip'
downloadLink.click()
// Clean up the URL object after download
URL.revokeObjectURL(downloadLink.href)
export const resetLocalStorageWorld = () => {
for (const key of Object.keys(localStorage)) {
if (/^[\da-fA-F]{8}(?:\b-[\da-fA-F]{4}){3}\b-[\da-fA-F]{12}$/g.test(key) || key === '/') {
localStorage.removeItem(key)
}
}
}
window.resetLocalStorageWorld = resetLocalStorageWorld

View file

@ -3,6 +3,7 @@ import { join } from 'path'
import JSZip from 'jszip'
import { fsState } from './loadSave'
import { closeWan, openToWanAndCopyJoinLink } from './localServerMultiplayer'
import { resetLocalStorageWorld } from './browserfs'
const notImplemented = () => {
return 'Not implemented yet'
@ -42,7 +43,8 @@ const exportWorld = async () => {
// Create a download link and trigger the download
const downloadLink = document.createElement('a')
downloadLink.href = URL.createObjectURL(zipContent)
downloadLink.download = 'world-exported.zip'
// todo use loaded zip/folder name
downloadLink.download = 'world-prismarine-exported.zip'
downloadLink.click()
// Clean up the URL object after download
@ -81,11 +83,10 @@ const commands = [
async invoke() {
if (fsState.inMemorySave) return
// todo for testing purposes
sessionStorage.oldData = localStorage
sessionStorage.oldWorldData = localStorage
console.log('World removed. Old data saved to sessionStorage.oldData')
localServer.quit()
// todo browserfs bug
fs.rmdirSync(localServer.options.worldFolder, { recursive: true })
resetLocalStorageWorld()
}
},
{

View file

@ -4,6 +4,7 @@ const { addPanoramaCubeMap } = require('../panorama')
const { hideModal, activeModalStacks, activeModalStack, replaceActiveModalStack, miscUiState } = require('../globalState')
const { guessProblem } = require('../guessProblem')
const { fsState } = require('../loadSave')
const { resetLocalStorageWorld } = require('../browserfs')
const { commonCss } = require('./components/common')
class LoadingErrorScreen extends LitElement {
@ -98,11 +99,7 @@ class LoadingErrorScreen extends LitElement {
addPanoramaCubeMap()
}}></pmui-button><pmui-button .hidden=${!(miscUiState.singleplayer && fsState.inMemorySave)} pmui-width="200px" pmui-label="Reset world" @pmui-click=${() => {
if (!confirm('Are you sure you want to delete all local world content?')) return
for (const key of Object.keys(localStorage)) {
if (/^[\da-fA-F]{8}(?:\b-[\da-fA-F]{4}){3}\b-[\da-fA-F]{12}$/g.test(key) || key === '/') {
localStorage.removeItem(key)
}
}
resetLocalStorageWorld()
window.location.reload()
}}></pmui-button><pmui-button @pmui-click=${() => window.location.reload()} pmui-label="Full Reload" pmui-width="200px"></pmui-button></div>`
: ''