@osbjs/osbjs
Version:
a minimalist osu! storyboarding framework
71 lines (70 loc) • 4.36 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HitObjectHighlight = void 0;
const Math_1 = require("../Math");
const Core_1 = require("../Core");
const Beatmap_1 = require("../Beatmap");
class HitObjectHighlight extends Core_1.Component {
/**
* Highlight every objects inbetween 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 `hl.png` is in it, then it should be `sb/hl.png`
* @param startTime times in milliseconds/timestamp indicate the start time of the section you want to highlight.
* @param endTime times in milliseconds/timestamp indicate the end time of the section you want to highlight.
* @param beatmap `Beatmap` instance of difficulty you want to use
* @param options Additional options.
*/
constructor(osbPath, startTime, endTime, beatmap, options) {
super();
this.name = 'HitObjectHighlight';
this.options = {
startScale: 1,
endScale: 1.2,
fadeDuration: 200,
beatDivisor: 8,
followSliderPath: true,
};
this.osbPath = osbPath;
this.beatmap = beatmap;
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);
let firstUninherited = this.beatmap.timingPoints
.filter((tPoint) => tPoint.uninherited && tPoint.time <= this.startTime)
.sort((t1, t2) => t2.time - t1.time)[0];
this.startTime = Math.max(firstUninherited.time, this.startTime);
this.options = { ...this.options, ...options };
this.circles = this.beatmap.hitObjects.circles.filter((c) => c.startTime >= this.startTime && c.startTime <= this.endTime);
this.sliders = this.beatmap.hitObjects.sliders.filter((s) => s.startTime >= this.startTime && s.startTime <= this.endTime);
this.beat = this.beatmap.timingPoints
.filter((tPoint) => tPoint.time <= this.startTime && tPoint.uninherited)
.sort((t1, t2) => t2.time - t1.time)[0].beatLength;
}
generate() {
this.circles.forEach((circle) => {
let sprite = new Core_1.Sprite(this.osbPath, Core_1.Layer.Background);
sprite.MoveAtTime(circle.startTime, Core_1.OsbVector2.fromVector2(Math_1.Vector2.add(circle.position, Beatmap_1.PlayfieldToStoryboardOffset)));
sprite.Scale(circle.startTime, circle.startTime + this.options.fadeDuration, this.options.startScale, this.options.endScale, Core_1.Easing.In);
sprite.Fade(circle.startTime, circle.startTime + Math.round(this.beat / 2), 1, 0);
this.registerComponents(sprite);
});
let timestep = Math.round(this.beat / this.options.beatDivisor);
this.sliders.forEach((slider) => {
let sprite = new Core_1.Sprite(this.osbPath, Core_1.Layer.Background);
sprite.Scale(slider.startTime, slider.endTime + this.options.fadeDuration, this.options.startScale, this.options.endScale, Core_1.Easing.In);
sprite.Fade(slider.startTime, Math.round(slider.endTime + this.options.fadeDuration), 1, 0);
if (this.options.followSliderPath) {
let startTime = slider.startTime;
let totalStep = Math.round((slider.endTime - slider.startTime) / timestep);
for (let i = 0; i < totalStep; i++) {
let prevEndTime = startTime + timestep * i;
let endTime = startTime + timestep * (i + 1);
let startPosition = slider.getPositionAtTime(prevEndTime);
let endPosition = slider.getPositionAtTime(endTime);
sprite.Move(prevEndTime, endTime, Core_1.OsbVector2.fromVector2(Math_1.Vector2.add(startPosition, Beatmap_1.PlayfieldToStoryboardOffset)), Core_1.OsbVector2.fromVector2(Math_1.Vector2.add(endPosition, Beatmap_1.PlayfieldToStoryboardOffset)));
}
}
this.registerComponents(sprite);
});
}
}
exports.HitObjectHighlight = HitObjectHighlight;