UNPKG

@osbjs/osbjs

Version:

a minimalist osu! storyboarding framework

42 lines (41 loc) 2.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Background = void 0; const Core_1 = require("../Core"); const image_size_1 = require("image-size"); const path_1 = require("path"); class Background extends Core_1.Component { /** * Set background between start and end time. * @param osbPath relative path to image file. * For example, if you have a folder named `sb` inside your beatmap folder and your `image.jpg` is in it, then it should be `sb/image.jpg` * @param folderPath full path to beatmap folder. * @param startTime times in milliseconds/timestamp indicate when the image will be shown. * @param endTime times in milliseconds/timestamp indicate when the image will be shown. * @param options Additional options. */ constructor(osbPath, folderPath, startTime, endTime, options) { super(); this.name = 'Background'; this.options = { opacity: 0.8, fadeDuration: 500, }; this.osbPath = osbPath; this.folderPath = folderPath; this.startTime = typeof startTime == 'string' ? (0, Core_1.parseOsuTimestamp)(startTime) : Math.round(startTime); this.endTime = typeof endTime == 'string' ? (0, Core_1.parseOsuTimestamp)(endTime) : Math.round(endTime); this.options = { ...this.options, ...options }; } generate() { const { height } = (0, image_size_1.imageSize)((0, path_1.join)(this.folderPath, this.osbPath)); if (height) { let bg = new Core_1.Sprite(this.osbPath, Core_1.Layer.Background); bg.ScaleAtTime(this.startTime, 480 / height); bg.Fade(this.startTime - this.options.fadeDuration, this.startTime, 0, this.options.opacity); bg.Fade(this.endTime, this.endTime + this.options.fadeDuration, 0, this.options.opacity); this.registerComponents(bg); } } } exports.Background = Background;