/// <summary> /// Creates a new entity and adds it to this scene. /// </summary> /// <returns>The new entity.</returns> /// <param name="blueprint">The EntityBlueprint to create from.</param> public Entity CreateEntity(EntityBlueprint blueprint) { // Create the entity and add it to the scene. Entity newEntity = new Entity(blueprint, this); // Add specific subscriptions to this event. OnDelete.Subscribe(newEntity.Delete); // Then return it. return(newEntity); }
/// <summary> /// Creates a new EntityBlueprint and returns it. It it stored /// at a location in the dictionary that must be unique. /// </summary> /// <returns>A new EntityBlueprint.</returns> /// <param name="name">The unique name for the new blueprint.</param> public EntityBlueprint CreateEntityBlueprint(string name) { if (_blueprints.ContainsKey(name)) { throw Ludum.Error.General("A Entity specification named '" + name + "' already exists."); } EntityBlueprint blueprint = new EntityBlueprint(); _blueprints[name] = blueprint; return(blueprint); }
/// <summary> /// Initializes a new instance of the <see cref="LudumEngine.Entity"/> class from a /// entity blueprint and assigns it to a scene. /// </summary> /// <param name="blueprint">A blueprint to instantiate from.</param> /// <param name="scene">A scene to add the entity to.</param> internal Entity(EntityBlueprint blueprint, Scene scene) { this.Scene = scene; _componentCollection = new ComponentCollection(blueprint.ComponentCollection); foreach (Component component in _componentCollection.GetAllComponents()) { component.Entity = this; component.Reset(); component.Initialize(); } }
/// <summary> /// Creates a new EntityBlueprint that is a copy of a previous one. /// </summary> /// <returns>A new EntityBlueprint.</returns> /// <param name="name">The unique name for the new blueprint.</param> /// <param name="copyfrom">The unique name for the blueprint to copy from.</param> public EntityBlueprint CopyEntityBlueprint(string name, string copyfrom) { if (_blueprints.ContainsKey(name)) { throw Ludum.Error.General("A Entity specification named '" + name + "' already exists."); } EntityBlueprint parent = GetEntityBlueprint(name); EntityBlueprint blueprint = new EntityBlueprint(parent); _blueprints[name] = blueprint; return(blueprint); }
/// <summary> /// Initializes a new instance of the <see cref="LudumEngine.EntityBlueprint"/> class as /// a copy of another blueprint. /// </summary> /// <param name="parent">The blueprint to copy.</param> internal EntityBlueprint(EntityBlueprint parent) { this.ComponentCollection = new ComponentCollection(parent.ComponentCollection); }