motion-and-tween
Version:
Motion and Tween
109 lines (108 loc) • 4.18 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import Motion from "../motion/Motion.js";
var Tween = /** @class */ (function (_super) {
__extends(Tween, _super);
function Tween(params, funcName) {
var _this = _super.call(this, {
obj: params.obj,
propertyToChange: params.propertyToChange,
beginValue: params.beginValue,
actionDuration: params.actionDuration,
}) || this;
_this.isComplete = false;
_this.funcName = "";
_this._finishValue = 0;
if (params.hasOwnProperty("valueChange")) {
_this._valueChange = params.valueChange;
_this._finishValue = _this._beginValue + _this._valueChange;
}
else if (params.hasOwnProperty("finishValue")) {
var fv = params.finishValue;
_this._finishValue = fv;
_this._valueChange = fv - _this._beginValue;
}
_this.isComplete = false;
_this.funcName = funcName;
return _this;
}
Tween.prototype.checkIfFinished = function (t, actionDuration) {
if (t > actionDuration) {
this.isComplete = true;
this.obj[this.propertyToChange] = this._finishValue;
return true;
}
return false;
};
Tween.prototype.update = function (params, tweenAlgo) {
if (params === void 0) { params = null; }
if (tweenAlgo === void 0) { tweenAlgo = null; }
var newParams = this.expandParams(params);
if (tweenAlgo) {
var newValue = tweenAlgo(newParams);
if (!this.checkIfFinished(newParams.nextT, newParams.actionDuration)) {
this.obj[this.propertyToChange] = newValue;
}
}
_super.prototype.update.call(this, params);
return this.obj;
};
// override
Tween.prototype.tweenAlgorithm = function (params) {
var newValue = 0;
return newValue;
};
// TODO: Test/Verify or remove
Tween.prototype.continueTo = function (finish, interimDuration) {
this.setBegin(this.getPosition());
this.setFinish(finish);
if (!interimDuration) {
this.setActionDuration(interimDuration);
}
this.start();
};
// TODO: Test/Verify or remove
Tween.prototype.yoyo = function () {
this.continueTo(this.getBegin(), this.getActionDuration());
};
// TODO: Test/Verify or remove
Tween.prototype.getPosition = function (t) {
if (!t) {
t = this._currentTime;
}
var returnValue = this._pos;
return returnValue;
};
Tween.prototype.setChange = function (change) {
this._valueChange = change;
};
Tween.prototype.getChange = function () {
return this._valueChange;
};
Tween.prototype.setFinish = function (finish) {
this._finishValue = finish;
this._valueChange = this._finishValue - this._beginValue;
};
Tween.prototype.calcFinish = function () {
return this._valueChange + this._beginValue;
};
Tween.prototype.toString = function () {
return "Tween[".concat(_super.prototype.toString.call(this), ", funcName: ").concat(this.funcName, ", _valueChange: ").concat(this._valueChange, ", _finishValue: ").concat(this._finishValue, ", isComplete: ").concat(this.isComplete, "]");
};
return Tween;
}(Motion));
export { Tween };
export default Tween;