mirror of
https://github.com/PrismarineJS/prismarine-web-client.git
synced 2024-11-23 16:17:49 -05:00
Should show error screen on error (#350)
* Should show error screen on error * not sure how its there ; * remove bedrock files as doesnt seem to be supported anyway * lint fix * handle non-promise variant as well
This commit is contained in:
parent
856639d586
commit
2fba863d66
3 changed files with 43 additions and 2 deletions
19
index.js
19
index.js
|
@ -176,6 +176,17 @@ async function connect (options) {
|
||||||
|
|
||||||
loadingScreen.status = 'Logging in'
|
loadingScreen.status = 'Logging in'
|
||||||
|
|
||||||
|
const errorAbortController = new AbortController()
|
||||||
|
window.addEventListener('unhandledrejection', (e) => {
|
||||||
|
handleError(e.reason)
|
||||||
|
}, {
|
||||||
|
signal: errorAbortController
|
||||||
|
})
|
||||||
|
window.addEventListener('error', (e) => {
|
||||||
|
handleError(e.message)
|
||||||
|
}, {
|
||||||
|
signal: errorAbortController.signal
|
||||||
|
})
|
||||||
const bot = mineflayer.createBot({
|
const bot = mineflayer.createBot({
|
||||||
host,
|
host,
|
||||||
port,
|
port,
|
||||||
|
@ -189,12 +200,13 @@ async function connect (options) {
|
||||||
})
|
})
|
||||||
hud.preload(bot)
|
hud.preload(bot)
|
||||||
|
|
||||||
bot.on('error', (err) => {
|
const handleError = (err) => {
|
||||||
console.log('Encountered error!', err)
|
console.log('Encountered error!', err)
|
||||||
loadingScreen.status = `Error encountered. Error message: ${err}. Please reload the page`
|
loadingScreen.status = `Error encountered. Error message: ${err}. Please reload the page`
|
||||||
loadingScreen.style = 'display: block;'
|
loadingScreen.style = 'display: block;'
|
||||||
loadingScreen.hasError = true
|
loadingScreen.hasError = true
|
||||||
})
|
}
|
||||||
|
bot.on('error', handleError)
|
||||||
|
|
||||||
bot.on('kicked', (kickReason) => {
|
bot.on('kicked', (kickReason) => {
|
||||||
console.log('User was kicked!', kickReason)
|
console.log('User was kicked!', kickReason)
|
||||||
|
@ -398,6 +410,9 @@ async function connect (options) {
|
||||||
hud.style.display = 'block'
|
hud.style.display = 'block'
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
// game in playable state show errors in console instead
|
||||||
|
errorAbortController.abort()
|
||||||
|
if (loadingScreen.hasError) return
|
||||||
// remove loading screen, wait a second to make sure a frame has properly rendered
|
// remove loading screen, wait a second to make sure a frame has properly rendered
|
||||||
loadingScreen.style = 'display: none;'
|
loadingScreen.style = 'display: none;'
|
||||||
}, 2500)
|
}, 2500)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
"description": "A minecraft client running in a browser",
|
"description": "A minecraft client running in a browser",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"postinstall": "node scripts/patchPackages.js",
|
||||||
"build": "webpack --config webpack.prod.js",
|
"build": "webpack --config webpack.prod.js",
|
||||||
"build-dev": "webpack --config webpack.dev.js",
|
"build-dev": "webpack --config webpack.dev.js",
|
||||||
"start": "node --max-old-space-size=8192 server.js 8080 dev",
|
"start": "node --max-old-space-size=8192 server.js 8080 dev",
|
||||||
|
|
25
scripts/patchPackages.js
Normal file
25
scripts/patchPackages.js
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
// @ts-check
|
||||||
|
const path = require('path')
|
||||||
|
const dataPath = path.join(require.resolve('minecraft-data'), '../data.js')
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
|
const lines = fs.readFileSync(dataPath, 'utf8').split('\n')
|
||||||
|
if (lines[0] === '//patched') {
|
||||||
|
console.log('Already patched')
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeLinesBetween (start, end) {
|
||||||
|
const startIndex = lines.findIndex(line => line === start)
|
||||||
|
if (startIndex === -1) return
|
||||||
|
const endIndex = startIndex + lines.slice(startIndex).findIndex(line => line === end)
|
||||||
|
// insert block comments
|
||||||
|
lines.splice(startIndex, 0, '/*')
|
||||||
|
lines.splice(endIndex + 2, 0, '*/')
|
||||||
|
}
|
||||||
|
|
||||||
|
removeLinesBetween(" 'bedrock': {", ' }')
|
||||||
|
|
||||||
|
lines.unshift('//patched')
|
||||||
|
fs.writeFileSync(dataPath, lines.join('\n'), 'utf8')
|
Loading…
Reference in a new issue