Exemple #1
0
        public void Execute(IConsoleShell shell, string argStr, string[] args)
        {
            var id               = args.Length == 0 ? null : string.Join(" ", args);
            var entityManager    = IoCManager.Resolve <IEntityManager>();
            var prototypeManager = IoCManager.Resolve <IPrototypeManager>();

            IEntityQuery query;

            if (id == null)
            {
                query = new AllEntityQuery();
            }
            else
            {
                if (!prototypeManager.TryIndex(id, out EntityPrototype prototype))
                {
                    shell.WriteLine($"No entity prototype found with id {id}.");
                    return;
                }

                query = new PredicateEntityQuery(e => e.Prototype == prototype);
            }

            var entities   = 0;
            var components = 0;

            foreach (var entity in entityManager.GetEntities(query))
            {
                if (entity.Prototype == null)
                {
                    continue;
                }

                var modified = false;

                foreach (var component in entity.GetAllComponents())
                {
                    if (!entity.Prototype.Components.ContainsKey(component.Name))
                    {
                        entityManager.ComponentManager.RemoveComponent(entity.Uid, component);
                        components++;

                        modified = true;
                    }
                }

                if (modified)
                {
                    entities++;
                }
            }

            shell.WriteLine($"Removed {components} components from {entities} entities{(id == null ? "." : $" with id {id}")}");
Exemple #2
0
        public void Execute(IConsoleShell shell, string argStr, string[] args)
        {
            if (args.Length != 1)
            {
                shell.WriteLine(Help);
                return;
            }

            var id            = args[0].ToLower();
            var entityManager = IoCManager.Resolve <IEntityManager>();
            var query         = new PredicateEntityQuery(e => e.Prototype?.ID.ToLower() == id);
            var entities      = entityManager.GetEntities(query);
            var i             = 0;

            foreach (var entity in entities)
            {
                entity.Delete();
                i++;
            }

            shell.WriteLine($"Deleted all entities with id {id}. Occurrences: {i}");
        }