actuate
Version:
Actuate is a flexible, fast "tween" library for animations
159 lines (141 loc) • 5.86 kB
JavaScript
// Class: motion.actuators.MotionPathActuator
var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this
$global.Object.defineProperty(exports, "__esModule", {value: true});
var __map_reserved = {};
// Imports
var $hxClasses = require("./../../hxClasses_stub").default;
var $import = require("./../../import_stub").default;
var $extend = require("./../../extend_stub").default;
function motion_actuators_SimpleActuator() {return require("./../../motion/actuators/SimpleActuator");}
function Reflect() {return require("./../../Reflect");}
function js_Boot() {return require("./../../js/Boot");}
function motion_IComponentPath() {return require("./../../motion/IComponentPath");}
function motion_actuators_PropertyPathDetails() {return require("./../../motion/actuators/PropertyPathDetails");}
// Constructor
var MotionPathActuator = function(target,duration,properties) {
(motion_actuators_SimpleActuator().default).call(this,target,duration,properties);
}
// Meta
MotionPathActuator.__name__ = ["motion","actuators","MotionPathActuator"];
MotionPathActuator.__isInterface__ = false;
MotionPathActuator.__super__ = (motion_actuators_SimpleActuator().default);
MotionPathActuator.prototype = $extend((motion_actuators_SimpleActuator().default).prototype, {
apply: function() {
var _g = 0;
var _g1 = (Reflect().default).fields(this.properties);
while(_g < _g1.length) {
var propertyName = _g1[_g];
++_g;
if((Reflect().default).hasField(this.target,propertyName)) {
(Reflect().default).setField(this.target,propertyName,((js_Boot().default).__cast((Reflect().default).field(this.properties,propertyName) , (motion_IComponentPath().default))).get_end());
} else {
(Reflect().default).setProperty(this.target,propertyName,((js_Boot().default).__cast((Reflect().default).field(this.properties,propertyName) , (motion_IComponentPath().default))).get_end());
}
}
},
initialize: function() {
var details;
var path;
var _g = 0;
var _g1 = (Reflect().default).fields(this.properties);
while(_g < _g1.length) {
var propertyName = _g1[_g];
++_g;
path = (js_Boot().default).__cast((Reflect().default).field(this.properties,propertyName) , (motion_IComponentPath().default));
if(path != null) {
var isField = true;
if((Reflect().default).hasField(this.target,propertyName)) {
path.set_start((Reflect().default).field(this.target,propertyName));
} else {
isField = false;
path.set_start((Reflect().default).getProperty(this.target,propertyName));
}
details = new (motion_actuators_PropertyPathDetails().default)(this.target,propertyName,path,isField);
this.propertyDetails.push(details);
}
}
this.detailsLength = this.propertyDetails.length;
this.initialized = true;
},
update: function(currentTime) {
if(!this.paused) {
var details;
var easing;
var tweenPosition = (currentTime - this.timeOffset) / this.duration;
if(tweenPosition > 1) {
tweenPosition = 1;
}
if(!this.initialized) {
this.initialize();
}
if(!this.special) {
easing = this._ease.calculate(tweenPosition);
var _g = 0;
var _g1 = this.propertyDetails;
while(_g < _g1.length) {
var details1 = _g1[_g];
++_g;
if(details1.isField) {
(Reflect().default).setField(details1.target,details1.propertyName,((js_Boot().default).__cast(details1 , (motion_actuators_PropertyPathDetails().default))).path.calculate(easing));
} else {
(Reflect().default).setProperty(details1.target,details1.propertyName,((js_Boot().default).__cast(details1 , (motion_actuators_PropertyPathDetails().default))).path.calculate(easing));
}
}
} else {
if(!this._reverse) {
easing = this._ease.calculate(tweenPosition);
} else {
easing = this._ease.calculate(1 - tweenPosition);
}
var endValue;
var _g2 = 0;
var _g11 = this.propertyDetails;
while(_g2 < _g11.length) {
var details2 = _g11[_g2];
++_g2;
if(!this._snapping) {
if(details2.isField) {
(Reflect().default).setField(details2.target,details2.propertyName,((js_Boot().default).__cast(details2 , (motion_actuators_PropertyPathDetails().default))).path.calculate(easing));
} else {
(Reflect().default).setProperty(details2.target,details2.propertyName,((js_Boot().default).__cast(details2 , (motion_actuators_PropertyPathDetails().default))).path.calculate(easing));
}
} else if(details2.isField) {
(Reflect().default).setField(details2.target,details2.propertyName,Math.round(((js_Boot().default).__cast(details2 , (motion_actuators_PropertyPathDetails().default))).path.calculate(easing)));
} else {
(Reflect().default).setProperty(details2.target,details2.propertyName,Math.round(((js_Boot().default).__cast(details2 , (motion_actuators_PropertyPathDetails().default))).path.calculate(easing)));
}
}
}
if(tweenPosition == 1) {
if(this._repeat == 0) {
this.active = false;
if(this.toggleVisible && this.getField(this.target,"alpha") == 0) {
this.setField(this.target,"visible",false);
}
this.complete(true);
return;
} else {
if(this._onRepeat != null) {
this.callMethod(this._onRepeat,this._onRepeatParams);
}
if(this._reflect) {
this._reverse = !this._reverse;
}
this.startTime = currentTime;
this.timeOffset = this.startTime + this._delay;
if(this._repeat > 0) {
this._repeat--;
}
}
}
if(this.sendChange) {
this.change();
}
}
}
});
MotionPathActuator.prototype.__class__ = MotionPathActuator.prototype.constructor = $hxClasses["motion.actuators.MotionPathActuator"] = MotionPathActuator;
// Init
// Statics
// Export
exports.default = MotionPathActuator;