-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1 lines (1 loc) · 2.44 KB
/
index.html
File metadata and controls
1 lines (1 loc) · 2.44 KB
1
<!DOCTYPE html><html><head> <title>Space Revolution</title> <meta charset="utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body> <canvas id="screen" class="canvas" style="position:absolute;top:0px;left:0px;"></canvas> <script>var Module={print: function (text){console.log('stdout: ' + text)}, printErr: function (text){console.error('stderr: ' + text)},}; </script> <script src="index.js"></script> <script>async function loadImage(src, id){const imgBlob=await fetch(src).then(resp=> resp.blob()); const img=await createImageBitmap(imgBlob); const canvas=document.createElement('canvas'); canvas.width=img.width; canvas.height=img.height; const ctx=canvas.getContext('2d'); ctx.drawImage(img, 0, 0); var imageData=ctx.getImageData(0, 0, img.width, img.height); dataPointer=Module._malloc(imageData.data.length); Module.writeArrayToMemory(imageData.data, dataPointer); Module._addImage(dataPointer, img.width, img.height, id);}async function loadMap(src){const data=await fetch(src).then(resp=> resp.text()); dataPointer=Module._malloc(data.length); Module.stringToUTF8(data, dataPointer, data.length); Module._addMap(dataPointer);}Module.renderImageFromMemory=function (){this.canvasContext.putImageData(this.imageData, 0, 0);}; Module.renderSetup=function (){var canvas=document.getElementById('screen'); this.canvasContext=canvas.getContext('2d'); var width=this._getScreenWidth(); var height=this._getScreenHeight(); var offset=this._getMemoryOffset(); canvas.width=width; canvas.height=height; this.imageData=new ImageData(new Uint8ClampedArray(this.wasmMemory.buffer, offset, width * height * 4), width, height);}; Module.loadAssets=function (){loadImage("assets/characters/mcharanimall.png", 0); loadImage("assets/tileset.png", 1); loadImage("assets/masikfont.png", 2); loadImage("assets/characters/joskaanimall.png", 3); loadImage("gwgc201819_overlay.png", 4); loadMap("assets/maps.txt");}; Module.onRuntimeInitialized=function (){document.addEventListener('keydown', function (event){if (event.getModifierState("Alt") && event.keyCode==13){openFullscreen();}}); Module.loadAssets();}; function openFullscreen(){var canvas=document.getElementById('screen'); if (canvas.requestFullscreen){canvas.requestFullscreen();}else if (canvas.mozRequestFullScreen){canvas.mozRequestFullScreen();}else if (canvas.webkitRequestFullscreen){canvas.webkitRequestFullscreen();}else if (canvas.msRequestFullscreen){canvas.msRequestFullscreen();}}</script></body></html>