singlePlayerServer -> localServer (intention: will allow other players to connect soon)
This commit is contained in:
parent
2244e1781c
commit
360ed68d98
6 changed files with 20 additions and 18 deletions
|
|
@ -31,7 +31,7 @@ async function addFolderToZip(folderPath, zip, relativePath) {
|
|||
const exportWorld = async () => {
|
||||
// todo issue into chat warning if fs is writable!
|
||||
const zip = new JSZip()
|
||||
let worldFolder: string = singlePlayerServer.options.worldFolder
|
||||
let worldFolder: string = localServer.options.worldFolder
|
||||
if (!worldFolder.startsWith('/')) worldFolder = `/${worldFolder}`
|
||||
await addFolderToZip(worldFolder, zip, '')
|
||||
|
||||
|
|
@ -66,9 +66,9 @@ const commands = [
|
|||
if (fsState.isReadonly || !fsState.syncFs) return
|
||||
// todo for testing purposes
|
||||
sessionStorage.oldData = localStorage
|
||||
singlePlayerServer.quit()
|
||||
localServer.quit()
|
||||
// todo browserfs bug
|
||||
fs.rmdirSync(singlePlayerServer.options.worldFolder, { recursive: true })
|
||||
fs.rmdirSync(localServer.options.worldFolder, { recursive: true })
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -80,7 +80,7 @@ const commands = [
|
|||
]
|
||||
|
||||
export const tryHandleBuiltinCommand = (message) => {
|
||||
if (!singlePlayerServer) return
|
||||
if (!localServer) return
|
||||
|
||||
for (const command of commands) {
|
||||
if (command.command.includes(message)) {
|
||||
|
|
@ -91,10 +91,10 @@ export const tryHandleBuiltinCommand = (message) => {
|
|||
}
|
||||
|
||||
export const saveWorld = async () => {
|
||||
for (const player of window.singlePlayerServer.players) {
|
||||
for (const player of localServer.players) {
|
||||
await player.save()
|
||||
}
|
||||
const worlds = [singlePlayerServer.overworld]
|
||||
const worlds = [localServer.overworld]
|
||||
for (const world of worlds) {
|
||||
await world.storageProvider.close()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,8 +124,8 @@ export const gameAdditionalState = proxy({
|
|||
window.gameAdditionalState = gameAdditionalState
|
||||
|
||||
const savePlayers = () => {
|
||||
if (!window.singlePlayerServer) return
|
||||
for (const player of window.singlePlayerServer.players) {
|
||||
if (!window.localServer) return
|
||||
for (const player of window.localServer.players) {
|
||||
player.save()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
src/globals.d.ts
vendored
2
src/globals.d.ts
vendored
|
|
@ -3,7 +3,7 @@
|
|||
declare const THREE: typeof import('three')
|
||||
// todo
|
||||
declare const bot: import('mineflayer').Bot
|
||||
declare const singlePlayerServer: any
|
||||
declare const localServer: any
|
||||
|
||||
declare interface Document {
|
||||
getElementById(id): any
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
window.bot = undefined
|
||||
window.THREE = undefined
|
||||
window.singlePlayerServer = undefined
|
||||
window.localServer = undefined
|
||||
|
|
|
|||
14
src/index.js
14
src/index.js
|
|
@ -306,7 +306,7 @@ async function connect (connectOptions) {
|
|||
let bot
|
||||
const destroyAll = () => {
|
||||
viewer.resetAll()
|
||||
window.singlePlayerServer = undefined
|
||||
window.localServer = undefined
|
||||
|
||||
// simple variant, still buggy
|
||||
postRenderFrameFn = () => { }
|
||||
|
|
@ -354,7 +354,7 @@ async function connect (connectOptions) {
|
|||
}, {
|
||||
signal: errorAbortController.signal
|
||||
})
|
||||
let singlePlayerServer
|
||||
let localServer
|
||||
try {
|
||||
Object.assign(serverOptions, _.defaultsDeep({}, connectOptions.serverOverrides ?? {}, options.localServerOptions, serverOptions))
|
||||
let version = connectOptions.botVersion ?? serverOptions.version
|
||||
|
|
@ -378,13 +378,13 @@ async function connect (connectOptions) {
|
|||
setLoadingScreenStatus('Starting local server')
|
||||
window.serverDataChannel ??= {}
|
||||
window.worldLoaded = false
|
||||
singlePlayerServer = window.singlePlayerServer = startLocalServer()
|
||||
localServer = window.localServer = startLocalServer()
|
||||
// todo need just to call quit if started
|
||||
// loadingScreen.maybeRecoverable = false
|
||||
// init world, todo: do it for any async plugins
|
||||
if (!singlePlayerServer.worldsReady) {
|
||||
if (!localServer.worldsReady) {
|
||||
await new Promise(resolve => {
|
||||
singlePlayerServer.once('worldsReady', resolve)
|
||||
localServer.once('worldsReady', resolve)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -466,10 +466,12 @@ async function connect (connectOptions) {
|
|||
|
||||
const center = bot.entity.position
|
||||
|
||||
/** @type {import('../prismarine-viewer/viewer/lib/worldView').WorldView} */
|
||||
const worldView = new WorldView(bot.world, singeplayer ? renderDistance : Math.min(renderDistance, maxMultiplayerRenderDistance), center)
|
||||
if (singeplayer) {
|
||||
let prevRenderDistance = renderDistance
|
||||
const d = subscribeKey(options, 'renderDistance', () => {
|
||||
singlePlayerServer.options['view-distance'] = options.renderDistance
|
||||
localServer.options['view-distance'] = options.renderDistance
|
||||
worldView.viewDistance = options.renderDistance
|
||||
window.onPlayerChangeRenderDistance?.(options.renderDistance)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -149,9 +149,9 @@ export const setLoadingScreenStatus = function (/** @type {string} */status, isE
|
|||
|
||||
|
||||
export const disconnect = async () => {
|
||||
if (window.singlePlayerServer) {
|
||||
if (window.localServer) {
|
||||
await saveWorld()
|
||||
singlePlayerServer.quit()
|
||||
localServer.quit()
|
||||
}
|
||||
bot._client.emit('end')
|
||||
miscUiState.gameLoaded = false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue