taiko-web/public/src/js/canvastest.js
KatieFrogs 0655b79293 Bug fixes
- Change song select mouse wheel song scrolling to be instant
- Clicking on don chan in account settings toggles the animation
- If the music is too long for the chart, the results screen is shown earlier
- Fix weird BPM values freezing the browser (zero, negative, and very large)
- Add a warning to the page when JavaScript is disabled in the browser
- Fix Chrome auto dark mode by forcing light mode on the page
- Add a meta keywords tag to the page
- Fix plugin names getting cut off in the menu
- Delay the function editing of the EditFunction class in plugins to the start() function instead of load()
  - When stopping one of the plugins, all the plugins have to be stopped in reverse order and started again so that patched code of a stopped plugin does not linger around
- Fix importing plugins that have a SyntaxError
- Fix plugins getting the same internal name when added without one, causing them to not appear in the plugin settings
- Support editing args in EditFunction for plugins
- Prevent multiple websockets from being opened
- Fix page freezing after selecting Random song with no songs
- Fix the back button being repeated twice when there are no songs
- Fix /admin/users not accepting case insensitive usernames
- Pressing enter on the Delete Account field does the expected action instead of refreshing the page
- Better error message when custom folder access is denied
- Fix being able to start netplay in custom songs after refreshing the page (#383)
- Fix an error when importing songs from previous session and clicking on the white spot where you normally start multiplayer session
- Fix canvas elements becoming smaller than 1x1 resolution and crashing the game (#390)
- Fix song frame shadow cache on song select not being cleared when resizing the browser window, causing it to become blurry
- Fix a pause-restart error when you hit both confirm keys on the restart button
2022-02-17 23:50:07 +03:00

152 lines
3.7 KiB
JavaScript

class CanvasTest{
constructor(...args){
this.init(...args)
}
init(){
this.canvas = document.createElement("canvas")
var pixelRatio = window.devicePixelRatio || 1
var width = innerWidth * pixelRatio
var height = innerHeight * pixelRatio
this.canvas.width = Math.max(1, width)
this.canvas.height = Math.max(1, height)
this.ctx = this.canvas.getContext("2d")
this.ctx.scale(pixelRatio, pixelRatio)
this.ratio = pixelRatio
this.draw = new CanvasDraw()
this.font = "serif"
this.songAsset = {
marginLeft: 18,
marginTop: 90,
width: 82,
height: 452,
border: 6,
innerBorder: 8
}
}
blurPerformance(){
return new Promise(resolve => {
requestAnimationFrame(() => {
var ctx = this.ctx
ctx.save()
var lastIteration = this.blurIteration()
var frameTime = []
for(var i = 0; i < 10; i++){
lastIteration = lastIteration.then(ms => {
frameTime.push(ms)
return this.blurIteration()
})
}
lastIteration.then(() => {
ctx.restore()
resolve(frameTime.reduce((a, b) => a + b) / frameTime.length)
})
})
})
}
blurIteration(){
return new Promise(resolve => {
requestAnimationFrame(() => {
var startTime = Date.now()
var ctx = this.ctx
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height)
for(var x = 0; x < this.canvas.width; x += this.songAsset.width + this.songAsset.marginLeft){
this.draw.songFrame({
ctx: ctx,
x: x,
y: this.songAsset.marginTop,
width: this.songAsset.width,
height: this.songAsset.height,
border: this.songAsset.border,
innerBorder: this.songAsset.innerBorder,
background: "#efb058",
borderStyle: ["#ffe7bd", "#c68229"],
ratio: this.ratio,
innerContent: () => {}
})
}
for(var i = 0; i < 2; i++){
this.draw.layeredText({
ctx: ctx,
text: "I am a text",
fontSize: 48,
fontFamily: this.font,
x: 23 + 300 * i,
y: 15
}, [
{x: -2, y: -2, outline: "#000", letterBorder: 22},
{},
{x: 2, y: 2, shadow: [2, 2, 7]},
{x: 2, y: 2, outline: "#ad1516", letterBorder: 10},
{x: -2, y: -2, outline: "#ff797b"},
{outline: "#f70808"},
{fill: "#fff", shadow: [-1, 1, 3, 1.5]}
])
}
resolve(Date.now() - startTime)
})
})
}
drawAllImages(){
return new Promise(resolve => {
requestAnimationFrame(() => {
var startTime = Date.now()
var ctx = this.ctx
ctx.save()
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height)
for(var name in assets.image){
ctx.drawImage(assets.image[name], 0, 0)
}
var comboCount = 765
var comboX = 100
var comboY = 100
var fontSize = 120
this.ctx.font = "normal " + fontSize + "px TnT, Meiryo, sans-serif"
this.ctx.textAlign = "center"
this.ctx.strokeStyle = "#000"
this.ctx.lineWidth = fontSize / 10
var glyph = this.ctx.measureText("0").width
var comboText = comboCount.toString().split("")
for(var i in comboText){
var textX = comboX + glyph * (i - (comboText.length - 1) / 2)
if(comboCount >= 100){
var grd = this.ctx.createLinearGradient(
textX - glyph * 0.2,
comboY - fontSize * 0.8,
textX + glyph * 0.2,
comboY - fontSize * 0.2
)
grd.addColorStop(0, "#f00")
grd.addColorStop(1, "#fe0")
this.ctx.fillStyle = grd
}else{
this.ctx.fillStyle = "#fff"
}
this.strokeFillText(comboText[i],
textX,
comboY
)
}
ctx.restore()
resolve(Date.now() - startTime)
})
})
}
strokeFillText(text, x, y){
this.ctx.strokeText(text, x, y)
this.ctx.fillText(text, x, y)
}
clean(){
this.draw.clean()
delete this.ctx
delete this.canvas
}
}