mirror of
https://github.com/FlamedDogo99/EaglerMobile.git
synced 2024-11-09 22:16:04 -08:00
350 lines
29 KiB
JavaScript
350 lines
29 KiB
JavaScript
|
// ==UserScript==
|
||
|
// @name Eagler Mobile
|
||
|
// @description Allows eaglercraft to run on mobile, adds touch controls, and fixes a few mobile-related crashes
|
||
|
// @author FlamedDogo99
|
||
|
// @namespace http://github.com/FlamedDogo99
|
||
|
// @downloadURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.js
|
||
|
//
|
||
|
// @license Apache License 2.0 - http://www.apache.org/licenses/
|
||
|
// @match https://eaglercraft.com/mc/*
|
||
|
// @version 1.1
|
||
|
// @updateURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.js
|
||
|
// @run-at document-start
|
||
|
// ==/UserScript==
|
||
|
|
||
|
|
||
|
// Hides inventory button
|
||
|
window.inInventory = false;
|
||
|
// Used for changing touchmove events to mousemove events
|
||
|
var previousX = null;
|
||
|
var previousY = null;
|
||
|
// Key and mouse events
|
||
|
function keyEvent(name, state) {
|
||
|
const keyName = name.toUpperCase().charCodeAt(0)
|
||
|
window.dispatchEvent(new KeyboardEvent(state, {
|
||
|
key: name,
|
||
|
keyCode: keyName,
|
||
|
which: keyName
|
||
|
}));
|
||
|
}
|
||
|
function shiftKey(state) {
|
||
|
window.dispatchEvent(new KeyboardEvent(state, {
|
||
|
keyCode: 16,
|
||
|
which: 16
|
||
|
}));
|
||
|
}
|
||
|
function mouseEvent(number, state, canvas) {
|
||
|
canvas.dispatchEvent(new PointerEvent(state, {"button": number}))
|
||
|
}
|
||
|
// POINTERLOCK
|
||
|
// When requestpointerlock is called, this dispatches an event, saves the requested element to window.fakelock, and unhides the touch controls
|
||
|
window.fakelock = null;
|
||
|
|
||
|
Element.prototype.requestPointerLock = function() {
|
||
|
window.fakelock = this
|
||
|
document.dispatchEvent(new Event('pointerlockchange'));
|
||
|
console.log("requested pointerlock")
|
||
|
var hideButtonStyleDOM = document.getElementById('hideButtonStyle');
|
||
|
var hideInventoryStyleDOM = document.getElementById('hideInventoryStyle');
|
||
|
hideButtonStyleDOM.disabled = true;
|
||
|
hideInventoryStyleDOM.disabled = true;
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
|
||
|
// Makes pointerLockElement return window.fakelock
|
||
|
Object.defineProperty(document, "pointerLockElement", {
|
||
|
get: function() {
|
||
|
return window.fakelock;
|
||
|
}
|
||
|
});
|
||
|
// When exitPointerLock is called, this dispatches an event, clears the
|
||
|
document.exitPointerLock = function() {
|
||
|
window.fakelock = null
|
||
|
document.dispatchEvent(new Event('pointerlockchange'));
|
||
|
var hideButtonStyleDOM = document.getElementById('hideButtonStyle');
|
||
|
var hideInventoryStyleDOM = document.getElementById('hideInventoryStyle');
|
||
|
hideButtonStyleDOM.disabled = false;
|
||
|
hideInventoryStyleDOM.disabled = window.inInventory;
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// FULLSCREEN
|
||
|
window.fakefull = null;
|
||
|
// Stops the client from crashing when fullscreen is requested
|
||
|
Element.prototype.requestFullscreen = function() {
|
||
|
window.fakefull = this
|
||
|
document.dispatchEvent(new Event('fullscreenchange'));
|
||
|
return true
|
||
|
}
|
||
|
Object.defineProperty(document, "fullscreenElement", {
|
||
|
get: function() {
|
||
|
return window.fakefull;
|
||
|
}
|
||
|
});
|
||
|
document.exitFullscreen = function() {
|
||
|
window.fakefull = null
|
||
|
document.dispatchEvent(new Event('fullscreenchange'));
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// FILE UPLOADING
|
||
|
// Safari doesn't recognize the element.click() used to display the file uplaoder as an action performed by the user, so it ignores it.
|
||
|
// This hijacks the element.createElement() function to add the file upload to the DOM, so the user can manually press the button again.
|
||
|
var oldCreate = document.createElement;
|
||
|
document.createElement = function(type) {
|
||
|
this.oldCreate = oldCreate;
|
||
|
var element = this.oldCreate(type);
|
||
|
if(type == "input") {
|
||
|
var newElement = document.querySelector('input');
|
||
|
if(!newElement) {
|
||
|
this.body.appendChild(element);
|
||
|
newElement = document.querySelector('input');
|
||
|
newElement.addEventListener('change', function(e) {
|
||
|
this.hidden = true;
|
||
|
})
|
||
|
}
|
||
|
newElement.value = null;
|
||
|
newElement.style.cssText ="position:absolute;left:0%;right:100%;top:0%;bottom:100%;width:100%;height:100%;background-color:rgba(255,255,255,0.5);";
|
||
|
newElement.hidden = false;
|
||
|
return newElement;
|
||
|
}
|
||
|
return this.oldCreate(type);
|
||
|
}
|
||
|
// CSS for touch screen buttons, along with fixing iOS's issues with 100vh ignoring the naviagtion bar, and actually disabling zoom because safari ignores user-scalable=no :(
|
||
|
let customStyle = document.createElement("style");
|
||
|
customStyle.textContent = `
|
||
|
button {
|
||
|
position: absolute;
|
||
|
width: 9.5vh;
|
||
|
height: 9.5vh;
|
||
|
font-size:4vh;
|
||
|
-webkit-user-select: none;
|
||
|
-ms-user-select: none;
|
||
|
user-select: none;
|
||
|
line-height: 0px;
|
||
|
padding:0px;
|
||
|
color: #ffffff;
|
||
|
text-shadow: 0.35vh 0.35vh #000000;
|
||
|
box-sizing: content-box;
|
||
|
image-rendering: pixelated;
|
||
|
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAAUCAYAAACnOeyiAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAUGVYSWZNTQAqAAAACAACARIAAwAAAAEAAQAAh2kABAAAAAEAAAAmAAAAAAADoAEAAwAAAAEAAQAAoAIABAAAAAEAAAACoAMABAAAAAEAAAAUAAAAABBl8JYAAAIvaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJYTVAgQ29yZSA2LjAuMCI+CiAgIDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+CiAgICAgIDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiCiAgICAgICAgICAgIHhtbG5zOmV4aWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20vZXhpZi8xLjAvIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWURpbWVuc2lvbj4yMDwvZXhpZjpQaXhlbFlEaW1lbnNpb24+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yPC9leGlmOlBpeGVsWERpbWVuc2lvbj4KICAgICAgICAgPGV4aWY6Q29sb3JTcGFjZT4xPC9leGlmOkNvbG9yU3BhY2U+CiAgICAgICAgIDx0aWZmOk9yaWVudGF0aW9uPjE8L3RpZmY6T3JpZW50YXRpb24+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgp+x0mNAAAAU0lEQVQIHV2OXQoAIAiDdSIdt0N3iAiMfhz00IPzw01URWSdEtRabxe01ghmRlgrIwJ352TOSUg9ggdjDFqlFAJAF733z3pbqvqF34mISOsG8o8N3G8YG4Y+w98AAAAASUVORK5CYII=) no-repeat right center, url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAAAUCAYAAADIpHLKAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAUGVYSWZNTQAqAAAACAACARIAAwAAAAEAAQAAh2kABAAAAAEAAAAmAAAAAAADoAEAAwAAAAEAAQAAoAIABAAAAAEAAADIoAMABAAAAAEAAAAUAAAAAMWDgdMAAAIxaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJYTVAgQ29yZSA2LjAuMCI+CiAgID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0g2f8dFZb/zicq3y1Js59vBqqBeH3PSmEy48HF62bqwBJhSwQsAKe7wwCUpsuYvt8kEQAT2JaHhyG5gUnC7cwHop1ZcP639o46BlmjiD8ZLT0heCHy9f/VQXD1+89URTOuT1oqvN5NMIz/TJ+G+yfv3F0k5zfPuvZXzh64VW+empbzixac700N/LxudMux+FmS+3udg3C3t58cOYzbQZt69uHOo0a7Vh+LxL9UoXfPNxxiPOb9UHH2uNVzx8/cKlG45/8joXp4vB0cZfjP/4SStodTGaS
|
||
|
background-size: contain, cover;
|
||
|
outline:none;
|
||
|
box-shadow: none;
|
||
|
border: none;
|
||
|
}
|
||
|
button:active {
|
||
|
position: absolute;
|
||
|
width: 9.5vh;
|
||
|
height: 9.5vh;
|
||
|
font-size:4vh;
|
||
|
-webkit-user-select: none;
|
||
|
-ms-user-select: none;
|
||
|
user-select: none;
|
||
|
line-height: 0px;
|
||
|
padding:0px;
|
||
|
color: #ffffff;
|
||
|
text-shadow: 0.35vh 0.35vh #000000;
|
||
|
box-sizing: content-box;
|
||
|
image-rendering: pixelated;
|
||
|
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAAUCAYAAACnOeyiAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAUGVYSWZNTQAqAAAACAACARIAAwAAAAEAAQAAh2kABAAAAAEAAAAmAAAAAAADoAEAAwAAAAEAAQAAoAIABAAAAAEAAAACoAMABAAAAAEAAAAUAAAAABBl8JYAAAIvaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJYTVAgQ29yZSA2LjAuMCI+CiAgIDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+CiAgICAgIDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiCiAgICAgICAgICAgIHhtbG5zOmV4aWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20vZXhpZi8xLjAvIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWURpbWVuc2lvbj4yMDwvZXhpZjpQaXhlbFlEaW1lbnNpb24+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yPC9leGlmOlBpeGVsWERpbWVuc2lvbj4KICAgICAgICAgPGV4aWY6Q29sb3JTcGFjZT4xPC9leGlmOkNvbG9yU3BhY2U+CiAgICAgICAgIDx0aWZmOk9yaWVudGF0aW9uPjE8L3RpZmY6T3JpZW50YXRpb24+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgp+x0mNAAAAWUlEQVQIHV2OUQrAMAhDNaX01vverXYPL1IES9ca1o99GB8moioic5Xgup/dBWZGKKUQ5syIoNbKyRiDkLoEB9ydVmuNANBF7/1nnS1VpXWORgQnH+xA/vECGrAYeIZg8CAAAAAASUVORK5CYII=) no-repeat right center, url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAAAUCAYAAADIpHLKAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAUGVYSWZNTQAqAAAACAACARIAAwAAAAEAAQAAh2kABAAAAAEAAAAmAAAAAAADoAEAAwAAAAEAAQAAoAIABAAAAAEAAADIoAMABAAAAAEAAAAUAAAAAMWDgdMAAAIxaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJYTVAgQ29yZSA2LjAuMCI+CiAgIDxyZGY6UkRGIHhtbG5zOnJ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FhErxcoYTMay04Zj83BoQHZ4iG7nKb5Naj/78mU73MGkCSLyZqeeuXvB6xzvqQH9NJqj5tnvu/7NWd9N5ZXGgS2PimzCY2oidkSsaYPDYCyiFrAYT89k7sh35yU+3+KLqXcd8WYc3uCRJ99isUvv8U2X3fX1dtiYv75+HnXVB6tVb5xjgfgi1ol346aoHBMFMSb4VASQgLm271nnQCqWo8SBszqNnZ93IfmTqDiK4jpFk8DZ2Xw0joXFp3m+iHm3+oxb
|
||
|
background-size: contain, cover;
|
||
|
outline:none;
|
||
|
box-shadow: none;
|
||
|
border: none;
|
||
|
|
||
|
}
|
||
|
html, body {
|
||
|
height: -webkit-fill-available !important;
|
||
|
touch-action: pan-x pan-y;
|
||
|
}
|
||
|
`;
|
||
|
document.documentElement.appendChild(customStyle);
|
||
|
|
||
|
// Lazy way to hide touch controls through CSS.
|
||
|
let hideButtonStyle = document.createElement("style");
|
||
|
hideButtonStyle.id = "hideButtonStyle";
|
||
|
hideButtonStyle.textContent = `
|
||
|
#hideButton {
|
||
|
display: none;
|
||
|
}`;
|
||
|
document.documentElement.appendChild(hideButtonStyle);
|
||
|
let hideInventoryStyle = document.createElement("style");
|
||
|
hideInventoryStyle.id = "hideInventoryStyle";
|
||
|
hideInventoryStyle.textContent = `
|
||
|
#hideInventory {
|
||
|
display: none;
|
||
|
}`;
|
||
|
document.documentElement.appendChild(hideInventoryStyle);
|
||
|
|
||
|
// The canvas is created by the client after it finishes unzipping and loading. When the canvas is created, this applies any necessary event listeners
|
||
|
function waitForElm(selector) {
|
||
|
return new Promise(resolve => {
|
||
|
if (document.querySelector(selector)) {
|
||
|
return resolve(document.querySelector(selector));
|
||
|
}
|
||
|
const observer = new MutationObserver(mutations => {
|
||
|
if (document.querySelector(selector)) {
|
||
|
observer.disconnect();
|
||
|
resolve(document.querySelector(selector));
|
||
|
}
|
||
|
});
|
||
|
observer.observe(document.documentElement, {
|
||
|
childList: true,
|
||
|
subtree: true
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
|
||
|
waitForElm('canvas').then(() => {insertCanvasElements()});
|
||
|
function insertCanvasElements() {
|
||
|
// Translates touchmove events to mousemove events
|
||
|
var canvas = document.querySelector('canvas');
|
||
|
canvas.addEventListener("touchmove", (e) => {
|
||
|
const touch = e.targetTouches[0]; // We can get away with this because every other touch event will be on different elements
|
||
|
|
||
|
if (!previousX) {
|
||
|
previousX = touch.pageX;
|
||
|
previousY = touch.pageY;
|
||
|
}
|
||
|
e.movementX = touch.pageX - previousX;
|
||
|
e.movementY = touch.pageY - previousY;
|
||
|
var evt = new MouseEvent("mousemove", {
|
||
|
movementX: e.movementX,
|
||
|
movementY: e.movementY
|
||
|
});
|
||
|
canvas.dispatchEvent(evt);
|
||
|
previousX = touch.pageX;
|
||
|
previousY = touch.pageY;
|
||
|
event.preventDefault();
|
||
|
}, false);
|
||
|
|
||
|
canvas.addEventListener("touchend", (e) => {
|
||
|
previousX = null;
|
||
|
previousY = null;
|
||
|
}, false)
|
||
|
// Adds all of the touch screen controls
|
||
|
// Theres probably a better way to do this but this works for now
|
||
|
var forwardButton = document.createElement('button');
|
||
|
forwardButton.id = "hideButton"
|
||
|
forwardButton.textContent = "▲";
|
||
|
forwardButton.style.cssText = "left:10vh;bottom:20vh;"
|
||
|
forwardButton.addEventListener("touchstart", function(e){keyEvent("w", "keydown")}, false);
|
||
|
forwardButton.addEventListener("touchend", function(e){keyEvent("w", "keyup")}, false);
|
||
|
forwardButton.addEventListener("touchmove", function(e){e.preventDefault()}, false);
|
||
|
document.body.appendChild(forwardButton);
|
||
|
var rightButton = document.createElement('button');
|
||
|
rightButton.id = "hideButton"
|
||
|
rightButton.textContent = "▶";
|
||
|
rightButton.style.cssText = "left:20vh;bottom:10vh;"
|
||
|
rightButton.addEventListener("touchstart", function(e){keyEvent("d", "keydown")}, false);
|
||
|
rightButton.addEventListener("touchend", function(e){keyEvent("d", "keyup")}, false);
|
||
|
rightButton.addEventListener("touchmove", function(e){e.preventDefault()}, false);
|
||
|
document.body.appendChild(rightButton);
|
||
|
var leftButton = document.createElement('button');
|
||
|
leftButton.id = "hideButton"
|
||
|
leftButton.textContent = "◀";
|
||
|
leftButton.style.cssText = "left: 0vh; bottom:10vh;"
|
||
|
leftButton.addEventListener("touchstart", function(e){keyEvent("a", "keydown")}, false);
|
||
|
leftButton.addEventListener("touchend", function(e){keyEvent("a", "keyup")}, false);
|
||
|
leftButton.addEventListener("touchmove", function(e){e.preventDefault()}, false);
|
||
|
document.body.appendChild(leftButton);
|
||
|
var backButton = document.createElement('button');
|
||
|
backButton.id = "hideButton"
|
||
|
backButton.textContent = "▼";
|
||
|
backButton.style.cssText = "left:10vh;bottom:0vh;"
|
||
|
backButton.addEventListener("touchstart", function(e){keyEvent("s", "keydown")}, false);
|
||
|
backButton.addEventListener("touchend", function(e){keyEvent("s", "keyup")}, false);
|
||
|
backButton.addEventListener("touchmove", function(e){e.preventDefault()}, false);
|
||
|
document.body.appendChild(backButton);
|
||
|
var jumpButton = document.createElement('button');
|
||
|
jumpButton.id = "hideButton"
|
||
|
jumpButton.textContent = "⇧";
|
||
|
jumpButton.style.cssText = "right:10vh;bottom:10vh;"
|
||
|
jumpButton.addEventListener("touchstart", function(e){keyEvent(" ", "keydown")}, false);
|
||
|
jumpButton.addEventListener("touchend", function(e){keyEvent(" ", "keyup")}, false);
|
||
|
jumpButton.addEventListener("touchmove", function(e){e.preventDefault()}, false);
|
||
|
document.body.appendChild(jumpButton);
|
||
|
var crouchButton = document.createElement('button');
|
||
|
crouchButton.id = "hideButton"
|
||
|
crouchButton.textContent = "⇩";
|
||
|
crouchButton.style.cssText = "left:10vh;bottom:10vh;"
|
||
|
crouchButton.addEventListener("touchstart", function(e){shiftKey("keydown")}, false);
|
||
|
crouchButton.addEventListener("touchend", function(e){shiftKey("keyup")}, false);
|
||
|
crouchButton.addEventListener("touchmove", function(e){e.preventDefault()}, false);
|
||
|
document.body.appendChild(crouchButton);
|
||
|
var inventoryButton = document.createElement('button');
|
||
|
inventoryButton.id = "hideInventory"
|
||
|
inventoryButton.textContent = "🎒";
|
||
|
inventoryButton.style.cssText = "right:0vh;bottom:0vh;"
|
||
|
inventoryButton.addEventListener("touchstart", function(e){
|
||
|
window.inInventory = (window.fakelock != null)
|
||
|
keyEvent("e", "keydown");
|
||
|
}, false);
|
||
|
inventoryButton.addEventListener("touchend", function(e){keyEvent("e", "keyup")}, false);
|
||
|
inventoryButton.addEventListener("touchmove", function(e){e.preventDefault()}, false);
|
||
|
document.body.appendChild(inventoryButton);
|
||
|
var chatButton = document.createElement('button');
|
||
|
chatButton.id = "hideButton"
|
||
|
chatButton.textContent = "💬";
|
||
|
chatButton.style.cssText = "right:0vh;top:0vh;"
|
||
|
chatButton.addEventListener("touchstart", function(e){keyEvent("¿", "keydown")}, false);
|
||
|
chatButton.addEventListener("touchend", function(e){keyEvent("¿", "keydown")}, false);
|
||
|
chatButton.addEventListener("touchmove", function(e){e.preventDefault()}, false);
|
||
|
document.body.appendChild(chatButton);
|
||
|
var exitButton = document.createElement('button');
|
||
|
exitButton.id = "exitButton"
|
||
|
exitButton.textContent = "⮐";
|
||
|
exitButton.style.cssText = "left:0vh;top:0vh;"
|
||
|
exitButton.addEventListener("touchstart", function(e){keyEvent("À", "keydown")}, false);
|
||
|
exitButton.addEventListener("touchend", function(e){keyEvent("À", "keyup")}, false);
|
||
|
exitButton.addEventListener("touchmove", function(e){e.preventDefault()}, false);
|
||
|
document.body.appendChild(exitButton);
|
||
|
var placeButton = document.createElement('button');
|
||
|
placeButton.id = "hideButton"
|
||
|
placeButton.textContent = "⊹";
|
||
|
placeButton.style.cssText = "right:0vh;bottom:20vh;"
|
||
|
placeButton.addEventListener("touchstart", function(e){mouseEvent(2, "mousedown", canvas)}, false);
|
||
|
placeButton.addEventListener("touchend", function(e){mouseEvent(2, "mouseup", canvas)}, false);
|
||
|
placeButton.addEventListener("touchmove", function(e){e.preventDefault()}, false);
|
||
|
document.body.appendChild(placeButton);
|
||
|
var breakButton = document.createElement('button');
|
||
|
breakButton.id = "hideButton"
|
||
|
breakButton.textContent = "🗡";
|
||
|
breakButton.style.cssText = "right:10vh;bottom:20vh;"
|
||
|
breakButton.addEventListener("touchstart", function(e){mouseEvent(0, "mousedown", canvas)}, false);
|
||
|
breakButton.addEventListener("touchend", function(e){mouseEvent(0, "mouseup", canvas)}, false);
|
||
|
breakButton.addEventListener("touchmove", function(e){e.preventDefault()}, false);
|
||
|
document.body.appendChild(breakButton);
|
||
|
var scrollUpButton = document.createElement('button');
|
||
|
scrollUpButton.id = "hideButton"
|
||
|
scrollUpButton.textContent = "⇨";
|
||
|
scrollUpButton.style.cssText = "right:0vh;bottom:30vh;"
|
||
|
scrollUpButton.addEventListener("touchstart", function(e){
|
||
|
canvas.dispatchEvent(new WheelEvent("wheel", {"wheelDeltaY": -10}))
|
||
|
}, false);
|
||
|
scrollUpButton.addEventListener("touchmove", function(e){e.preventDefault()}, false);
|
||
|
document.body.appendChild(scrollUpButton);
|
||
|
var scrollDownButton = document.createElement('button');
|
||
|
scrollDownButton.id = "hideButton"
|
||
|
scrollDownButton.textContent = "⇦";
|
||
|
scrollDownButton.style.cssText = "right:10vh;bottom:30vh;"
|
||
|
scrollDownButton.addEventListener("touchstart", function(e){
|
||
|
canvas.dispatchEvent(new WheelEvent("wheel", {"wheelDeltaY": 10}))
|
||
|
}, false);
|
||
|
scrollDownButton.addEventListener("touchmove", function(e){e.preventDefault()}, false);
|
||
|
document.body.appendChild(scrollDownButton);
|
||
|
var throwButton = document.createElement('button');
|
||
|
throwButton.id = "hideInventory"
|
||
|
throwButton.textContent = "Q";
|
||
|
throwButton.style.cssText = "right:0vh;bottom:10vh;"
|
||
|
throwButton.addEventListener("touchstart", function(e){
|
||
|
window.inInventory = (window.fakelock != null)
|
||
|
keyEvent("q", "keydown");
|
||
|
}, false);
|
||
|
throwButton.addEventListener("touchend", function(e){keyEvent("q", "keyup")}, false);
|
||
|
throwButton.addEventListener("touchmove", function(e){e.preventDefault()}, false);
|
||
|
document.body.appendChild(throwButton);
|
||
|
}
|