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

151 lines
3.8 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-13 08:39:07 +01:00
* @param direction
* @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-13 08:39:07 +01:00
* @param camera
2017-11-16 13:54:51 +01:00
* @param pulse
2017-11-03 13:07:45 +01:00
* @param parentEntity
* @constructor
*/
GameLib.D3.API.ParticleEngine = function(
id,
name,
position,
2017-11-13 08:39:07 +01:00
direction,
enabled,
templateParticle,
2017-11-03 13:07:45 +01:00
particlesPerSecond,
2017-11-05 10:51:46 +01:00
frequency,
elapsed,
2017-11-13 08:39:07 +01:00
camera,
2017-11-16 13:54:51 +01:00
pulse,
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-13 08:39:07 +01:00
if (GameLib.Utils.UndefinedOrNull(direction)) {
direction = new GameLib.API.Vector3(0, 1, 0);
2017-11-05 15:53:23 +01:00
}
2017-11-13 08:39:07 +01:00
this.direction = direction;
2017-11-05 15:53:23 +01:00
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-13 08:39:07 +01:00
if (GameLib.Utils.UndefinedOrNull(camera)) {
camera = null;
}
this.camera = camera;
2017-11-16 13:54:51 +01:00
if (GameLib.Utils.UndefinedOrNull(pulse)) {
pulse = false;
}
this.pulse = pulse;
2017-12-04 13:23:15 +01:00
GameLib.API.Component.call(
this,
GameLib.Component.PARTICLE_ENGINE,
parentEntity
);
2017-11-03 13:07:45 +01:00
};
2018-01-07 12:40:16 +01:00
GameLib.D3.API.ParticleEngine.prototype = Object.create(GameLib.API.Component.prototype);
2017-11-03 13:07:45 +01:00
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) {
2017-11-13 08:39:07 +01:00
apiTemplateParticle = GameLib.D3.API.Particle.FromObject(objectParticleEngine.templateParticle);
} else {
apiTemplateParticle = objectParticleEngine.templateParticle;
}
2017-11-03 13:07:45 +01:00
}
2017-11-16 13:54:51 +01:00
var apiCamera = null;
if (objectParticleEngine.camera) {
if (objectParticleEngine.camera instanceof Object) {
apiCamera = GameLib.D3.API.Camera.FromObject(objectParticleEngine.camera);
} else {
apiCamera = objectParticleEngine.camera;
}
}
2017-11-13 08:39:07 +01:00
var apiPosition = null;
if (objectParticleEngine.position) {
apiPosition = GameLib.API.Vector3.FromObject(objectParticleEngine.position);
}
var apiDirection = null;
if (objectParticleEngine.direction) {
apiDirection = GameLib.API.Vector3.FromObject(objectParticleEngine.direction);
}
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,
2017-11-13 08:39:07 +01:00
apiPosition,
apiDirection,
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-16 13:54:51 +01:00
apiCamera,
objectParticleEngine.pulse,
2017-11-03 13:07:45 +01:00
objectParticleEngine.parentEntity
2017-11-03 13:07:45 +01:00
);
};