Skip to content

Commit

Permalink
refactor to utils for fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Sep 2, 2023
1 parent dd43438 commit e808763
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
8 changes: 2 additions & 6 deletions src/menus/pause_screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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>
`
Expand Down
27 changes: 26 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e808763

Please sign in to comment.