[wip] idb impl
This commit is contained in:
parent
6e701d8ac3
commit
5bb2f25f91
@ -110,8 +110,7 @@ function loop(deltaT) {
|
||||
|
||||
lib.startGameLoop(loop);
|
||||
|
||||
</pre
|
||||
>
|
||||
</pre>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
40
src/gesundheit.js
Normal file
40
src/gesundheit.js
Normal file
@ -0,0 +1,40 @@
|
||||
async function asyncIdbRequest(req) {
|
||||
return await new Promise((resolve, reject) => {
|
||||
req.onerror = () => {
|
||||
reject(req.error);
|
||||
};
|
||||
|
||||
req.onsuccess = () => {
|
||||
resolve(req.result);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const Idb = new Proxy(globalThis.indexedDB, {
|
||||
get(target, prop, _receiver) {
|
||||
if (typeof target[prop] === "function") {
|
||||
return (...args) => {
|
||||
const req = target[prop](...args);
|
||||
return asyncIdbRequest(req);
|
||||
};
|
||||
}
|
||||
return Reflect.get(...arguments);
|
||||
},
|
||||
});
|
||||
|
||||
export class Gesundheit {
|
||||
static #isInternalConstructing = false;
|
||||
static #idb = globalThis.indexedDB;
|
||||
|
||||
constructor() {
|
||||
if (!Gesundheit.#isInternalConstructing) {
|
||||
throw new TypeError("Gesundheit is not constructable - use Gesundheit.load()");
|
||||
}
|
||||
Gesundheit.#isInternalConstructing = false;
|
||||
}
|
||||
|
||||
static async load(name) {
|
||||
const db = await Idb.open(name);
|
||||
console.log(db);
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ import { TextCompleter } from "./text_completer.js";
|
||||
import { ConsoleInput } from "./console_input.js";
|
||||
import { downloadFile, slugify } from "./utils.js";
|
||||
import { HtmlExporter } from "./html_exporter.js";
|
||||
import { Gesundheit } from "./gesundheit.js";
|
||||
|
||||
const editor = ace.edit("editor");
|
||||
editor.setTheme("ace/theme/gruvbox");
|
||||
@ -150,3 +151,5 @@ addEventListener("keydown", (ev) => {
|
||||
});
|
||||
|
||||
toggleSpriteEditorButton.addEventListener("click", () => spriteEditor.toggleEditor());
|
||||
|
||||
Gesundheit.load("spritedb");
|
||||
|
Loading…
x
Reference in New Issue
Block a user