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

99 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-12-15 14:53:39 +01:00
/**
* Follow Component
* @param id
* @param name
* @param currentComponent GameLib.Component
* @param targetComponent GameLib.Component
* @param targetPositionOffset GameLib.API.Vector3
2016-12-15 14:53:39 +01:00
* @param minDistance
* @param moveSpeed
2017-01-02 17:05:40 +01:00
* @param parentEntity
2016-12-15 14:53:39 +01:00
* @constructor
*/
GameLib.D3.API.Follow = function (
id,
name,
currentComponent,
targetComponent,
targetPositionOffset,
2016-12-15 14:53:39 +01:00
minDistance,
2017-01-02 17:05:40 +01:00
moveSpeed,
parentEntity
2016-12-15 14:53:39 +01:00
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_FOLLOW,
{
'currentComponent': GameLib.Component,
'targetComponent': GameLib.Component
2017-01-02 17:05:40 +01:00
},
parentEntity
);
2016-12-15 14:53:39 +01:00
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;
2016-12-15 14:53:39 +01:00
}
this.targetComponent = targetComponent;
2016-12-15 14:53:39 +01:00
if(GameLib.Utils.UndefinedOrNull(targetPositionOffset)) {
targetPositionOffset = new GameLib.API.Vector3(0, 0, 0);
2016-12-15 14:53:39 +01:00
}
this.targetPositionOffset = targetPositionOffset;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(minDistance)) {
minDistance = 2;
2016-12-15 14:53:39 +01:00
}
this.minDistance = minDistance;
if (GameLib.Utils.UndefinedOrNull(moveSpeed)) {
moveSpeed = 12.5;
}
this.moveSpeed = moveSpeed;
this.target = new GameLib.API.Vector3(0, 0, 0);
2016-12-15 14:53:39 +01:00
this.targetToParent = new GameLib.API.Vector3(0, 0, 0);
2016-12-15 14:53:39 +01:00
this.rotatedTargetOffset = new GameLib.API.Vector3(0, 0, 0);
2016-12-15 14:53:39 +01:00
this.rotated = new GameLib.API.Quaternion();
2016-12-15 14:53:39 +01:00
};
GameLib.D3.API.Follow.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Follow.prototype.constructor = GameLib.D3.API.Follow;
2017-01-06 16:53:53 +01:00
/**
* Object to GameLib.D3.API.Follow
* @param objectComponent
* @returns {GameLib.D3.API.Follow}
* @constructor
*/
2017-06-14 14:21:57 +02:00
GameLib.D3.API.Follow.FromObject = function(objectComponent) {
2017-01-06 16:53:53 +01:00
return new GameLib.D3.API.Follow(
objectComponent.id,
objectComponent.name,
objectComponent.currentComponent,
objectComponent.targetComponent,
2017-06-14 14:21:57 +02:00
GameLib.API.Vector3.FromObject(objectComponent.targetPositionOffset),
2017-01-06 16:53:53 +01:00
objectComponent.minDistance,
objectComponent.moveSpeed,
objectComponent.parentEntity
);
};