UNPKG

@osbjs/components

Version:
30 lines (29 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Background = void 0; const osbjs_1 = require("@osbjs/osbjs"); const image_size_1 = require("image-size"); const path_1 = require("path"); class Background extends osbjs_1.Component { constructor(osbPath, folderPath, startTime, endTime, opacity = 0.8, fadeDuration = 500) { super(); this.name = 'Background'; this.osbPath = osbPath; this.folderPath = folderPath; this.startTime = typeof startTime == 'string' ? (0, osbjs_1.parseOsuTimestamp)(startTime) : Math.round(startTime); this.endTime = typeof endTime == 'string' ? (0, osbjs_1.parseOsuTimestamp)(endTime) : Math.round(endTime); this.opacity = opacity; this.fadeDuration = fadeDuration; } generate() { const { height } = (0, image_size_1.imageSize)((0, path_1.join)(this.folderPath, this.osbPath)); if (height) { let bg = new osbjs_1.Sprite(this.osbPath, osbjs_1.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); } } } exports.Background = Background;