/** * Entity API Object (for storing / loading entities to and from API) * @param id * @param name * @param components GameLib.Component[] * @constructor */ GameLib.API.Entity = function( id, name, components ) { 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; }; /** * 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 ) };