japanese-drum-game/public/src/js/main.js

124 lines
2.7 KiB
JavaScript
Raw Normal View History

2018-11-27 07:05:02 +08:00
addEventListener("error", function(err){
2018-10-14 16:04:31 +08:00
var stack
if("error" in err){
stack = err.error.stack
}else{
stack = err.message + "\n at " + err.filename + ":" + err.lineno + ":" + err.colno
}
2018-12-04 06:23:11 +08:00
errorMessage(stack)
})
function errorMessage(stack){
2018-10-14 16:04:31 +08:00
localStorage["lastError"] = JSON.stringify({
2018-12-13 17:18:52 +08:00
timestamp: Date.now(),
2018-10-14 16:04:31 +08:00
stack: stack
})
2018-12-04 06:23:11 +08:00
}
2018-10-14 16:04:31 +08:00
function toggleFullscreen(){
if("requestFullscreen" in root){
if(document.fullscreenElement){
document.exitFullscreen()
}else{
root.requestFullscreen()
}
}else if("webkitRequestFullscreen" in root){
if(document.webkitFullscreenElement){
document.webkitExitFullscreen()
}else{
root.webkitRequestFullscreen()
}
}else if("mozRequestFullScreen" in root){
if(document.mozFullScreenElement){
document.mozCancelFullScreen()
}else{
root.mozRequestFullScreen()
}
}
}
2018-10-14 16:04:31 +08:00
function resizeRoot(){
if(lastHeight !== innerHeight){
lastHeight = innerHeight
root.style.height = innerHeight + "px"
}
}
2018-10-15 02:08:05 +08:00
function debug(){
if(debugObj.state === "open"){
debugObj.debug.clean()
return "Debug closed"
}else if(debugObj.state === "minimised"){
debugObj.debug.restore()
return "Debug restored"
}else{
debugObj.debug = new Debug()
return "Debug opened"
}
}
2018-10-13 02:04:28 +08:00
var root = document.documentElement
if(/iPhone|iPad/.test(navigator.userAgent)){
var fullScreenSupported = false
}else{
var fullScreenSupported = "requestFullscreen" in root || "webkitRequestFullscreen" in root || "mozRequestFullScreen" in root
}
var pageEvents = new PageEvents()
var snd = {}
var p2
2018-10-09 14:59:36 +08:00
var disableBlur = false
2018-10-14 16:04:31 +08:00
var cancelTouch = true
var lastHeight
2018-10-15 02:08:05 +08:00
var debugObj = {
state: "closed",
debug: null
}
var perf = {
blur: 0,
allImg: 0,
load: 0
}
var strings
2019-01-30 00:10:56 +08:00
var vectors
2018-10-14 16:04:31 +08:00
pageEvents.add(root, ["touchstart", "touchmove", "touchend"], event => {
if(event.cancelable && cancelTouch && event.target.tagName !== "SELECT"){
2018-10-14 16:04:31 +08:00
event.preventDefault()
}
})
var versionDiv = document.getElementById("version")
var versionLink = document.getElementById("version-link")
pageEvents.add(versionDiv, ["click", "touchend"], event => {
if(event.target === versionDiv){
versionLink.click()
pageEvents.send("version-link")
}
2018-10-14 16:04:31 +08:00
})
resizeRoot()
setInterval(resizeRoot, 100)
pageEvents.keyAdd(debugObj, "all", "down", event => {
2018-11-11 03:12:29 +08:00
if((event.keyCode === 186 || event.keyCode === 59) && event.ctrlKey && event.shiftKey && !event.altKey){
// Semicolon
if(debugObj.state === "open"){
debugObj.debug.minimise()
}else if(debugObj.state === "minimised"){
debugObj.debug.restore()
}else{
2019-02-21 04:48:21 +08:00
try{
debugObj.debug = new Debug()
}catch(e){}
}
}
if(event.keyCode === 82 && debugObj.debug && debugObj.controller){
2018-11-11 03:12:29 +08:00
// R
debugObj.controller.restartSong()
}
})
2018-10-14 16:04:31 +08:00
var loader = new Loader(songId => {
new Titlescreen(songId)
})
2018-11-27 07:05:02 +08:00