r3-legacy/src/game-lib-d3-api-particle-en...

123 lines
3.2 KiB
JavaScript
Raw Normal View History

2017-11-03 13:07:45 +01:00
/**
* Raw ParticleEngine API object - should always correspond with the ParticleEngine Schema
* @param id
* @param name
* @param position
2017-11-05 15:53:23 +01:00
* @param rotation
* @param scale
* @param enabled
* @param templateParticle
2017-11-03 13:07:45 +01:00
* @param particlesPerSecond
2017-11-05 15:53:23 +01:00
* @param frequency
* @param elapsed
2017-11-03 13:07:45 +01:00
* @param parentEntity
* @constructor
*/
GameLib.D3.API.ParticleEngine = function(
id,
name,
position,
2017-11-05 15:53:23 +01:00
rotation,
scale,
enabled,
templateParticle,
2017-11-03 13:07:45 +01:00
particlesPerSecond,
2017-11-05 10:51:46 +01:00
frequency,
elapsed,
2017-11-03 13:07:45 +01:00
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'ParticleEngine (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(position)) {
position = new GameLib.API.Vector3(0, 0, 0);
}
this.position = position;
2017-11-03 13:07:45 +01:00
2017-11-05 15:53:23 +01:00
if (GameLib.Utils.UndefinedOrNull(rotation)) {
rotation = new GameLib.API.Vector3(0, 0, 0);
}
this.rotation = rotation;
if (GameLib.Utils.UndefinedOrNull(scale)) {
scale = new GameLib.API.Vector3(1, 1, 1);
}
this.scale = scale;
if (GameLib.Utils.UndefinedOrNull(enabled)) {
enabled = false;
2017-11-03 13:07:45 +01:00
}
this.enabled = enabled;
2017-11-03 13:07:45 +01:00
if (GameLib.Utils.UndefinedOrNull(templateParticle)) {
templateParticle = null;
2017-11-05 10:51:46 +01:00
}
this.templateParticle = templateParticle;
2017-11-03 13:07:45 +01:00
if (GameLib.Utils.UndefinedOrNull(particlesPerSecond)) {
particlesPerSecond = 1;
}
this.particlesPerSecond = particlesPerSecond;
2017-11-05 10:51:46 +01:00
if (GameLib.Utils.UndefinedOrNull(frequency)) {
frequency = Number(1 / Number(this.particlesPerSecond));
2017-11-05 10:51:46 +01:00
}
this.frequency = frequency;
if (GameLib.Utils.UndefinedOrNull(elapsed)) {
elapsed = 0;
}
this.elapsed = elapsed;
2017-11-03 13:07:45 +01:00
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.ParticleEngine.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.ParticleEngine.prototype.constructor = GameLib.D3.API.ParticleEngine;
/**
* Creates an API ParticleEngine from an Object ParticleEngine
* @param objectParticleEngine
* @constructor
*/
GameLib.D3.API.ParticleEngine.FromObject = function(objectParticleEngine) {
var apiTemplateParticle = null;
if (objectParticleEngine.templateParticle) {
if (objectParticleEngine.templateParticle instanceof Object) {
apiTemplateParticle = GameLib.D3.API.Material.FromObject(objectParticleEngine.templateParticle);
} else {
apiTemplateParticle = objectParticleEngine.templateParticle;
}
2017-11-03 13:07:45 +01:00
}
return new GameLib.D3.API.ParticleEngine(
2017-11-03 13:07:45 +01:00
objectParticleEngine.id,
objectParticleEngine.name,
GameLib.API.Vector3.FromObject(objectParticleEngine.position),
2017-11-05 15:53:23 +01:00
GameLib.API.Vector3.FromObject(objectParticleEngine.rotation),
GameLib.API.Vector3.FromObject(objectParticleEngine.scale),
objectParticleEngine.enabled,
apiTemplateParticle,
2017-11-03 13:07:45 +01:00
objectParticleEngine.particlesPerSecond,
2017-11-05 10:51:46 +01:00
objectParticleEngine.frequency,
objectParticleEngine.elapsed,
2017-11-03 13:07:45 +01:00
objectParticleEngine.parentEntity
2017-11-03 13:07:45 +01:00
);
};