2018-09-15 22:34:53 +08:00
|
|
|
class Scoresheet{
|
|
|
|
constructor(controller, score, multiplayer){
|
|
|
|
this.controller = controller
|
|
|
|
this.score = score
|
|
|
|
this.multiplayer = multiplayer
|
2018-09-18 06:37:59 +08:00
|
|
|
loader.changePage("scoresheet")
|
|
|
|
this.run()
|
2015-07-17 16:22:46 +08:00
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
setResults(score, scoreCont){
|
|
|
|
this.positionning(scoreCont)
|
|
|
|
var scoreMark = this.elem("score-mark", scoreCont)
|
|
|
|
var scoreHpBarColour = this.elem("score-hp-bar-colour", scoreCont)
|
|
|
|
|
|
|
|
if(score.fail == 0){
|
|
|
|
var mark = "gold"
|
|
|
|
}else if (score.hp >= 50){
|
|
|
|
var mark = "silver"
|
|
|
|
}
|
|
|
|
scoreHpBarColour.dataset.hp = score.hp
|
|
|
|
var imgW = score.hp * scoreHpBarColour.offsetWidth / 100
|
|
|
|
var imgH = scoreHpBarColour.offsetHeight
|
|
|
|
scoreHpBarColour.getElementsByTagName("img")[0].style.clip = "rect(0, " + imgW + "px, " + imgH + "px, 0)"
|
|
|
|
|
|
|
|
if(mark == "gold"){
|
|
|
|
scoreMark.src = "/assets/img/ranking-X.png"
|
|
|
|
}else if(mark == "silver"){
|
|
|
|
scoreMark.src = "/assets/img/ranking-S.png"
|
|
|
|
}else{
|
|
|
|
scoreMark.parentNode.removeChild(scoreMark)
|
|
|
|
}
|
|
|
|
this.altText(this.elem("score-points", scoreCont), score.points + "点")
|
|
|
|
this.altText(this.elem("nb-great", scoreCont), score.great)
|
|
|
|
this.altText(this.elem("nb-good", scoreCont), score.good)
|
|
|
|
this.altText(this.elem("nb-fail", scoreCont), score.fail)
|
|
|
|
this.altText(this.elem("max-combo", scoreCont), score.maxCombo)
|
2018-09-16 01:27:53 +08:00
|
|
|
this.altText(this.elem("nb-drumroll", scoreCont), score.drumroll)
|
2018-09-15 22:34:53 +08:00
|
|
|
|
2018-09-18 06:37:59 +08:00
|
|
|
pageEvents.add(window, "resize", () => {
|
2018-09-15 22:34:53 +08:00
|
|
|
this.positionning(scoreCont)
|
|
|
|
})
|
2015-07-17 16:22:46 +08:00
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
elem(className, parent){
|
|
|
|
return parent.getElementsByClassName(className)[0]
|
|
|
|
}
|
|
|
|
text(string){
|
|
|
|
return document.createTextNode(string)
|
|
|
|
}
|
|
|
|
altText(element, string){
|
|
|
|
element.appendChild(this.text(string))
|
|
|
|
element.setAttribute("alt", string)
|
|
|
|
}
|
|
|
|
positionning(scoreCont){
|
|
|
|
var scoreHpBarBg = this.elem("score-hp-bar-bg", scoreCont)
|
|
|
|
var scoreHpBarColour = this.elem("score-hp-bar-colour", scoreCont)
|
|
|
|
|
|
|
|
var scoreBarW = scoreCont.offsetWidth * 0.9
|
|
|
|
var bgW = scoreBarW
|
|
|
|
var bgH = 51 / 703 * scoreBarW
|
|
|
|
|
|
|
|
scoreHpBarBg.style.width = bgW + "px"
|
|
|
|
scoreHpBarBg.style.height = bgH + "px"
|
|
|
|
var bgX = scoreHpBarBg.offsetLeft
|
|
|
|
var bgY = scoreHpBarBg.offsetTop
|
|
|
|
|
|
|
|
scoreHpBarColour.style.left = (bgW * 0.008) + "px"
|
|
|
|
scoreHpBarColour.style.top = (bgH * 0.15) + "px"
|
|
|
|
scoreHpBarColour.style.width = (bgW - bgW * 0.08) + "px"
|
|
|
|
scoreHpBarColour.style.height = (bgH - bgH * 0.25) + "px"
|
|
|
|
|
|
|
|
var imgW = scoreHpBarColour.dataset.hp * scoreHpBarColour.offsetWidth / 100
|
|
|
|
var imgH = scoreHpBarColour.offsetHeight
|
|
|
|
scoreHpBarColour.getElementsByTagName("img")[0].style.clip = "rect(0, " + imgW + "px, " + imgH + "px, 0)"
|
|
|
|
}
|
|
|
|
run(){
|
|
|
|
this.scoresheet = document.getElementsByClassName("scoresheet")[0]
|
|
|
|
var scoreCont = this.elem("score-cont", this.scoresheet)
|
|
|
|
var scoreContHtml = scoreCont.innerHTML
|
|
|
|
assets.sounds["results"].play()
|
|
|
|
assets.sounds["bgm_result"].playLoop(0.1, false, 0, 0.847, 17.689)
|
|
|
|
|
|
|
|
this.setResults(this.score, scoreCont)
|
|
|
|
this.altText(this.elem("result-song", this.scoresheet), this.score.song)
|
|
|
|
|
2018-09-27 04:06:14 +08:00
|
|
|
this.songSelect = this.elem("song-select", this.scoresheet)
|
|
|
|
this.replay = this.elem("replay", this.scoresheet)
|
|
|
|
pageEvents.once(this.songSelect, "click").then(() => {
|
2018-09-18 06:37:59 +08:00
|
|
|
this.clean()
|
2018-09-15 22:34:53 +08:00
|
|
|
assets.sounds["don"].play()
|
|
|
|
this.controller.songSelection()
|
|
|
|
})
|
2018-09-18 06:37:59 +08:00
|
|
|
pageEvents.once(this.elem("replay", this.scoresheet), "click").then(() => {
|
|
|
|
this.clean()
|
2018-09-15 22:34:53 +08:00
|
|
|
assets.sounds["don"].play()
|
|
|
|
this.controller.restartSong()
|
|
|
|
})
|
2018-09-27 04:06:14 +08:00
|
|
|
pageEvents.keyAdd(this, "all", "down", this.keyDown.bind(this))
|
|
|
|
this.gamepad = new Gamepad({
|
|
|
|
"13": ["b", "start"],
|
|
|
|
"37": ["l", "r", "lb", "lt", "rb", "rt"]
|
|
|
|
}, (pressed, key) => {
|
|
|
|
if(pressed){
|
|
|
|
this.keyDown(false, key)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-09-15 22:34:53 +08:00
|
|
|
if(this.multiplayer && p2.results){
|
|
|
|
var scoreCont2 = document.createElement("div")
|
|
|
|
scoreCont2.classList.add("score-cont")
|
|
|
|
scoreCont2.innerHTML = scoreContHtml
|
|
|
|
scoreCont.parentNode.appendChild(scoreCont2)
|
|
|
|
this.setResults(p2.results, scoreCont2)
|
|
|
|
}
|
2018-09-11 06:17:13 +08:00
|
|
|
}
|
2018-09-27 04:06:14 +08:00
|
|
|
keyDown(event, code){
|
|
|
|
if(!code){
|
|
|
|
code = event.keyCode
|
|
|
|
}
|
|
|
|
var selected = this.elem("selected", this.scoresheet)
|
|
|
|
if(code == 13){
|
|
|
|
// Enter
|
|
|
|
selected.click()
|
|
|
|
}else if(code == 37 || code == 39){
|
|
|
|
// Left, Right
|
|
|
|
selected.classList.remove("selected")
|
|
|
|
var next = selected.nextElementSibling
|
|
|
|
if(!next){
|
|
|
|
next = selected.previousElementSibling
|
|
|
|
}
|
|
|
|
next.classList.add("selected")
|
|
|
|
}
|
|
|
|
}
|
2018-09-18 06:37:59 +08:00
|
|
|
clean(){
|
|
|
|
assets.sounds["bgm_result"].stop()
|
2018-09-27 04:06:14 +08:00
|
|
|
pageEvents.keyRemove(this, "all")
|
2018-09-18 06:37:59 +08:00
|
|
|
pageEvents.remove(window, "resize")
|
|
|
|
}
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|