Esempio n. 1
0
 /// <summary>
 /// Finds all entities in a registry that have a component of the specified type attached to them.
 /// </summary>
 public static IEnumerable <IEntityRecord> FindAllWithComponent <TComponent>(IEntityRecordCollection registry)
     where TComponent : class, IComponent
 {
     return(registry != null?
            registry.Where(entity =>
                           entity.HasComponent <TComponent>()) :
                null);
 }
Esempio n. 2
0
 /// <summary>
 /// Creates a new entity with the specified name and registers it to the registry.
 /// </summary>
 public EntityRecord(string name, IEntityRecordCollection registry)
     : this()
 {
     Name      = name;
     Registry  = registry;
     _mediator = new Mediator();
     _children = new List <IEntityRecord>();
 }
Esempio n. 3
0
        /// <summary>
        /// Creates and registers an entity in the specified registry.
        /// </summary>
        public static IEntityRecord Create(string name, IEntityRecordCollection registry)
        {
            IEntityRecord record = new EntityRecord(name, registry);

            /// Ensure that the entity gets registered.
            record.Synchronize();

            return(record);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates and registers a new entity in the specified registry. The specified components will also be attached to it.
        /// </summary>
        public static IEntityRecord Create(string name, IEntityRecordCollection registry, params IComponent[] components)
        {
            IEntityRecord record = Create(name, registry);

            foreach (IComponent component in components)
            {
                record.Add(component);
            }

            return(record);
        }
Esempio n. 5
0
        /// <summary>
        /// Attempts to find the entity that matches the specified name in a registry. Returns `null` if none was found.
        /// </summary>
        public static IEntityRecord Find(string name, IEntityRecordCollection registry)
        {
            IEntityRecord record = new EntityRecord(name, registry);

            if (!registry.Contains(record))
            {
                record = null;
            }

            return(record);
        }
Esempio n. 6
0
        /// <summary>
        /// Broadcasts a message to every single component that is currently attached to an entity in the specified registry.
        /// </summary>
        public static void Broadcast <TData>(IEntityRecordCollection registry, string message, TData data)
        {
            if (registry == null)
            {
                return;
            }

            foreach (IEntityRecord record in registry)
            {
                record.Notify(message, data);
            }
        }
Esempio n. 7
0
        public static IEntityRecord CreateChild(this IEntityRecord parent, string name, IEntityRecordCollection registry, params IComponent[] components)
        {
            IEntityRecord record = Entity.Create(name, registry, components);

            record.Parent = record;
            return(record);
        }
Esempio n. 8
0
        public static IEntityRecord CreateChild(this IEntityRecord parent, string name, IEntityRecordCollection registry)
        {
            IEntityRecord record = Entity.Create(name, registry);

            record.Parent = record;
            return(record);
        }
Esempio n. 9
0
 /// <summary>
 /// Creates a new entity with the specified name and registers it to the registry.
 /// </summary>
 public EntityRecord(string name, IEntityRecordCollection registry)
     : this()
 {
     Name     = name;
     Registry = registry;
 }