More cleanup lol
This commit is contained in:
parent
7a6b83cb58
commit
f71885f89e
@ -1,152 +0,0 @@
|
||||
const Console = require('./Console')
|
||||
const ModPackage = require('./ModPackage')
|
||||
const handleIframe = require('./util/handleIframe'),
|
||||
gzip = require('./util/gzip'),
|
||||
promisify = require('./util/promisify')
|
||||
|
||||
const openAsync = promisify($file.open),
|
||||
{ Buffer } = le._apps.abnt
|
||||
|
||||
class Instance {
|
||||
constructor(app, modPath) {
|
||||
let self = this,
|
||||
bundleDir = app.bundle.for('/import/')
|
||||
|
||||
this.consoleWindow
|
||||
this.window
|
||||
this.mod
|
||||
this.closed = false
|
||||
this.app = app
|
||||
this.assets = new Map()
|
||||
this.import = new Proxy(this.assets, {
|
||||
get(target, prop) {
|
||||
console.log(`LOADING "${prop}"`)
|
||||
|
||||
if( !target.has(prop) && bundleDir.access(prop) ) {
|
||||
target.set(prop, bundleDir.openSync(prop, 'URL') )
|
||||
}
|
||||
|
||||
return target.get(prop)
|
||||
}
|
||||
})
|
||||
this.arguments = []
|
||||
this.console = new Console()
|
||||
|
||||
console.log('INSTANCE:', this)
|
||||
|
||||
// Post init
|
||||
|
||||
this.package = this.loadPackage(modPath)
|
||||
.then(mod => {
|
||||
this.mod = mod
|
||||
console.log('woo window,', this.window)
|
||||
|
||||
return mod
|
||||
})
|
||||
|
||||
this.package.catch(console.error)
|
||||
|
||||
this.openMain()
|
||||
}
|
||||
|
||||
async loadPackage(path) {
|
||||
const buffer = await openAsync(path, 'ArrayBuffer').then(ab => Buffer.from(ab)),
|
||||
mod = await ModPackage.unpack(buffer)
|
||||
|
||||
return mod
|
||||
}
|
||||
|
||||
openMain() {
|
||||
// We'll need to shove it in a fragment to force it to load while hidden
|
||||
const iframe = document.createElement('iframe'),
|
||||
self = this
|
||||
|
||||
const options = {
|
||||
title: 'Xash3D',
|
||||
// url: "data:text/plain,",
|
||||
// icon: app.icon,
|
||||
// Windows93 adds to these to compensate for title height and such,
|
||||
// but we want it to match the canvas resolution.
|
||||
// We want 647 x 508 on the window element
|
||||
width: 640 + 7 - 9,
|
||||
height: 480 + 28 - 30,
|
||||
menu: [
|
||||
{
|
||||
name: 'Game',
|
||||
items: [
|
||||
{
|
||||
name: 'Open console',
|
||||
action: function() {
|
||||
self.openConsole()
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
onready() {
|
||||
console.log('this:', this)
|
||||
this.el.body.appendChild(iframe)
|
||||
},
|
||||
onclose() {
|
||||
self.consoleWindow?.close()
|
||||
self.closed = true
|
||||
|
||||
app.cleanInstances()
|
||||
}
|
||||
}
|
||||
|
||||
iframe.style.display = 'none'
|
||||
iframe.src = this.app.bundle.openSync('./main.html', 'URL')
|
||||
|
||||
iframe.onload = () => {
|
||||
iframe.contentWindow.instance = self
|
||||
iframe.contentWindow.onmessage = event => {
|
||||
console.log(event)
|
||||
|
||||
if(event.data == 'loadingDone')
|
||||
self.window = $window(options)
|
||||
iframe.style.display = 'initial'
|
||||
}
|
||||
|
||||
handleIframe(iframe, '/import/')
|
||||
console.log('loadd')
|
||||
}
|
||||
|
||||
document.body.append(iframe)
|
||||
console.log(iframe)
|
||||
}
|
||||
|
||||
openConsole() {
|
||||
const self = this
|
||||
|
||||
if(this.consoleWindow)
|
||||
// Put focus on the window instead
|
||||
this.focusConsole()
|
||||
|
||||
const options = {
|
||||
title: 'Xash Console',
|
||||
bodyClass: 'ui_terminal xash3d_terminal',
|
||||
onready() {
|
||||
self.console.attachTo(self.consoleWindow)
|
||||
self.focusConsole()
|
||||
},
|
||||
onclose() {
|
||||
self.console.unattach()
|
||||
}
|
||||
}
|
||||
|
||||
this.consoleWindow = $window(options)
|
||||
}
|
||||
|
||||
focusConsole() {
|
||||
this.consoleWindow.el.header.click()
|
||||
}
|
||||
|
||||
kill() {
|
||||
this.window?.close()
|
||||
this.consoleWindow?.close()
|
||||
delete this.assets // pls my memory
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Instance
|
Loading…
x
Reference in New Issue
Block a user