Deploying to built from @ 2c08238259 🚀

This commit is contained in:
pulsejet 2020-10-19 06:49:10 +00:00
parent 3cd3eb5a31
commit 2c8df35ec7
4 changed files with 227 additions and 40 deletions

View File

@ -3,7 +3,10 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="manifest" href="manifest.webmanifest">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<script src="js/localforage.min.js"></script> <script src="js/localforage.min.js"></script>
<script src="js/drive.js"></script>
<script src="gameasync/mapping.js"></script> <script src="gameasync/mapping.js"></script>
<title>MKXP</title> <title>MKXP</title>
@ -26,7 +29,10 @@
border: 0px none; border: 0px none;
background-color: black; background-color: black;
height: 100%; height: 100%;
max-height: 100vh;
max-width: 100vw;
} }
#spinner { #spinner {
position: fixed; position: fixed;
bottom: 40px; bottom: 40px;
@ -90,6 +96,45 @@
padding: 3px 10px; padding: 3px 10px;
border-top-right-radius: 5px; border-top-right-radius: 5px;
} }
#dpad, #apad {
position: fixed;
bottom: 0; left: 0;
height: 30vh; max-height: 30vw;
width: 30vh; max-width: 30vw;
transform: translate(55%, -5%);
}
#apad {
right: 0; left: unset;
transform: unset;
width: 15vh; max-width: 15vw;
}
#dpad *, #apad * {
position: absolute;
height: 15vh; max-height: 15vw;
width: 15vh; max-width: 15vw;
background-color: gray;
opacity: 0.3;
}
#apad * {
border-radius: 50%;
}
#d-up { transform: translateY(-100%); }
#d-left { transform: translateX(-100%); }
#d-down { transform: translateY(100%); }
#d-right { transform: translateX(100%); }
#ap-b { transform: translate(-130%, 90%); }
#ap-c { transform: translate(-15%, -25%); }
#ap-a {
height: 7vh; max-height: 7vw;
width: 7vh; max-width: 7vw;
top: 50%;
transform: translate(25%, 25%);
}
</style> </style>
</head> </head>
<body> <body>
@ -100,6 +145,20 @@
<div id="progress">Loading ...</div> <div id="progress">Loading ...</div>
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1 width="640" height="480"></canvas> <canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1 width="640" height="480"></canvas>
<div id="dpad">
<div id="d-up"></div>
<div id="d-right"></div>
<div id="d-down"></div>
<div id="d-left"></div>
<div id="d-pl"></div>
</div>
<div id="apad">
<div id="ap-c"></div>
<div id="ap-b"></div>
<div id="ap-a"></div>
</div>
</div> </div>
<div onclick="fullscreen()" id="fullscreen"> <div onclick="fullscreen()" id="fullscreen">
@ -119,7 +178,7 @@
window.saveFile = function(filename) { window.saveFile = function(filename) {
const buf = FS.readFile('/game/' + filename); const buf = FS.readFile('/game/' + filename);
const b64 = btoa(String.fromCharCode.apply(null, buf)); const b64 = _bytesToBase64(buf);
localforage.setItem(namespace + filename, b64); localforage.setItem(namespace + filename, b64);
localforage.getItem(namespace, function(err, res) { localforage.getItem(namespace, function(err, res) {
@ -141,7 +200,7 @@
localforage.getItem(namespace + key, (err, res) => { localforage.getItem(namespace + key, (err, res) => {
if (err) return; if (err) return;
const buf = new Uint8Array(atob(res).split('').map((c) => c.charCodeAt(0))); const buf = _base64ToBytes(res);
FS.writeFile('/game/' + key, buf); FS.writeFile('/game/' + key, buf);
}); });
}); });
@ -201,6 +260,7 @@
function fullscreen() { function fullscreen() {
document.getElementById('main').requestFullscreen(); document.getElementById('main').requestFullscreen();
screen.orientation.lock("landscape")
} }
window.onerror = function() { window.onerror = function() {
@ -291,6 +351,106 @@
document.body.appendChild(s); document.body.appendChild(s);
}); });
}, 500); }, 500);
function simulateKeyEvent(eventType, keyCode, charCode) {
var e = document.createEventObject ? document.createEventObject() : document.createEvent("Events");
if (e.initEvent) e.initEvent(eventType, true, true);
e.keyCode = keyCode;
e.which = keyCode;
e.charCode = charCode;
// Dispatch directly to Emscripten's html5.h API (use this if page uses emscripten/html5.h event handling):
if (typeof JSEvents !== 'undefined' && JSEvents.eventHandlers && JSEvents.eventHandlers.length > 0) {
for(var i = 0; i < JSEvents.eventHandlers.length; ++i) {
if ((JSEvents.eventHandlers[i].target == Module['canvas'] || JSEvents.eventHandlers[i].target == window)
&& JSEvents.eventHandlers[i].eventTypeString == eventType) {
JSEvents.eventHandlers[i].handlerFunc(e);
}
}
} else {
// Dispatch to browser for real (use this if page uses SDL or something else for event handling):
Module['canvas'].dispatchEvent ? Module['canvas'].dispatchEvent(e) : Module['canvas'].fireEvent("on" + eventType, e);
}
}
// Mappings
const keyMap = {};
const keysDown = {};
/** Add virtual key binding */
function bindKey(elem, key) {
keyMap[elem] = key;
const ne = document.getElementById(elem);
ne.addEventListener('touchstart', function(e) {
e.preventDefault();
simulateKeyEvent('keydown', key);
keysDown[e.target.id] = elem;
});
ne.addEventListener('touchend', function(e) {
e.preventDefault();
if (keysDown[e.target.id] && keyMap[keysDown[e.target.id]]) {
simulateKeyEvent('keyup', keyMap[keysDown[e.target.id]]);
}
keysDown[e.target.id] = 0;
});
ne.addEventListener('touchmove', function(event) {
const myLocation = event.changedTouches[0];
const realTarget = document.elementFromPoint(myLocation.clientX, myLocation.clientY).id;
const origTarget = keysDown[myLocation.target.id];
if (origTarget !== realTarget) {
if (origTarget) {
simulateKeyEvent('keyup', keyMap[origTarget]);
keysDown[myLocation.target.id] = 0;
}
if (keyMap[realTarget]) {
simulateKeyEvent('keydown', keyMap[realTarget]);
keysDown[myLocation.target.id] = realTarget;
}
}
});
}
function is_touch_device() {
try {
document.createEvent("TouchEvent");
return true;
} catch (e) {
return false;
}
}
if (!is_touch_device()) {
document.getElementById('dpad').style.display = 'none';
document.getElementById('apad').style.display = 'none';
}
// Add all bindings
bindKey('d-up', 38);
bindKey('d-right', 39);
bindKey('d-down', 40);
bindKey('d-left', 37);
bindKey('ap-c', 67);
bindKey('ap-b', 88);
bindKey('ap-a', 90);
const resize = function() {
const el = document.getElementById('canvas');
if (window.innerHeight > window.innerWidth) {
el.style.height = 'unset';
el.style.width = '100%';
} else {
el.style.width = 'unset';
el.style.height = '100%';
}
}
window.addEventListener('resize', resize);
resize();
</script> </script>
<!-- <script async type="text/javascript" src="mkxp.js"></script> --> <!-- <script async type="text/javascript" src="mkxp.js"></script> -->

20
js/drive.js Normal file
View File

@ -0,0 +1,20 @@
// https://stackoverflow.com/a/9458996
function _bytesToBase64(bytes) {
var binary = '';
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
// https://stackoverflow.com/a/21797381
function _base64ToBytes(base64) {
var binary_string = window.atob(base64);
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes;
}

7
manifest.webmanifest Normal file
View File

@ -0,0 +1,7 @@
{
"name": "Knight Blade",
"short_name": "KN_E",
"description": "Sample RPG XP game",
"display": "fullscreen",
"scope": "/"
}

BIN
mkxp.wasm

Binary file not shown.