Merge pull request #143 from bui/fix-code

Fix code
This commit is contained in:
Bui 2019-03-24 16:25:28 +00:00 committed by GitHub
commit 7411022b14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 15 deletions

View File

@ -15,7 +15,7 @@ body{
margin: 0; margin: 0;
padding: 0; padding: 0;
background-color: #000; background-color: #000;
background-position: top center; background-position: center;
background-size: 30vh; background-size: 30vh;
} }
#screen.pattern-bg{ #screen.pattern-bg{
@ -29,8 +29,8 @@ body{
width:90%; width:90%;
height:10%; height:10%;
border:1px solid black; border:1px solid black;
position: fixed; position: absolute;
top:50%; top:45%;
left:5%; left:5%;
background: rgba(0,0,0,0.65); background: rgba(0,0,0,0.65);
} }

View File

@ -29,33 +29,58 @@ class CanvasCache{
return return
} }
var saved = false var saved = false
var time = Date.now()
if(!img){ if(!img){
var w = config.w var w = config.w
var h = config.h var h = config.h
this.x += this.lastW + 1 this.x += this.lastW + (this.lastW ? 1 : 0)
if(this.x + w > this.w){ if(this.x + w > this.w){
this.x = 0 this.x = 0
this.y += this.lastH + 1 this.y += this.lastH + 1
} }
this.lastW = w if(this.y + h > this.h){
this.lastH = Math.max(this.lastH, h) var clear = true
img = { var oldest = {time: time}
x: this.x, this.map.forEach((oldImg, id) => {
y: this.y, if(oldImg.time < oldest.time){
w: w, oldest.id = id
h: h oldest.time = oldImg.time
}
})
var oldImg = this.map.get(oldest.id)
this.map.delete(oldest.id)
img = {
x: oldImg.x,
y: oldImg.y,
w: w,
h: h
}
}else{
var clear = false
this.lastW = w
this.lastH = Math.max(this.lastH, h)
img = {
x: this.x,
y: this.y,
w: w,
h: h
}
} }
this.map.set(config.id, img)
saved = true saved = true
this.ctx.save() this.ctx.save()
this.ctx.translate(img.x |0, img.y |0) this.ctx.translate(img.x |0, img.y |0)
if(clear){
this.ctx.clearRect(0, 0, (img.w |0) + 1, (img.h |0) + 1)
}
this.ctx.beginPath() this.ctx.beginPath()
this.ctx.rect(0, 0, img.w |0, img.h |0) this.ctx.rect(0, 0, img.w |0, img.h |0)
this.ctx.clip() this.ctx.clip()
this.map.set(config.id, img)
callback(this.ctx) callback(this.ctx)
} }
img.time = time
if(setOnly){ if(setOnly){
this.ctx.restore() this.ctx.restore()
return return
@ -81,6 +106,7 @@ class CanvasCache{
this.ctx.clearRect(0, 0, this.w, this.h) this.ctx.clearRect(0, 0, this.w, this.h)
} }
clean(){ clean(){
this.resize(1, 1, 1)
delete this.map delete this.map
delete this.ctx delete this.ctx
delete this.canvas delete this.canvas

View File

@ -803,9 +803,11 @@ class SongSelect{
this.canvas.style.height = (winH / this.pixelRatio) + "px" this.canvas.style.height = (winH / this.pixelRatio) + "px"
var borders = (this.songAsset.border + this.songAsset.innerBorder) * 2 var borders = (this.songAsset.border + this.songAsset.innerBorder) * 2
var songsLength = Math.ceil(winW / ratio / (this.songAsset.width + this.songAsset.marginLeft)) + 1
this.songTitleCache.resize( this.songTitleCache.resize(
(this.songAsset.width - borders + 1) * Math.ceil(this.songs.length / 3), (this.songAsset.width - borders + 1) * songsLength,
(this.songAsset.height - borders + 1) * 3, this.songAsset.height - borders + 1,
ratio + 0.2 ratio + 0.2
) )
@ -827,7 +829,7 @@ class SongSelect{
categories++ categories++
} }
}) })
this.categoryCache.resize(280, (this.songAsset.marginTop + 1) * categories , ratio + 0.5) this.categoryCache.resize(280, this.songAsset.marginTop + 1 , ratio + 0.5)
this.difficultyCache.resize((44 + 56 + 2) * 5, 135 + 10, ratio + 0.5) this.difficultyCache.resize((44 + 56 + 2) * 5, 135 + 10, ratio + 0.5)
@ -1933,6 +1935,7 @@ class SongSelect{
this.categoryCache.clean() this.categoryCache.clean()
this.difficultyCache.clean() this.difficultyCache.clean()
this.sessionCache.clean() this.sessionCache.clean()
this.currentSongCache.clean()
assets.sounds["bgm_songsel"].stop() assets.sounds["bgm_songsel"].stop()
if(!this.bgmEnabled){ if(!this.bgmEnabled){
snd.musicGain.fadeIn() snd.musicGain.fadeIn()

View File

@ -1874,6 +1874,8 @@
this.assets.clean() this.assets.clean()
this.titleCache.clean() this.titleCache.clean()
this.comboCache.clean() this.comboCache.clean()
this.pauseCache.clean()
this.branchCache.clean()
if(this.multiplayer !== 2){ if(this.multiplayer !== 2){
if(this.touchEnabled){ if(this.touchEnabled){