Noah Petherbridge
af67b20d9b
* Initial WebAssembly build target for Doodle in the wasm/ folder. * Add a new render.Engine implementation, lib/render/canvas that uses the HTML 5 Canvas API instead of SDL2 for the WebAssembly target. * Ported the basic DrawLine(), DrawBox() etc. functions from SDL2 to Canvas context2d API. * Fonts are handled with CSS embedded fonts named after the font filename and defined in wasm/index.html * `make wasm` builds the WASM program, and `make wasm-serve` runs a dev Go server that hosts the WASM file for development. The server also watches the dev tree for *.go files and rebuilds the WASM binary automatically on change. * This build "basically" runs the game. UI and fonts all work and mouse movements and clicks are detected. No wallpaper support yet or texture caching (which will crash the game as soon as you click and draw a pixel in your map!)
55 lines
1.2 KiB
HTML
55 lines
1.2 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Project: Doodle</title>
|
|
<style>
|
|
#canvas {
|
|
position: fixed;
|
|
width: 100%;
|
|
height: 100%;
|
|
top: 0;
|
|
right: 0;
|
|
left: 0;
|
|
bottom: 0;
|
|
}
|
|
|
|
@font-face {
|
|
font-family: "DejaVuSansMono";
|
|
src: url("fonts/DejaVuSansMono.ttf") format("truetype");
|
|
}
|
|
@font-face {
|
|
font-family: "DejaVuSans";
|
|
src: url("fonts/DejaVuSans.ttf") format("truetype");
|
|
}
|
|
@font-face {
|
|
font-family: "DejaVuSans-Bold";
|
|
src: url("fonts/DejaVuSans-Bold.ttf") format("truetype");
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<script src="wasm_exec.js"></script>
|
|
<script>
|
|
if (!WebAssembly.instantiateStreaming) { // polyfill
|
|
WebAssembly.instantiateStreaming = async (resp, importObject) => {
|
|
const source = await (await resp).arrayBuffer();
|
|
return await WebAssembly.instantiate(source, importObject);
|
|
};
|
|
}
|
|
|
|
(function() {
|
|
const go = new Go();
|
|
WebAssembly.instantiateStreaming(fetch("doodle.wasm"), go.importObject).then(result => {
|
|
console.clear();
|
|
go.run(result.instance);
|
|
WebAssembly.instantiate(result.module, go.importObject); // reset instance
|
|
})
|
|
})();
|
|
</script>
|
|
|
|
<canvas id="canvas"></canvas>
|
|
|
|
</body>
|
|
</html>
|