Add browser support tests

This commit is contained in:
LoveEevee 2018-11-27 02:05:02 +03:00
parent 5061f0d261
commit 14d98254bb
8 changed files with 208 additions and 13 deletions

View File

@ -28,4 +28,64 @@
font-family: sans-serif; font-family: sans-serif;
font-size: 5vmin; font-size: 5vmin;
color: white; color: white;
} }
#unsupportedBrowser{
position: absolute;
top: 0;
right: 0;
left: 0;
max-height: 100%;
overflow: hidden auto;
padding: 10px;
background: #aef;
font-family: sans-serif;
font-size: 20px;
z-index: 10;
}
#unsupportedBrowser::before{
content: "!";
display: inline-block;
width: 30px;
height: 30px;
margin-right: 10px;
background: #39a;
color: #fff;
text-align: center;
line-height: 30px;
}
#unsupportedBrowser.hidden{
width: 30px;
}
#unsupportedBrowser.hidden *{
display: none !important;
}
#unsupportedBrowser a{
color: #02e;
cursor: pointer;
text-decoration: none;
}
#unsupportedBrowser a:hover{
text-decoration: underline;
}
#unsupportedBrowser ul{
margin: 5px;
}
#unsupportedDetails{
display: none;
margin: 10px 50px 0 50px;
border: 3px solid #39a;
padding: 5px;
user-select: text;
}
#unsupportedHide{
position: absolute;
right: 0;
top: 0;
width: 50px;
height: 50px;
text-align: center;
line-height: 45px;
color: #777;
text-shadow: 1px 1px #fff;
}

View File

@ -0,0 +1,107 @@
function browserSupport(){
var tests = {
"Arrow function": function(){
eval("()=>{}")
return true
},
"AudioContext": function(){
return "AudioContext" in window || "webkitAudioContext" in window
},
"Class": function(){
eval("class a{}")
return true
},
"Array.find": function(){
return "find" in Array.prototype && "findIndex" in Array.prototype
},
"Path2D SVG": function(){
var canvas = document.createElement("canvas")
canvas.width = 1
canvas.height = 1
var ctx = canvas.getContext("2d")
var path = new Path2D("M0 0H1V1H0")
ctx.fill(path)
return ctx.getImageData(0, 0, 1, 1).data[3] !== 0
},
"Promise": function(){
if("Promise" in window && "resolve" in window.Promise && "reject" in window.Promise && "all" in window.Promise && "race" in window.Promise){
var resolve
new window.Promise(function(r){resolve = r})
return typeof resolve === "function"
}
},
"CSS Calc": function(){
var el = document.createElement("a")
el.style.width = "calc(1px)"
return el.style.length !== 0
}
}
var failedTests = []
for(var name in tests){
var result = false
try{
result = tests[name]()
}catch(e){}
if(result === false){
failedTests.push("<li>" + name + "</li>")
}
}
if(failedTests.length !== 0){
var div = document.createElement("div")
div.id = "unsupportedBrowser"
div.innerHTML =
'<div id="unsupportedHide">x</div>\
<span>You are running an unsupported browser (\
<a id="unsupportedLink">Details...</a>)</span>\
<div id="unsupportedDetails">\
The following tests have failed:\
<ul>'
+ failedTests.join("")
+ '</ul>\
Please use a supported browser such as \
<a href="https://www.google.com/chrome/" target="_blank" id="unsupportedChrome">Google Chrome</a>\
</div>'
document.body.appendChild(div)
var link = document.getElementById("unsupportedLink")
var details = document.getElementById("unsupportedDetails")
var hide = document.getElementById("unsupportedHide")
var chrome = document.getElementById("unsupportedChrome")
var divClick = function(event){
if(event.type === "touchstart"){
event.preventDefault()
getSelection().removeAllRanges()
}
div.classList.remove("hidden")
}
div.addEventListener("click", divClick)
div.addEventListener("touchstart", divClick)
var toggleDetails = function(event){
if(event.type === "touchstart"){
event.preventDefault()
}
if(details.style.display === "block"){
details.style.display = ""
}else{
details.style.display = "block"
}
}
link.addEventListener("click", toggleDetails)
link.addEventListener("touchstart", toggleDetails)
var hideClick = function(event){
if(event.type === "touchstart"){
event.preventDefault()
}
event.stopPropagation()
div.classList.add("hidden")
}
hide.addEventListener("click", hideClick)
hide.addEventListener("touchstart", hideClick)
chrome.addEventListener("touchend", function(event){
event.preventDefault()
chrome.click()
})
}
}
browserSupport()

