Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Emscripten platform #1423

Merged
merged 13 commits into from
Jan 30, 2022
Prev Previous commit
Next Next commit
Emscripten: add launcher html
  • Loading branch information
ericoporto committed Jan 23, 2022

Verified

This commit was signed with the committer’s verified signature.
snyk-bot Snyk bot
commit 3415ea65cb9a22b6edb896b72ccab2d5f47760b3
276 changes: 276 additions & 0 deletions Emscripten/launcher_index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Emscripten-Generated Code</title>
<style>
body {
font-family: arial;
margin: 0;
padding: none;
}

.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
textarea.emscripten { font-family: monospace; width: 80%; }
div.emscripten { text-align: center; }
div.emscripten_border { border: 1px solid black; }
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
canvas.emscripten { min-height: 360px; min-width: 640px; border: 0px none; background-color: black; }

.spinner {
height: 50px;
width: 50px;
margin: 0px auto;
-webkit-animation: rotation .8s linear infinite;
-moz-animation: rotation .8s linear infinite;
-o-animation: rotation .8s linear infinite;
animation: rotation 0.8s linear infinite;
border-left: 10px solid rgb(0,150,240);
border-right: 10px solid rgb(0,150,240);
border-bottom: 10px solid rgb(0,150,240);
border-top: 10px solid rgb(100,0,200);
border-radius: 100%;
background-color: rgb(200,100,250);
}
@-webkit-keyframes rotation {
from {-webkit-transform: rotate(0deg);}
to {-webkit-transform: rotate(360deg);}
}
@-moz-keyframes rotation {
from {-moz-transform: rotate(0deg);}
to {-moz-transform: rotate(360deg);}
}
@-o-keyframes rotation {
from {-o-transform: rotate(0deg);}
to {-o-transform: rotate(360deg);}
}
@keyframes rotation {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}

#status {
display: inline-block;
vertical-align: top;
margin-top: 30px;
margin-left: 20px;
font-weight: bold;
color: rgb(120, 120, 120);
}

#progress {
height: 20px;
width: 300px;
}

#controls {
display: inline-block;
float: right;
vertical-align: top;
margin-top: 30px;
margin-right: 20px;
}

#output {
width: 100%;
height: 200px;
margin: 0 auto;
margin-top: 10px;
border-left: 0px;
border-right: 0px;
padding-left: 0px;
padding-right: 0px;
display: block;
background-color: black;
color: white;
font-family: 'Lucida Console', Monaco, monospace;
outline: none;
}
</style>
</head>
<body>
<script>

var fileresulthere = {};
var game_file = {};
file_reader_fr = 0;

function agsAttachFileInput(fileInput)
{
if (fileInput.files.length == 0)
return;

file_total_count = fileInput.files.length;
for(var i=0; i<file_total_count; i++)
{
if((fileInput.files[i].name != "winsetup.exe") &&
(fileInput.files[i].name.endsWith(".exe") ||
fileInput.files[i].name.endsWith(".ags")))
{
game_file = fileInput.files[i];
break;
}
}

file_read_count = 0;

if(file_reader_fr == 0)
{
file_reader_fr = new FileReader();
}

file_reader_fr.onload = function () {
fileresulthere = file_reader_fr.result;
//fileInput.value = '';

var data = new Uint8Array(fileresulthere);
Module['FS_createDataFile']('/', fileInput.files[file_read_count].name, data, true, true, true);

file_read_count=file_read_count+1;

if(file_read_count == file_total_count)
{
Module.callMain(['/' + game_file.name , '--windowed']);
}
else
{
file_reader_fr.readAsArrayBuffer(fileInput.files[file_read_count]);
}
};
file_reader_fr.readAsArrayBuffer(fileInput.files[0]);

}
</script>

<div class="spinner" id='spinner'></div>
<div class="emscripten" id="status">Downloading...</div>

<span id='controls'>
<span><input type="file"
id="agsgamepkgid" name="agsgamepkg" multiple="multiple" onchange="agsAttachFileInput(this);"
accept="*/*"><label for="agsgamepkgid">Put a .ags game with every dependencies built in.</label></span>
<span hidden=1><input type="checkbox" id="resize" checked>Resize canvas</span>
<span><input type="checkbox" id="pointerLock" checked>Lock/hide mouse pointer &nbsp;&nbsp;&nbsp;</span>

</span>

<div class="emscripten">
<progress value="0" max="100" id="progress" hidden=1></progress>
</div>


<div class="emscripten_border">
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
</div>
<textarea id="output" rows="8"></textarea>

<script type='text/javascript'>
function getPrettyTime()
{
var d = new Date();
var h = addZero(d.getHours(), 2);
var m = addZero(d.getMinutes(), 2);
var s = addZero(d.getSeconds(), 2);
var ms = addZero(d.getMilliseconds(), 3);
var fullDate = h + ":" + m + ":" + s + ":" + ms;

function addZero(x, n) {
while (x.toString().length < n) {
x = "0" + x;
}
return x;
}
return fullDate;
}



var statusElement = document.getElementById('status');
var progressElement = document.getElementById('progress');
var spinnerElement = document.getElementById('spinner');

var Module = {
arguments: [],
preRun: [],
postRun: [],
print: (function() {
var element = document.getElementById('output');
if (element) element.value = ''; // clear browser cache
return function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
// These replacements are necessary if you render to raw HTML
//text = text.replace(/&/g, "&amp;");
//text = text.replace(/</g, "&lt;");
//text = text.replace(/>/g, "&gt;");
//text = text.replace('\n', '<br>', 'g');
var print_text = getPrettyTime() + ": " + text;
console.log(print_text);
if (element) {
element.value += print_text + "\n";
element.scrollTop = element.scrollHeight; // focus on bottom
}
};
})(),
printErr: function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.error(text);
},
canvas: (function() {
var canvas = document.getElementById('canvas');

window.addEventListener ("resize", function (e) {
Module.canvas.style.width = canvas.clientWidth + "px";
Module.canvas.style.height = canvas.clientHeight + "px";
}, true);
canvas

// As a default initial behavior, pop up an alert when webgl context is lost. To make your
// application robust, you may want to override this behavior before shipping!
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);

return canvas;
})(),
setStatus: function(text) {
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
if (text === Module.setStatus.last.text) return;
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
var now = Date.now();
if (m && now - Module.setStatus.last.time < 30) return; // if this is a progress update, skip it if too soon
Module.setStatus.last.time = now;
Module.setStatus.last.text = text;
if (m) {
text = m[1];
progressElement.value = parseInt(m[2])*100;
progressElement.max = parseInt(m[4])*100;
progressElement.hidden = false;
spinnerElement.hidden = false;
} else {
progressElement.value = null;
progressElement.max = null;
progressElement.hidden = true;
if (!text) spinnerElement.hidden = true;
}
statusElement.innerHTML = text;
},
totalDependencies: 0,
monitorRunDependencies: function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
}
};
Module.setStatus('Downloading...');
window.onerror = function(event) {
Module.setStatus('Exception thrown, see JavaScript console');
spinnerElement.style.display = 'none';
Module.setStatus = function(text) {
if (text) Module.printErr('[post-exception status] ' + text);
};
};


</script>
{{{ SCRIPT }}}
</body>
</html>