/** * Entity Runtime * @constructor */ GameLib.Entity = function RuntimeEntity( entityManager, parentObject, apiEntity ) { if (GameLib.Utils.UndefinedOrNull(entityManager)) { throw new Error('You cannot create entities without an entity manager') } this.entityManager = entityManager; if (GameLib.Utils.UndefinedOrNull(parentObject)) { parentObject = null; } this.parentObject = parentObject; GameLib.API.Entity.call( this, apiEntity.id, apiEntity.name, apiEntity.components ); this.instance = this.createInstance(); }; GameLib.Entity.prototype = Object.create(GameLib.API.Entity.prototype); GameLib.Entity.prototype.constructor = GameLib.Entity; /** * Creates an entity instance */ GameLib.Entity.prototype.createInstance = function() { var instance = this.entityManager.createEntity(); return instance; }; /** * Updates an entity instance */ GameLib.Entity.prototype.updateInstance = function() { this.instance = this.createInstance(true); }; /** * Converts a GameLib.Entity to GameLib.API.Entity * @returns {GameLib.API.Entity} */ GameLib.Entity.prototype.toApiEntity = function() { //TODO: refactor / fix // var apiEntity = new GameLib.API.Entity( // this.id, // this.name, // GameLib.Utils.IdArrayOrEmptyArray(this.components), // this.position.toApiVector(), // this.quaternion.toApiQuaternion(), // this.scale.toApiVector(), // GameLib.Utils.IdOrNull(this.parentScene), // GameLib.Utils.IdOrNull(this.mesh) // ); // // return apiEntity; }; /** * * @param graphics GameLib.D3.Graphics * @param objectEntity Object * @constructor */ GameLib.Entity.FromObjectEntity = function(graphics, objectEntity) { //TODO: refactor /fix // var apiEntity = new GameLib.API.Entity( // objectEntity.id, // objectEntity.name, // objectEntity.components, // new GameLib.API.Vector3( // objectEntity.position.x, // objectEntity.position.y, // objectEntity.position.z // ), // new GameLib.API.Quaternion( // objectEntity.quaternion.x, // objectEntity.quaternion.y, // objectEntity.quaternion.z, // objectEntity.quaternion.w, // new GameLib.API.Vector3( // objectEntity.quaternion.axis.x, // objectEntity.quaternion.axis.y, // objectEntity.quaternion.axis.z // ) // ), // new GameLib.API.Vector3( // objectEntity.scale.x, // objectEntity.scale.y, // objectEntity.scale.z // ), // objectEntity.parentScene, // objectEntity.mesh // ); // // return new GameLib.Entity( // graphics, // apiEntity // ); };