diff --git a/web/src/components/GodotFrame.tsx b/web/src/components/GodotFrame.tsx index 89d963b..e73982f 100644 --- a/web/src/components/GodotFrame.tsx +++ b/web/src/components/GodotFrame.tsx @@ -3,6 +3,7 @@ import { Button } from "../shadcn/ui/button"; import { FaPlay, FaExpand, FaVolumeUp, FaVolumeMute } from "react-icons/fa"; import { useQuery } from "@tanstack/react-query"; import { getGameVersionInfo } from "../lib/versions"; +import { getGodotFile } from "../foreign/indexedDB"; interface AudioBridge { state?: boolean; @@ -15,6 +16,13 @@ interface WindowBridge extends Window { godotAudioBridge: GodotBridge; } +async function aboba() { + const a = {}; + let c = getGodotFile(a); + const b = a.blob; + return [c, a]; +} + export const GodotFrame = () => { const [showIframe, setShowIframe] = useState(false); const [muted, setMuted] = useState(false); @@ -23,6 +31,10 @@ export const GodotFrame = () => { queryKey: ["version-data"], queryFn: async () => await getGameVersionInfo(), }); + const { data: gameSettingsFile, error } = useQuery({ + queryKey: ["game-settings-data"], + queryFn: async () => await aboba(), + }); const handleFullscreen = () => { if (iframeRef.current) { @@ -99,9 +111,15 @@ export const GodotFrame = () => { > )} -
+
build: {gameVersionData?.version} commit: {gameVersionData?.commit}
+ ); diff --git a/web/src/foreign/indexedDB.ts b/web/src/foreign/indexedDB.ts new file mode 100644 index 0000000..dbc0748 --- /dev/null +++ b/web/src/foreign/indexedDB.ts @@ -0,0 +1,100 @@ +(function functionToExecute() { + // Open the database connection. + const open = indexedDB.open("/userfs"); + + open.onupgradeneeded = function () { + // Define the database schema if necessary. + const db = open.result; + const store = db.createObjectStore("/userfs"); + console.log("------------> Upgraded userfs?"); + }; + + open.onsuccess = function () { + const db = open.result; + const key = "/userfs/godot/app_userdata/SuperIcosahedron/settings.cfg"; + + // Write file to DB + // var tx = db.transaction('files', 'readwrite'); + // var store = tx.objectStore('files'); + // store.put(null, "test"); + + // Later, read file back out of DB + // let tx2: IDBTransaction | undefined; + let tx2; + try { + tx2 = db.transaction("FILE_DATA", "readonly"); + } catch (DOMException) { + console.error("Failed to get user data from indexedDB"); + return; + } + if (!tx2) { + return; + } + const store2 = tx2.objectStore("FILE_DATA"); + const request = store2.get(key); + + request.onsuccess = function (e) { + // Got the file! + const file = request.result; + + if (file == null) { + alert("You haven't generated any results yet."); + console.log("File is null"); + return; + } else { + console.log("Is int8array: " + (file.contents instanceof Int8Array)); + } + + const blob = new Blob([file.contents], { + type: "text/plain;charset=utf-8;", + }); + return blob; + }; + }; +})(); + +export const USER_CONFIG_KEY = + "/userfs/godot/app_userdata/SuperIcosahedron/settings.cfg"; + +export function getGodotFile(res: unknown, file: string = USER_CONFIG_KEY) { + // Open the database connection. + const open = indexedDB.open("/userfs"); + + open.onsuccess = function () { + const db = open.result; + const key = file; + + // Later, read file back out of DB + let tx: IDBTransaction | undefined; + try { + tx = db.transaction("FILE_DATA", "readonly"); + } catch (DOMException) { + console.error("Failed to get user data from indexedDB"); + return; + } + if (!tx) { + return; + } + const store2 = tx.objectStore("FILE_DATA"); + const request = store2.get(key); + + request.onsuccess = function (): Blob { + // Got the file! + const file = request.result; + + if (file == null) { + throw new Error("File not found"); + } else { + console.log("Is int8array: " + (file.contents instanceof Int8Array)); + } + + const blob = new Blob([file.contents], { + type: "text/plain;charset=utf-8;", + }); + res.blob = blob; + return blob; + }; + return request; + }; + return open; +}