View File

@ -109,6 +109,13 @@ class Loader{
} }
}) })
p2.send("invite", location.hash.slice(1).toLowerCase()) p2.send("invite", location.hash.slice(1).toLowerCase())
setTimeout(() => {
if(p2.socket.readyState !== 1){
p2.hash("")
p2.hashLock = false
resolve()
}
}, 10000)
}).then(() => { }).then(() => {
pageEvents.remove(p2, "message") pageEvents.remove(p2, "message")
})) }))

View File

@ -115,14 +115,21 @@ class loadSong{
canvas.height = h canvas.height = h
var ctx = canvas.getContext("2d") var ctx = canvas.getContext("2d")
ctx.drawImage(img, 0, 0, w, h) ctx.drawImage(img, 0, 0, w, h)
canvas.toBlob(blob => { var saveScaled = url => {
let img2 = document.createElement("img") let img2 = document.createElement("img")
pageEvents.load(img2).then(() => { pageEvents.load(img2).then(() => {
assets.image[filename] = img2 assets.image[filename] = img2
resolve() resolve()
}, reject) }, reject)
img2.src = URL.createObjectURL(blob) img2.src = url
}) }
if("toBlob" in canvas){
canvas.toBlob(blob => {
saveScaled(URL.createObjectURL(blob))
})
}else{
saveScaled(canvas.toDataURL())
}
}else{ }else{
assets.image[filename] = img assets.image[filename] = img
resolve() resolve()

View File

@ -1,4 +1,4 @@
addEventListener("error", err => { addEventListener("error", function(err){
var stack var stack
if("error" in err){ if("error" in err){
stack = err.error.stack stack = err.error.stack
@ -109,3 +109,4 @@ if(location.hash.length === 6){
var loader = new Loader(() => { var loader = new Loader(() => {
new Titlescreen() new Titlescreen()
}) })

View File

@ -407,7 +407,7 @@ class SongSelect{
var mouse = this.mouseOffset(event.offsetX, event.offsetY) var mouse = this.mouseOffset(event.offsetX, event.offsetY)
var moveTo = null var moveTo = null
if(this.state.screen === "song"){ if(this.state.screen === "song"){
if(mouse.x > 641 && mouse.y > 603){ if(mouse.x > 641 && mouse.y > 603 && p2.socket.readyState === 1){
moveTo = "session" moveTo = "session"
}else{ }else{
var moveTo = this.songSelMouse(mouse.x, mouse.y) var moveTo = this.songSelMouse(mouse.x, mouse.y)
@ -591,8 +591,10 @@ class SongSelect{
assets.sounds["diffsel"].stop() assets.sounds["diffsel"].stop()
assets.sounds["don"].play() assets.sounds["don"].play()
localStorage["selectedSong"] = this.selectedSong try{
localStorage["selectedDiff"] = difficulty + this.diffOptions.length localStorage["selectedSong"] = this.selectedSong
localStorage["selectedDiff"] = difficulty + this.diffOptions.length
}catch(e){}
if(difficulty === 3 && this.state.ura){ if(difficulty === 3 && this.state.ura){
difficulty = 4 difficulty = 4
@ -623,7 +625,9 @@ class SongSelect{
if(!p2.session){ if(!p2.session){
assets.sounds["ka"].play() assets.sounds["ka"].play()
this.selectedDiff = 1 this.selectedDiff = 1
this.state.options = this.mod(this.optionsList.length, this.state.options + moveBy) do{
this.state.options = this.mod(this.optionsList.length, this.state.options + moveBy)
}while(p2.socket.readyState !== 1 && this.state.options === 2)
} }
} }
toTitleScreen(){ toTitleScreen(){
@ -650,6 +654,9 @@ class SongSelect{
}, 500) }, 500)
} }
toSession(){ toSession(){
if(p2.socket.readyState !== 1){
return
}
if(p2.session){ if(p2.session){
p2.send("gameend") p2.send("gameend")
}else{ }else{
@ -1470,7 +1477,7 @@ class SongSelect{
ctx.lineTo(x + 4, y + 4) ctx.lineTo(x + 4, y + 4)
ctx.lineTo(x + 4, y + h) ctx.lineTo(x + 4, y + h)
ctx.fill() ctx.fill()
if(screen !== "difficulty"){ if(screen !== "difficulty" && p2.socket.readyState === 1){
var elapsed = (ms - this.state.screenMS) % 3100 var elapsed = (ms - this.state.screenMS) % 3100
var fade = 1 var fade = 1
if(!p2.session && screen === "song"){ if(!p2.session && screen === "song"){

View File

@ -961,6 +961,7 @@
var selectedSong = this.controller.selectedSong var selectedSong = this.controller.selectedSong
var songSkinName = selectedSong.songSkin.name var songSkinName = selectedSong.songSkin.name
var supportsBlend = "mixBlendMode" in songBg.style
if(selectedSong.category in this.categories){ if(selectedSong.category in this.categories){
var catId = this.categories[selectedSong.category].sort var catId = this.categories[selectedSong.category].sort
@ -972,7 +973,7 @@
if(!selectedSong.songSkin.song){ if(!selectedSong.songSkin.song){
var id = selectedSong.songBg var id = selectedSong.songBg
songBg.classList.add("songbg-" + id) songBg.classList.add("songbg-" + id)
this.setLayers("bg_song_" + id, true) this.setLayers("bg_song_" + id + (supportsBlend ? "" : "a"), supportsBlend)
}else if(selectedSong.songSkin.song !== "none"){ }else if(selectedSong.songSkin.song !== "none"){
var notStatic = selectedSong.songSkin.song !== "static" var notStatic = selectedSong.songSkin.song !== "static"
if(notStatic){ if(notStatic){
@ -1456,10 +1457,14 @@
} }
} }
ontouch(event){ ontouch(event){
for(let touch of event.changedTouches){ if(!("changedTouches" in event)){
event.changedTouches = [event]
}
for(var i = 0; i < event.changedTouches.length; i++){
var touch = event.changedTouches[i]
event.preventDefault() event.preventDefault()
if(this.controller.game.paused){ if(this.controller.game.paused){
var mouse = this.mouseOffset(event.touches[0].pageX, event.touches[0].pageY) var mouse = this.mouseOffset(touch.pageX, touch.pageY)
var moveTo = this.pauseMouse(mouse.x, mouse.y) var moveTo = this.pauseMouse(mouse.x, mouse.y)
if(moveTo !== null){ if(moveTo !== null){
this.pauseConfirm(moveTo) this.pauseConfirm(moveTo)

View File

@ -68,6 +68,7 @@
<a href="https://github.com/bui/taiko-web" target="_blank" id="version-link" class="stroke-sub" alt="taiko-web (unknown version)">taiko-web (unknown version)</a> <a href="https://github.com/bui/taiko-web" target="_blank" id="version-link" class="stroke-sub" alt="taiko-web (unknown version)">taiko-web (unknown version)</a>
{% endif %} {% endif %}
</div> </div>
<script src="/src/js/browsersupport.js?{{version.commit_short}}"></script>
<script src="/src/js/main.js?{{version.commit_short}}"></script> <script src="/src/js/main.js?{{version.commit_short}}"></script>
</body> </body>
</html> </html>