/** * Entity API Object (for storing / loading entities to and from API) * @param id * @param name * @param components GameLib.Component[] * @param parentEntity GameLib.Entity * @param parentEntityManager * @constructor */ GameLib.API.Entity = function( id, name, components, parentEntity, parentEntityManager ) { if (GameLib.Utils.UndefinedOrNull(parentEntity)) { parentEntity = null; } this.parentEntity = parentEntity; if (GameLib.Utils.UndefinedOrNull(parentEntityManager)) { parentEntityManager = null; } this.parentEntityManager = parentEntityManager; this.activeComponent = null; GameLib.Component.call( this, GameLib.Component.COMPONENT_ENTITY, { 'components' : [GameLib.Component], 'activeComponent' : GameLib.Component }, parentEntity ); if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } this.id = id; if (GameLib.Utils.UndefinedOrNull(name)) { name = 'Entity (' + this.id + ')'; } this.name = name; if (GameLib.Utils.UndefinedOrNull(components)) { components = []; } this.components = components; }; GameLib.API.Entity.prototype = Object.create(GameLib.Component.prototype); GameLib.API.Entity.prototype.constructor = GameLib.API.Entity; /** * Returns an API entity from an Object entity * @param objectEntity * @constructor */ GameLib.API.Entity.FromObjectEntity = function(objectEntity) { var apiComponents = objectEntity.components.map( function (objectComponent) { return GameLib.API.Component.FromObjectComponent(objectComponent); } ); return new GameLib.API.Entity( objectEntity.id, objectEntity.name, apiComponents, objectEntity.parentEntity, objectEntity.parentEntityManager ) };