Ejemplo n.º 1
0
        public U Run <U>() where U : Errand <T>, new()
        {
            var errand = ErrandFactory <T> .Get <U>();

            errand.Attach(this, _entities, Game);
            var type = typeof(U);

            _addQueue.Add(ErrandStoreFactory.Get(errand, type));
            return(errand);
        }
Ejemplo n.º 2
0
 public void Provision <U>(int num) where U : Errand <T>, new()
 {
     for (var i = 0; i < num; i++)
     {
         _provisionStorage.Add(ErrandFactory <T> .Get <U>());
     }
     for (var i = 0; i < num; i++)
     {
         ErrandFactory <T> .Recycle((U)_provisionStorage[i]);
     }
     if (!_errands.ContainsKey(typeof(U)))
     {
         _errands[typeof(U)] = new List <Errand <T> >();
     }
     _provisionStorage.Clear();
 }
Ejemplo n.º 3
0
        public void CommitErrandChanges()
        {
            foreach (var item in _addQueue)
            {
                var errand        = item.Errand;
                var type          = item.Type;
                var doesListExist = _errands.TryGetValue(type, out var errands);
                if (!doesListExist)
                {
                    errands        = new List <Errand <T> >();
                    _errands[type] = errands;
                }
                errands.Add(errand);
                ErrandStoreFactory.Recycle(item);
            }

            foreach (var item in _removeQueue)
            {
                var value         = item.Errand;
                var type          = item.Type;
                var isInitialized = _errands.TryGetValue(type, out var errands);
                if (!isInitialized)
                {
                    throw new Exception($"Trying to remove errand with nonexistant type {type}");
                }

                var isInList = errands.Remove(value);

                if (isInList)
                {
                    ErrandFactory <T> .Recycle(value, type);
                }
                ErrandStoreFactory.Recycle(item);
            }

            _addQueue.Clear();
            _removeQueue.Clear();
        }