@osbjs/osbjs
Version:
a minimalist osu! storyboarding framework
30 lines (26 loc) • 1.1 kB
JavaScript
const { Component, Layer, parseOsuTimestamp, Sprite } = require('@osbjs/osbjs')
const { imageSize } = require('image-size')
const { join } = require('path')
class MyBackground extends Component {
name = 'MyBackground'
constructor(osbPath, folderPath, startTime, endTime, opacity = 0.8, fadeDuration = 500) {
super()
this.osbPath = osbPath
this.folderPath = folderPath
this.startTime = typeof startTime == 'string' ? parseOsuTimestamp(startTime) : Math.round(startTime)
this.endTime = typeof endTime == 'string' ? parseOsuTimestamp(endTime) : Math.round(endTime)
this.opacity = opacity
this.fadeDuration = fadeDuration
}
generate() {
const { height } = imageSize(join(this.folderPath + this.osbPath))
if (height) {
let bg = new Sprite(this.osbPath, Layer.Background)
bg.ScaleAtTime(this.startTime, 480 / height)
bg.Fade(this.startTime - this.fadeDuration, this.startTime, 0, this.opacity)
bg.Fade(this.endTime, this.endTime + this.fadeDuration, 0, this.opacity)
this.registerComponents(bg)
}
}
}
module.exports = { MyBackground }