r3-legacy/src/r3-d3-api-z-animation.js

223 lines
5.4 KiB
JavaScript

/**
* R3.D3.Animation
* @param apiComponent
* @constructor
*/
R3.D3.Animation = function(
apiComponent
) {
__RUNTIME_COMPONENT__;
this.editor = null;
/**
* This indicates whether an animation is currently in process - for blocking to take effect
* @type {boolean}
*/
this.inProcess = false;
__UPGRADE_TO_RUNTIME__;
};
R3.D3.Animation.prototype = Object.create(R3.Component.prototype);
R3.D3.Animation.prototype.constructor = R3.D3.Animation;
R3.D3.Animation.prototype.createInstance = function() {
this.instance = {
rotation : null,
translation : null,
scale : null
};
try {
if (this.rotationFn) {
this.instance.rotation = new Function(
'data',
this.rotationFn
).bind(this);
}
if (this.translationFn) {
this.instance.translation = new Function(
'data',
this.translationFn
).bind(this);
}
if (this.scaleFn) {
this.instance.scale = new Function(
'data',
this.scaleFn
).bind(this);
}
} catch (error) {
console.error(error);
this.emit(
R3.Event.ANIMATION_COMPILE_FAILED,
{
component : this
}
)
}
__CREATE_INSTANCE__;
};
/**
* Updates the instance with the current state
*/
R3.D3.Animation.prototype.updateInstance = function(property) {
if (property === 'rotationSpeed') {
console.warn('todo: rotationSpeed update');
return;
}
if (property === 'translationSpeed') {
console.warn('todo: translationSpeed update');
return;
}
if (property === 'scaleSpeed') {
console.warn('todo: scaleSpeed update');
return;
}
if (property === 'rotationFn') {
try {
this.instance.rotation = new Function('data', this.rotationFn).bind(this);
this.emit(
R3.Event.ANIMATION_COMPILE_SUCCESS,
{
component : this,
type : R3.D3.API.Animation.ANIMATION_FUNCTION_TYPE_ROTATION
}
)
} catch (error) {
console.error(error);
this.emit(
R3.Event.ANIMATION_COMPILE_FAILED,
{
component : this
}
)
}
return;
}
if (property === 'translationFn') {
try {
this.instance.translation = new Function('data', this.translationFn).bind(this);
this.emit(
R3.Event.ANIMATION_COMPILE_SUCCESS,
{
component : this,
type : R3.D3.API.Animation.ANIMATION_FUNCTION_TYPE_TRANSLATION
}
);
} catch (error) {
console.error(error);
this.emit(
R3.Event.ANIMATION_COMPILE_FAILED,
{
component : this
}
)
}
return;
}
if (property === 'scaleFn') {
try {
this.instance.scale = new Function('data', this.scaleFn).bind(this);
this.emit(
R3.Event.ANIMATION_COMPILE_SUCCESS,
{
component : this,
type : R3.D3.Animation.API.ANIMATION_FUNCTION_TYPE_SCALE
}
)
} catch (error) {
console.error(error);
this.emit(
R3.Event.ANIMATION_COMPILE_FAILED,
{
component : this
}
)
}
return;
}
if (property === 'blocking') {
console.warn('todo: blocking update');
return;
}
if (property === 'applyToMeshWhenDone') {
console.warn('todo: applyToMeshWhenDone update');
return;
}
if (property === 'functionType') {
console.warn('todo: functionType update');
return;
}
__UPDATE_INSTANCE__;
};
R3.D3.Animation.prototype.launchEditor = function(){
var property = null;
if (this.functionType === R3.D3.Animation.ANIMATION_FUNCTION_TYPE_ROTATION) {
this.rotationFn = '//when the animation is complete, return true\nreturn true;';
property = 'rotationFn';
}
if (this.functionType === R3.D3.Animation.ANIMATION_FUNCTION_TYPE_TRANSLATION) {
this.translationFn = '//when the animation is complete, return true\nreturn true;';
property = 'translationFn';
}
if (this.functionType === R3.D3.Animation.ANIMATION_FUNCTION_TYPE_SCALE) {
this.scaleFn = '//when the animation is complete, return true\nreturn true;';
property = 'scaleFn';
}
if (property) {
this.editor = this.coder.instance(
document.body,
{
value : this[property],
mode : 'javascript',
lineNumbers : true,
scrollbarStyle : 'overlay'
}
);
this.editor.on('change', function(){
this[property] = this.editor.getValue();
this.updateInstance();
}.bind(this))
} else {
console.warn('invalid function type selected');
}
};
R3.D3.Animation.prototype.closeEditor = function(){
var dom = this.editor.getWrapperElement();
dom.parentElement.removeChild(dom);
};