]> git.rm.cloudns.org Git - xonotic/xonotic.git/commitdiff
File Upload support added. Lockl00p/WasmSupport
authorLockl00p <97256723+Lockl00p@users.noreply.github.com>
Tue, 10 Oct 2023 17:31:27 +0000 (12:31 -0500)
committerLockl00p <97256723+Lockl00p@users.noreply.github.com>
Tue, 10 Oct 2023 17:31:27 +0000 (12:31 -0500)
misc/buildfiles/emscripten/prejs.js
misc/buildfiles/emscripten/shell.html
misc/tools/all/xonotic.subr

index ca4ce9a87718346c3d5e28a9c050739cda5d2cea..cb1e820ef9a6e6d2790dc825996692e60e5c8912 100644 (file)
@@ -1,38 +1,22 @@
 //current command in ascii decimal
 let currentcmd = [0,0,0] 
+let currentfile = "";
+const sleep = ms => new Promise(r => setTimeout(r,ms));
+
 let isready = function(){
-    if(FS.analyzePath("/data/",false).exists == true){return 1}
+    if(FS.analyzePath("/save/data",false).exists == true){return 1}
     return 0
 }
 let cmditerate = 0
-console.log("Run Terminal Commands by running cmd(\"command to run here\")")
-cmd = function(input){
-    for (let i = 0; i < input.length; i++){
-        
-        currentcmd[i] = input.charCodeAt(i)
-
-    }
-    currentcmd[input.length] = 10;
-    return 0
-}
-Module['arguments'] = ["-xonotic"]
+Module['arguments'] = ["-xonotic","-basedir /save/data"]
 Module['print'] = function(text){console.log(text);}
 Module['preRun'] = function(){
     
-    function stdin(){
-    /*//if current command is default, it just returns 0, code for null
-    if(currentcmd == [0,0,0]){
-        return 0
-    }
-    //it iterates through the cmd
-    cmditerate++;
-    if(cmditerate - 1 > currentcmd.length - 1) {currentcmd = [0,0,0]; return 10}
-    return currentcmd[cmditerate - 1]
-
-    */ return 10};
+    function stdin(){return 10};
     var stdout = null;
     var stderr = null; 
     FS.init(stdin,stdout,stderr);
-    FS.mkdir('/config')
-    FS.mount(IDBFS,{},"/config");
+    FS.mkdir('/save')
+    FS.mount(IDBFS,{},"/save");
+    
 }
\ No newline at end of file
index b7d7f4e9bc69de84deffb8e6b9634ac70c5ef037..2d51563cba662994921a8ab75d3c7de036f33536 100644 (file)
         var Module = {
             canvas: (function() { return document.getElementById('canvas'); })()
         };
+        const file_reader = new FileReader();
+        file_reader.addEventListener("load", readf);
+        function readf(event){
+            //also heavily derivative of Riot's code on Stack Overflow cause I sure as hell don't udnerstand it.
+            const uint8Arr = new Uint8Array(file_reader.result);
+            console.log(currentname+fname);
+            try {
+                stream = FS.open(currentname+fname,'w');
+            } catch (error) {
+                alert(error.toString() + "... Was that not a directory?");
+                return;
+            }
+            
+            FS.write(stream, uint8Arr, 0, uint8Arr.length, 0);
+            FS.close(stream);
+        }
+
+        var currentname = "";
+        var fname = ""
+        
+        function save_files(){
+            fname = this.files[0].name;
+            file_reader.readAsArrayBuffer(this.files[0]);
+        };
+        
+
+        var file_selector = document.createElement('input');
+        file_selector.setAttribute('type', 'file');
+        file_selector.addEventListener("change", save_files, false);
+        
+
+
     </script>
     
     <!-- Where the script shall be -->
index 2fcfe99a1ec9177623df0cf62f8774dc6a703f98..cbc6b44858fbf1cc468ea539b7d5a209bd8ce6e4 100755 (executable)
@@ -312,7 +312,7 @@ case "$cmd" in
                        verbose emmake make $MAKEFLAGS clean
                fi
                for T in $TARGETS; do
-                       verbose emmake make $MAKEFLAGS LDFLAGS_EXTRA=' -sENVIRONMENT=web --pre-js ../../../../misc/buildfiles/emscripten/prejs.js -lidbfs.js --preload-file ../../../../.tmp/data@/config/ -sSINGLE_FILE -sUSE_ZLIB -sALLOW_MEMORY_GROWTH -sINITIAL_MEMORY=1500MB -sMAXIMUM_MEMORY=4GB' EXE_UNIXSDL="darkplaces-emscripten.html" DP_SSE=0 CFLAGS_EXTRA="-I../../../../misc/builddeps/emscripten/d0_blind_id/include -L../../../../misc/builddeps/emscripten/d0_blind_id/lib -Wl,-rpath,../../../../misc/builddeps/emscripten/d0_blind_id/lib -I../../../../misc/builddeps/emscripten/gmp/include -L../../../../misc/builddeps/emscripten/gmp/lib -Wl,-rpath,../../../../misc/builddeps/emscripten/gmp/lib -L../../../../misc/builddeps/emscripten/jpeg/lib/ -Wl,-rpath,../../../../misc/builddeps/emscripten/jpeg/lib/ -I../../../../misc/builddeps/emscripten/jpeg/include/ -sUSE_SDL=2 -sUSE_ZLIB=1 -DUSE_GLES2" LIBM="" LIBZ="" LIB_JPEG="../../../../misc/builddeps/emscripten/jpeg/lib/libjpeg.a" STRIP=: "$@" "$T"
+                       verbose emmake make $MAKEFLAGS LDFLAGS_EXTRA=' -sENVIRONMENT=web --pre-js ../../../../misc/buildfiles/emscripten/prejs.js --shell-file ../../../../misc/buildfiles/emscripten/shell.html -lidbfs.js -sSINGLE_FILE -sUSE_ZLIB -sALLOW_MEMORY_GROWTH -sINITIAL_MEMORY=1500MB -sMAXIMUM_MEMORY=4GB' EXE_UNIXSDL="darkplaces-emscripten.html" DP_SSE=0 CFLAGS_EXTRA="-I../../../../misc/builddeps/emscripten/d0_blind_id/include -L../../../../misc/builddeps/emscripten/d0_blind_id/lib -Wl,-rpath,../../../../misc/builddeps/emscripten/d0_blind_id/lib -I../../../../misc/builddeps/emscripten/gmp/include -L../../../../misc/builddeps/emscripten/gmp/lib -Wl,-rpath,../../../../misc/builddeps/emscripten/gmp/lib -L../../../../misc/builddeps/emscripten/jpeg/lib/ -Wl,-rpath,../../../../misc/builddeps/emscripten/jpeg/lib/ -I../../../../misc/builddeps/emscripten/jpeg/include/ -sUSE_SDL=2 -sUSE_ZLIB=1 -DUSE_GLES2" LIBM="" LIBZ="" LIB_JPEG="../../../../misc/builddeps/emscripten/jpeg/lib/libjpeg.a" STRIP=: "$@" "$T"
                done
                for T in $BAD_TARGETS; do
                        $ECHO "Warning: discarded invalid client $T."