From c8c4e3267d6126f59ce6335edb8c02bb01aa930d Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Mon, 11 Nov 2024 17:49:33 +0300 Subject: [PATCH] feat: auto save worlds in singleplayer every 2 seconds since crashes might happen. still possible to cancel this behavior via new setting or ?noSave=true feat: add setting for debugging to disable signs text rendering --- prismarine-viewer/viewer/lib/mesher/models.ts | 2 +- prismarine-viewer/viewer/lib/mesher/shared.ts | 3 ++- src/flyingSquidEvents.ts | 14 ++++++++++++++ src/optionsStorage.ts | 2 ++ src/watchOptions.ts | 1 + 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/prismarine-viewer/viewer/lib/mesher/models.ts b/prismarine-viewer/viewer/lib/mesher/models.ts index 555efd80..91c0cf40 100644 --- a/prismarine-viewer/viewer/lib/mesher/models.ts +++ b/prismarine-viewer/viewer/lib/mesher/models.ts @@ -484,7 +484,7 @@ export function getSectionGeometry (sx, sy, sz, world: World) { } } if (invisibleBlocks.has(block.name)) continue - if (block.name.includes('_sign') || block.name === 'sign') { + if ((block.name.includes('_sign') || block.name === 'sign') && !world.config.disableSignsMapsSupport) { const key = `${cursor.x},${cursor.y},${cursor.z}` const props: any = block.getProperties() const facingRotationMap = { diff --git a/prismarine-viewer/viewer/lib/mesher/shared.ts b/prismarine-viewer/viewer/lib/mesher/shared.ts index 11988db2..b08a2bd7 100644 --- a/prismarine-viewer/viewer/lib/mesher/shared.ts +++ b/prismarine-viewer/viewer/lib/mesher/shared.ts @@ -8,7 +8,8 @@ export const defaultMesherConfig = { outputFormat: 'threeJs' as 'threeJs' | 'webgpu', textureSize: 1024, // for testing debugModelVariant: undefined as undefined | number[], - clipWorldBelowY: undefined as undefined | number + clipWorldBelowY: undefined as undefined | number, + disableSignsMapsSupport: false } export type MesherConfig = typeof defaultMesherConfig diff --git a/src/flyingSquidEvents.ts b/src/flyingSquidEvents.ts index fb5b00e3..7231dd27 100644 --- a/src/flyingSquidEvents.ts +++ b/src/flyingSquidEvents.ts @@ -1,4 +1,7 @@ +import { saveServer } from './flyingSquidUtils' +import { watchUnloadForCleanup } from './gameUnload' import { showModal } from './globalState' +import { options } from './optionsStorage' import { chatInputValueGlobal } from './react/Chat' import { showNotification } from './react/NotificationProvider' @@ -10,4 +13,15 @@ export default () => { showModal({ reactType: 'chat' }) }) }) + + if (options.singleplayerAutoSave) { + const autoSaveInterval = setInterval(() => { + if (options.singleplayerAutoSave) { + void saveServer(true) + } + }, 2000) + watchUnloadForCleanup(() => { + clearInterval(autoSaveInterval) + }) + } } diff --git a/src/optionsStorage.ts b/src/optionsStorage.ts index c97dadc1..53deb927 100644 --- a/src/optionsStorage.ts +++ b/src/optionsStorage.ts @@ -53,6 +53,8 @@ const defaultOptions = { // antiAliasing: false, clipWorldBelowY: undefined as undefined | number, // will be removed + disableSignsMapsSupport: false, + singleplayerAutoSave: false, showChunkBorders: false, // todo rename option frameLimit: false as number | false, alwaysBackupWorldBeforeLoading: undefined as boolean | undefined | null, diff --git a/src/watchOptions.ts b/src/watchOptions.ts index 2996a2e1..4b69726c 100644 --- a/src/watchOptions.ts +++ b/src/watchOptions.ts @@ -60,6 +60,7 @@ export const watchOptionsAfterViewerInit = () => { }) watchValue(options, (o, isChanged) => { viewer.world.mesherConfig.clipWorldBelowY = o.clipWorldBelowY + viewer.world.mesherConfig.disableSignsMapsSupport = o.disableSignsMapsSupport if (isChanged) { (viewer.world as WorldRendererThree).rerenderAllChunks() }