@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
203 lines (202 loc) • 5.39 kB
JavaScript
"use strict";
import { TimelineBuilderProperty } from "./TimelineBuilderProperty";
import { Operation } from "./vars/AnimBuilderTypes";
import { gsapTimeline } from "../thirdParty/gsap/gsapFactory";
export class TimelineBuilder {
constructor() {
this._timelineBuilders = [];
this._duration = 1;
this._operation = Operation.SET;
this._delay = 0;
this._stoppable = true;
this._debug = false;
}
setDebug(debug) {
this._debug = debug;
}
_printDebug(message) {
if (!this._debug) {
return;
}
console.log(message);
}
addTimelineBuilder(timeline_builder) {
this._timelineBuilders.push(timeline_builder);
timeline_builder.setParent(this);
}
timelineBuilders() {
return this._timelineBuilders;
}
setParent(parent) {
this._parent = parent;
}
parent() {
return this._parent;
}
setTarget(target) {
this._target = target;
for (const builder of this._timelineBuilders) {
builder.setTarget(target);
}
}
target() {
return this._target;
}
setDuration(duration) {
if (duration >= 0) {
this._duration = duration;
for (const builder of this._timelineBuilders) {
builder.setDuration(duration);
}
}
}
duration() {
return this._duration;
}
setKeyframes(keyframes) {
this._keyframes = keyframes;
}
keyframes() {
return this._keyframes;
}
setEasing(easing) {
this._easing = easing;
for (const builder of this._timelineBuilders) {
builder.setEasing(easing);
}
}
easing() {
return this._easing;
}
setOperation(operation) {
this._operation = operation;
for (const builder of this._timelineBuilders) {
builder.setOperation(operation);
}
}
operation() {
return this._operation;
}
setRepeatParams(repeat_params) {
this._repeatParams = repeat_params;
for (const builder of this._timelineBuilders) {
builder.setRepeatParams(repeat_params);
}
}
repeatParams() {
return this._repeatParams;
}
setDelay(delay) {
this._delay = delay;
for (const builder of this._timelineBuilders) {
builder.setDelay(delay);
}
}
delay() {
return this._delay;
}
setPosition(position) {
this._position = position;
}
position() {
return this._position;
}
setStoppable(state) {
this._stoppable = state;
}
stoppable() {
return this._stoppable;
}
setUpdateCallback(update_callback) {
this._updateCallback = update_callback;
}
updateCallback() {
return this._updateCallback;
}
// merge(timeline_builder?: TimelineBuilder) {
// if (!timeline_builder) {
// return;
// }
// }
clone() {
const newTimelineBuilder = new TimelineBuilder();
newTimelineBuilder.setDuration(this._duration);
newTimelineBuilder.setOperation(this._operation);
newTimelineBuilder.setDelay(this._delay);
if (this._target) {
newTimelineBuilder.setTarget(this._target.clone());
}
if (this._easing) {
newTimelineBuilder.setEasing(this._easing);
}
if (this._keyframes) {
newTimelineBuilder.setKeyframes(this._keyframes);
}
if (this._delay) {
newTimelineBuilder.setDelay(this._delay);
}
if (this._updateCallback) {
newTimelineBuilder.setUpdateCallback(this._updateCallback.clone());
}
if (this._repeatParams) {
newTimelineBuilder.setRepeatParams({
count: this._repeatParams.count,
delay: this._repeatParams.delay,
yoyo: this._repeatParams.yoyo
});
}
if (this._property) {
const name = this._property.name();
if (name) {
newTimelineBuilder.setPropertyName(name);
}
const targetValue = this._property.targetValue();
if (targetValue != null) {
newTimelineBuilder.setPropertyValue(targetValue);
}
}
if (this._position) {
newTimelineBuilder.setPosition(this._position.clone());
}
newTimelineBuilder.setStoppable(this._stoppable);
for (const childTimelineBuilder of this._timelineBuilders) {
const newChildTimelineBuilder = childTimelineBuilder.clone();
newTimelineBuilder.addTimelineBuilder(newChildTimelineBuilder);
}
return newTimelineBuilder;
}
setPropertyName(name) {
this.property().setName(name);
}
property() {
return this._property = this._property || new TimelineBuilderProperty();
}
propertyName() {
return this.property().name();
}
setPropertyValue(value) {
this.property().setTargetValue(value);
}
propertyValue() {
var _a;
return (_a = this._property) == null ? void 0 : _a.targetValue();
}
populate(timeline, options) {
var _a;
this._printDebug(["populate", this, timeline, this._timelineBuilders]);
for (const timelineBuilder of this._timelineBuilders) {
const subTimeline = gsapTimeline();
if (!subTimeline) {
continue;
}
timelineBuilder.setDebug(this._debug);
timelineBuilder.populate(subTimeline, options);
const position_param = ((_a = timelineBuilder.position()) == null ? void 0 : _a.toParameter()) || void 0;
timeline.add(subTimeline, position_param);
}
if (this._property && this._target) {
this._property.setDebug(this._debug);
this._property.addToTimeline({ timelineBuilder: this, timeline, target: this._target, ...options });
}
}
}