r3-legacy/bak/game-lib-d3-api-follow.js

99 lines
2.5 KiB
JavaScript

/**
* Follow Component
* @param id
* @param name
* @param currentComponent GameLib.Component
* @param targetComponent GameLib.Component
* @param targetPositionOffset GameLib.API.Vector3
* @param minDistance
* @param moveSpeed
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Follow = function (
id,
name,
currentComponent,
targetComponent,
targetPositionOffset,
minDistance,
moveSpeed,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_FOLLOW,
{
'currentComponent': GameLib.Component,
'targetComponent': GameLib.Component
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = this.constructor.name;
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(currentComponent)) {
currentComponent = null;
}
this.currentComponent = currentComponent;
if (GameLib.Utils.UndefinedOrNull(targetComponent)) {
targetComponent = null;
}
this.targetComponent = targetComponent;
if(GameLib.Utils.UndefinedOrNull(targetPositionOffset)) {
targetPositionOffset = new GameLib.API.Vector3(0, 0, 0);
}
this.targetPositionOffset = targetPositionOffset;
if (GameLib.Utils.UndefinedOrNull(minDistance)) {
minDistance = 2;
}
this.minDistance = minDistance;
if (GameLib.Utils.UndefinedOrNull(moveSpeed)) {
moveSpeed = 12.5;
}
this.moveSpeed = moveSpeed;
this.target = new GameLib.API.Vector3(0, 0, 0);
this.targetToParent = new GameLib.API.Vector3(0, 0, 0);
this.rotatedTargetOffset = new GameLib.API.Vector3(0, 0, 0);
this.rotated = new GameLib.API.Quaternion();
};
GameLib.D3.API.Follow.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Follow.prototype.constructor = GameLib.D3.API.Follow;
/**
* Object to GameLib.D3.API.Follow
* @param objectComponent
* @returns {GameLib.D3.API.Follow}
* @constructor
*/
GameLib.D3.API.Follow.FromObject = function(objectComponent) {
return new GameLib.D3.API.Follow(
objectComponent.id,
objectComponent.name,
objectComponent.currentComponent,
objectComponent.targetComponent,
GameLib.API.Vector3.FromObject(objectComponent.targetPositionOffset),
objectComponent.minDistance,
objectComponent.moveSpeed,
objectComponent.parentEntity
);
};