Skip to content

Commit

Permalink
Upragde spx2
Browse files Browse the repository at this point in the history
  • Loading branch information
nighca committed Nov 26, 2024
1 parent 1ca3192 commit 5c7951e
Show file tree
Hide file tree
Showing 14 changed files with 306 additions and 347 deletions.
1 change: 1 addition & 0 deletions spx-gui/public/runner/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ diff.zip
favicon.png
game.zip
godot.html
godot.editor.html
godot.offline.html
godot.service.worker.js
index.html
Expand Down
Binary file removed spx-gui/public/runner/20241121_2139/engineres.zip
Binary file not shown.
Binary file added spx-gui/public/runner/20241126_1505/engineres.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class GameApp {
this.game = null;
this.persistentPath = '/home/web_user';
this.tempZipPath = '/tmp/preload.zip';
this.tempGamePath = '/home/spx_game_cache';
this.projectInstallName = config.projectName || "Game";
this.projectData = config.projectData;
this.oldData = config.projectData;
Expand Down Expand Up @@ -91,10 +92,14 @@ class GameApp {
console.error("project already loaded!")
}
this.isEditor = true

let url = this.assetURLs["engineres.zip"]
let engineData = await (await fetch(url)).arrayBuffer();

try {
this.onProgress(0.1);
this.clearPersistence(this.tempZipPath);
let isCacheValid = await this.checkAndUpdateCache(this.projectData, true);
let isCacheValid = await this.checkAndUpdateCache(engineData, true);
await this.checkEngineCache()
this.editor = new Engine(this.editorConfig);
if (!isCacheValid) {
Expand All @@ -105,55 +110,24 @@ class GameApp {
};
// install project
this.editor.init().then(async () => {
await this.mergeProjectWithEngineRes()
this.writePersistence(this.tempZipPath, this.projectData);
this.writePersistence(this.editor, this.tempZipPath, engineData);
const args = ['--project-manager', '--single-window', "--install_project_name", this.projectInstallName];
this.editor.start({ 'args': args, 'persistentDrops': true }).then(async () => {
this.editorCanvas.focus();
})
});
} else {
this.runEditor(resolve, reject)
this.logVerbose("cache is valid, skip it")
resolve()
}
} catch (error) {
console.error("Error checking database existence: ", error);
}
}

async updateProject(resolve, reject, newData, addInfos, deleteInfos, updateInfos) {
if (addInfos == null) {
addInfos = []
}
if (deleteInfos == null) {
deleteInfos = []
}
if (updateInfos == null) {
updateInfos = []
}
this.oldData = newData
let mergedArray = addInfos.concat(updateInfos);
const zip = new JSZip();
const zipContent = await zip.loadAsync(newData);
let datas = []
for (let path of mergedArray) {
const dstFile = zipContent.files[path];
let data = await dstFile.async('arraybuffer');
if (!dstFile.dir) {
datas.push({ "path": path, "data": data })
}
}
deleteInfos = deleteInfos.map(info => `res://${info}`);
const evt = new CustomEvent('spx_update_project', {
detail: {
"resolve": async () => {
await this.checkAndUpdateCache(newData)
resolve()
},
"dirtyInfos": datas,
"deleteInfos": deleteInfos,
}
});
this.editorCanvas.dispatchEvent(evt);
this.projectData = newData
resolve()
}

async stopProject(resolve, reject) {
Expand All @@ -165,13 +139,11 @@ class GameApp {
await this.stopGame(() => {
this.isEditor = true
this.onProgress(1.0);
this.exitFunc = () => {
this.logVerbose("on editor quit")
this.editor = null
this.exitFunc = null
resolve();
}
this.editor.requestQuit()
this.logVerbose("on editor quit")
this.editor = null
this.exitFunc = null
resolve();
}, null)
}

Expand Down Expand Up @@ -227,8 +199,10 @@ class GameApp {
this.onProgress(0.5);
this.game = new Engine(this.gameConfig);
let curGame = this.game
curGame.init().then(() => {
curGame.init().then(async () => {
this.onProgress(0.7);
await this.unpackGameData(curGame)

curGame.start({ 'args': args, 'canvas': this.gameCanvas }).then(async () => {
this.gameCanvas.focus();
await this.waitFsSyncDone(this.gameCanvas)
Expand All @@ -241,6 +215,19 @@ class GameApp {
});
}

async unpackGameData(curGame) {
const zip1 = new JSZip();
const zip1Content = await zip1.loadAsync(this.projectData);
let datas = []
for (const [filePath, file] of Object.entries(zip1Content.files)) {
const content = await file.async('arraybuffer');
if (!file.dir) {
datas.push({ "path": filePath, "data": content })
}
}
curGame.unpackGameData(this.tempGamePath, datas)
}


async stopGame(resolve, reject) {
this.stopGameTask--
Expand Down Expand Up @@ -288,12 +275,12 @@ class GameApp {
return `${this.persistentPath}/${this.projectInstallName}`;
}

writePersistence(targetPath, value) {
if (this.editor == null) {
console.error("please init editor first!")
writePersistence(engine, targetPath, value) {
if (engine == null) {
console.error("please init egnine first!")
return
}
this.editor.copyToFS(targetPath, value);
engine.copyToFS(targetPath, value);
}
clearPersistence(targetPath) {
const req = indexedDB.deleteDatabase(targetPath);
Expand Down Expand Up @@ -335,6 +322,10 @@ class GameApp {
request.onerror = function (event) {
reject('Error opening database: ' + dbName + " " + storeName + " " + event.target.error);
};

request.onblocked = function (event) {
reject('Database is blocked. Please close other tabs or windows using this database. ', dbName + " " + storeName + " " + event.target.error);
}
});
}

Expand Down Expand Up @@ -534,8 +525,8 @@ class GameApp {

function GetEngineHashes() {
return {
"gdspx.wasm":"d995c80195e064c64b48a0ab402aaa99104d9901cd86b4a9b763fff243444322",
"godot.editor.wasm":"0be7238826d50dc63fdcce6936d94eb286f511b5f6ee7a6f9c2d74b91d0d0660",
"gdspx.wasm":"abc5ef713f32ea02b8fc874a8785061e76b681757450254210c7b713b4f00a1b",
"godot.editor.wasm":"31b3a85bd04f1c4b712302612d7f0e494c31dc7da9242af2fc20a7e002725b13",

}
}
Expand Down
Binary file not shown.
Loading

0 comments on commit 5c7951e

Please sign in to comment.