Skip to content

Commit

Permalink
Whitespace and other nitpicks
Browse files Browse the repository at this point in the history
Signed-off-by: bones_was_here <[email protected]>
  • Loading branch information
bones-was-here committed Aug 10, 2024
1 parent 8e5df4e commit e9c4587
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
cd ..
# fail if there's any warnings
export CC="cc"
#export CC="cc"
make emscripten-release
Expand Down
100 changes: 51 additions & 49 deletions wasm/standalone-shell.htm
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,65 @@
<html>
<!-- Thank You Stack Overflow! -->
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8, width=device-width, initial-scale=1">
<title>Darkplaces</title>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8, width=device-width, initial-scale=1">
<title>DarkPlaces</title>
</head>

<body style="margin:0;padding:0">

<!-- Create the canvas that the C++ code will draw into -->
<canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<!-- Create the canvas that the C++ code will draw into -->
<canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>

<!-- Allow the C++ to access the canvas element -->
<script type='text/javascript'>
var Module = {
canvas: (function() { return document.getElementById('canvas'); })()
};
Module['preRun'] = []
</script>
<script type='text/javascript'>

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);
alert("File Uploaded");
}
<!-- Allow the C++ to access the canvas element -->
<script type='text/javascript'>
var Module = {
canvas: (function() { return document.getElementById('canvas'); })()
};
Module['preRun'] = []
</script>

var currentname = "";
var fname = ""

function save_files(){
fname = this.files[0].name;
file_reader.readAsArrayBuffer(this.files[0]);
};

<script type='text/javascript'>
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 understand it.
// Riot used the MIT license.
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;
}

var file_selector = document.createElement('input');
file_selector.setAttribute('type', 'file');
file_selector.addEventListener("change", save_files, false);
FS.write(stream, uint8Arr, 0, uint8Arr.length, 0);
FS.close(stream);
alert("File Uploaded");
}

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 -->
{{{ SCRIPT }}}

</script>

<!-- Where the script shall be -->
{{{ SCRIPT }}}

</body>

</html>
</html>
103 changes: 53 additions & 50 deletions wasm/standaloneprejs.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,63 @@
//current command in ascii decimal
let currentcmd = [0,0,0]
let currentfile = "";
const sleep = ms => new Promise(r => setTimeout(r,ms));
Module['print'] = function(text){console.log(text);}
const sleep = ms => new Promise(r => setTimeout(r, ms));

Module['print'] = function(text) { console.log(text); }

Module['preRun'] = function()
{

function stdin(){return 10};
var stdout = null;
var stderr = null;
FS.init(stdin,stdout,stderr);
FS.mount(IDBFS,{},"/home/web_user/");
FS.symlink("/home/web_user","/save");

function stdin() { return 10 };
var stdout = null;
var stderr = null;
FS.init(stdin, stdout, stderr);
FS.mount(IDBFS, {}, "/home/web_user/");
FS.symlink("/home/web_user", "/save");
}

Module['noInitialRun'] = true

document.addEventListener('click', (ev) => {
console.log("event is captured only once.");
args = []
if(window.location.href.indexOf("file://") > -1)
{
try
{
args = args.concat(prompt("Enter command line arguments").split(" "))
} catch (error)
{
console.log("Error: ",error);
console.log("Failed to concat extra arguments (likely passed nothing for the argument)")
}

console.log("event is captured only once.");
args = []
if(window.location.href.indexOf("file://") > -1)
{
try
{
args = args.concat(prompt("Enter command line arguments").split(" "))
}
catch (error)
{
console.log("Error: ", error);
console.log("Failed to concat extra arguments (likely passed nothing for the argument)")
}
}
else
{
parms = new URLSearchParams(window.location.search);
try
{
args = args.concat(parms.get("args").split(" "))
}
catch (error)
{
console.log("Error: ", error);
console.log("Failed to concat extra arguments (likely passed nothing for the argument)")
}
}

} else
{
parms = new URLSearchParams(window.location.search);
try
{
args = args.concat(parms.get("args").split(" "))
} catch (error)
{
console.log("Error: ",error);
console.log("Failed to concat extra arguments (likely passed nothing for the argument)")
}

}
FS.syncfs(true,function(){
if(FS.analyzePath("/preload/runhere").exists){
FS.symlink("/preload","/home/web_user/games");
args = args.concat(["-basedir","/home/web_user/games"])
}
else{
args = args.concat(["-basedir","/home/web_user/"])
}

Module.callMain(args);
});

}, { once: true });
FS.syncfs(true, function()
{
if(FS.analyzePath("/preload/runhere").exists)
{
FS.symlink("/preload", "/home/web_user/games");
args = args.concat(["-basedir", "/home/web_user/games"])
}
else
{
args = args.concat(["-basedir", "/home/web_user/"])
}


Module.callMain(args);
});
}, { once: true });

0 comments on commit e9c4587

Please sign in to comment.