refactor to utils for fixes

This commit is contained in:
Vitaly 2023-09-02 03:37:53 +03:00
commit e2bb768f3e
2 changed files with 28 additions and 7 deletions

View file

@ -6,6 +6,7 @@ const { fsState } = require('../loadFolder')
const { subscribe } = require('valtio')
const { saveWorld } = require('../builtinCommands')
const { notification } = require('./notification')
const { disconnect } = require('../utils')
class PauseScreen extends LitElement {
static get styles () {
@ -71,12 +72,7 @@ class PauseScreen extends LitElement {
</div>
<pmui-button pmui-width="204px" pmui-label="Options" @pmui-click=${() => showModal(document.getElementById('options-screen'))}></pmui-button>
<pmui-button pmui-width="204px" pmui-label="${!fsState.syncFs && !fsState.isReadonly ? 'Save & Quit' : 'Disconnect'}" @pmui-click=${async () => {
if (window.singlePlayerServer) {
await saveWorld()
singlePlayerServer.quit()
}
bot._client.emit('end')
miscUiState.gameLoaded = false
disconnect()
}}></pmui-button>
</main>
`

View file

@ -1,9 +1,10 @@
//@ts-check
import { activeModalStack, miscUiState } from './globalState'
import { activeModalStack, miscUiState, showModal } from './globalState'
import { notification } from './menus/notification'
import * as crypto from 'crypto'
import UUID from 'uuid-1345'
import { options } from './optionsStorage'
import { saveWorld } from './builtinCommands'
export const goFullscreen = async (doToggle = false) => {
if (!document.fullscreenElement) {
@ -132,6 +133,30 @@ function javaUUID (s) {
export function nameToMcOfflineUUID (name) {
return (new UUID(javaUUID('OfflinePlayer:' + name))).toString()
}
export const setLoadingScreenStatus = function (/** @type {string} */status, isError = false) {
const loadingScreen = document.getElementById('loading-error-screen')
// todo update in component instead
showModal(loadingScreen)
if (loadingScreen.hasError) {
miscUiState.gameLoaded = false
return
}
loadingScreen.hasError = isError
loadingScreen.status = status
}
export const disconnect = async () => {
if (window.singlePlayerServer) {
await saveWorld()
singlePlayerServer.quit()
}
bot._client.emit('end')
miscUiState.gameLoaded = false
}
export const loadScript = async function (/** @type {string} */ scriptSrc) {
if (document.querySelector(`script[src="${scriptSrc}"]`)) {
return