Exemplo n.º 1
0
        /// <summary>
        /// Adds/Creates a component associated with the given entity id.
        /// </summary>
        public C AddComponent <C>(int eid)
            where C : Component, new()
        {
            IComponentCollection collection = null;

            componentCollectionCache.TryGetValue(typeof(C), out collection);

            if (collection == null)
            {
                // Assigns the component collection a filter identifier
                collection = new ComponentCollection <C>(caboodle, _count++);
                componentCollections.Add(collection);
                componentCollectionCache.Add(typeof(C), collection);
            }

            var c = collection.Add(eid) as C;

            ComponentInfo info;

            info.id        = collection.GetId();
            info.component = c;

            OnAdded?.Invoke(eid, info);

            return(c);
        }
 public void SetRenderer(ISourceRenderer renderer)
 {
     if (renderer is ICloudRenderer <SlamLine> typedRenderer)
     {
         OnAdded          += typedRenderer.OnItemsAdded;
         OnUpdated        += typedRenderer.OnItemsUpdated;
         OnRemoved        += typedRenderer.OnItemsRemoved;
         OnVisibleChanged += visible =>
         {
             if (visible)
             {
                 typedRenderer.OnItemsAdded(this, new AddedEventArgs <SlamLine>(this));
             }
             else
             {
                 typedRenderer.OnClear(this);
             }
         };
         if (Count > 0)
         {
             OnAdded?.Invoke(this, new AddedEventArgs <SlamLine>(this));
         }
     }
     else if (renderer is TrackedObjectCloud trackedRenderer)
     {
         OnFollowed   += trackedRenderer.FollowCamera;
         OnUnfollowed += trackedRenderer.StopFollowCamera;
     }
 }
Exemplo n.º 3
0
        public void UpdateBy(IEnumerable <KeyValuePair <TKey, TItem> > source)
        {
            foreach (var kvp in source)
            {
                TItem currentValue;
                if (currentValues.TryGetValue(kvp.Key, out currentValue))
                {
                    if (currentValue.Equals(kvp.Value) == false)
                    {
                        currentValues[kvp.Key] = kvp.Value;
                        OnUpdated.Raise(kvp.Key, kvp.Value);
                    }
                }
                else
                {
                    currentValues[kvp.Key] = kvp.Value;
                    OnAdded.Raise(kvp.Key, kvp.Value);
                }
            }

            var keysRemoved = currentValues.Keys.Except(source.Select(kvp => kvp.Key)).ToArray();

            foreach (var keyRemoved in keysRemoved)
            {
                OnRemoved.Raise(keyRemoved, currentValues[keyRemoved]);
                currentValues.Remove(keyRemoved);
            }
        }
Exemplo n.º 4
0
 public void AddItem(Item item, int count)
 {
     item.Inventory = this;
     item.Count     = count;
     items.Add(item);
     OnAdded?.Invoke(item);
 }
Exemplo n.º 5
0
        public void Produce(CancellationToken ct, params T[] items)
        {
            if (items.Length == 0)
            {
                return;
            }
            int index = 0;
            T   item  = default;

            do
            {
                try {
                    item = items[index];
                    if (_collection.TryAdd(item, 10, ct))
                    {
                        Interlocked.Increment(ref index);
                        OnAdded?.Invoke(this, item);
                    }
                    else
                    {
                        OnAddBlocked?.Invoke(this, item);
                    }
                } catch (OperationCanceledException) {
                    OnAddingCanceled?.Invoke(this, item);
                    break;
                } catch (Exception ex) {
                    OnException?.Invoke(this, ex);
                }
            }while (index < items.Length);
        }
Exemplo n.º 6
0
        protected async void Execute()
        {
            await Commands.HandleAsync(new SetExchangeRate(SourceCurrency, TargetCurrency, ValidFrom, Rate));

            OnAdded?.Invoke();
            Reset();
        }
Exemplo n.º 7
0
        public void LoadAnnObjects(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }
            var jArray = JsonConvert.DeserializeObject(File.ReadAllText(path)) as JArray;

            foreach (var i in jArray)
            {
                AnnObject annObject;
                switch ((AnnObjectType)i["Type"].Value <int>())
                {
                case AnnObjectType.Ruler:
                    annObject = i.ToObject <LineAnnObject>();
                    break;

                case AnnObjectType.Ellipse:
                    annObject = i.ToObject <EllipseAnnObject>();
                    break;

                case AnnObjectType.Rectangle:
                    annObject = i.ToObject <RectangleAnnObject>();
                    break;

                default:
                    throw new NotSupportedException();
                }
                annObjects.Add(annObject);
                OnAdded?.Invoke(annObject);
            }
        }
        public void AddRangeWithHistory(IEnumerable <SlamTrackedObject> items, IEnumerable <IList <SlamLine> > histories)
        {
            var list          = items.ToList();
            var historiesList = histories.ToList();

            lock (_objects)
            {
                foreach (var(i, h) in list.Zip(historiesList, (i, h) => (i, h)))
                {
                    if (_objects.ContainsKey(i.Id))
                    {
                        return;
                    }

                    var container = CreateTrackContainer(i, h);
                    _objects.Add(i.Id, (i, container));
                }

                if (historiesList.Count != 0)
                {
                    _maxId = historiesList.SelectMany(l => l).Max(l => l.Id);
                }
            }

            OnAdded?.Invoke(this, new AddedEventArgs <SlamTrackedObject>(list));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates an entity.
        /// </summary>
        /// <returns></returns>
        public Entity Create()
        {
            var entity = caboodle.Pool.CreateEntity();

            entities.Set(entity.Id, entity);
            OnAdded?.Invoke(entity);
            return(entity);
        }
Exemplo n.º 10
0
 public void Add(TCloudItem item)
 {
     lock (_items)
     {
         _items.Add(item.Id, item);
         OnAdded?.Invoke(this, new AddedEventArgs <TCloudItem>(new[] { item }));
     }
 }
Exemplo n.º 11
0
 /// <summary>
 /// Add the newObject to the list if it is not there from before
 /// </summary>
 /// <param name="newObject"></param>
 public void Add(T newObject)
 {
     if (!objects.Contains(newObject))
     {
         objects.Add(newObject);
         OnAdded?.Invoke(newObject);
     }
 }
        public void Insert(int index, SlamLine item)
        {
            lock (_lines)
            {
                _lines.Insert(index, item);
            }

            OnAdded?.Invoke(this, new AddedEventArgs <SlamLine>(new[] { item }));
        }
Exemplo n.º 13
0
        public override void Add(IItem item)
        {
            Content = item;
            var quantity = item is StackableItem stackableItem ? stackableItem.Quantity : 0;

            Set(item.Definition.Icon.Data, item.Definition.ItemColor());
            m_quantityLabel.text = quantity == 0 ? "" : quantity.ToString();
            OnAdded?.Invoke(item);
        }
        public void Add(SlamLine item)
        {
            lock (_lines)
            {
                _lines.Add(item);
            }

            OnAdded?.Invoke(this, new AddedEventArgs <SlamLine>(new[] { item }));
        }
Exemplo n.º 15
0
        public int Add(int x, int y)
        {
            int z = x + y;

            if (OnAdded != null)
            {
                OnAdded.Invoke(x, y, z);
            }
            return(z);
        }
Exemplo n.º 16
0
        private void PerformAdds()
        {
            foreach (var tr in _Additions.ToList())
            {
                _Contents.Add(tr);
                tr.Completed += Remove;
                OnAdded?.Invoke(this, tr);
            }

            _Additions.Clear();
        }
        private void OnUnlockChange(string identifier, bool value)
        {
            if (value == true)
            {
                IEnumerable <IContentCachedPrefab> newlyUnlocked = _allPrefabs
                                                                   .Where(x => ContainsComponent(x.GetCache().GetComponent <TurretAssembly>(), identifier))
                                                                   .Where(x => IsUnlocked(x.GetCache().GetComponent <TurretAssembly>()));

                OnAdded?.Invoke(newlyUnlocked);
            }
        }
        private static void OnOperationStateCreated(int id)
        {
            if (!s_Initialized)
            {
                return;
            }
            var item = CreateProgressItem(id);

            s_ProgressDirty = true;
            OnAdded?.Invoke(new[] { item });
        }
Exemplo n.º 19
0
 public void Add(T item)
 {
     if (!Items.Contains(item))
     {
         Items.Add(item);
         if (OnAdded != null)
         {
             OnAdded.Invoke(item);
         }
     }
 }
Exemplo n.º 20
0
        public T AddItem <T>(int count) where T : Item, new()
        {
            T item = new T()
            {
                Inventory = this, Count = count
            };

            items.Add(item);
            OnAdded?.Invoke(item);
            return(item);
        }
Exemplo n.º 21
0
        public T AddItem <T>() where T : Item, new()
        {
            T item = new T()
            {
                Inventory = this
            };

            items.Add(item);
            OnAdded?.Invoke(item);
            return(item);
        }
Exemplo n.º 22
0
 public void Add(Entity data)
 {
     if (!entities.Contains(data))
     {
         data.OnDestroyed += Data_OnDestroyed;
         entities.Add(data);
         if (OnAdded != null)
         {
             OnAdded.Invoke(this, new AddedEventArgs <Entity>(data));
         }
     }
 }
Exemplo n.º 23
0
        public override void Add(IItem item)
        {
            var definition = (WeaponDefinition)item.Definition;

            if (definition.WeaponType == m_weaponType)
            {
                Content = item;
                Set(definition.Icon.Data, definition.ItemColor());
                m_typeIcon.enabled = false;
                OnAdded?.Invoke(item);
            }
        }
        public void Add(SlamTrackedObject item)
        {
            lock (_objects)
            {
                if (_objects.ContainsKey(item.Id))
                {
                    return;
                }
                var container = CreateTrackContainer(item);
                _objects[item.Id] = (item, container);
            }

            OnAdded?.Invoke(this, new AddedEventArgs <SlamTrackedObject>(new[] { item }));
        }
Exemplo n.º 25
0
        internal void DoAdded(GuiContainer parent)
        {
            Parent = parent;
            OnAdded?.Invoke();

            if (parent is GuiView)
            {
                DoAddedToView((GuiView)parent);
            }
            else if (parent.View != null)
            {
                DoAddedToView(parent.View);
            }
        }
Exemplo n.º 26
0
        internal void Added(Scene scene)
        {
            if (changeLock)
            {
                throw new Exception("Cannot add a manager in its add/remove callbacks.");
            }

            changeLock = true;

            Scene = scene;
            OnAdded?.Invoke();

            changeLock = false;
        }
Exemplo n.º 27
0
        internal void Add()
        {
            var block = new Block(this, Blocks.Count);

            Blocks.Add(block);
            OnAdded?.Invoke(this, block);
            if (UpdateBitmapSize())
            {
                DrawAll();
            }
            else
            {
                DrawOne(block);
            }
        }
        public void AddRange(IEnumerable <SlamLine> items)
        {
            if (items is null)
            {
                return;
            }
            var list = items.ToList();

            lock (_lines)
            {
                _lines.AddRange(list);
            }

            OnAdded?.Invoke(this, new AddedEventArgs <SlamLine>(list));
        }
        public void AddWithHistory(SlamTrackedObject item, IList <SlamLine> history)
        {
            lock (_objects)
            {
                if (_objects.ContainsKey(item.Id))
                {
                    return;
                }

                var container = CreateTrackContainer(item, history);
                _objects.Add(item.Id, (item, container));
                _maxId = history.Count > 0 ? history.Max(l => l.Id) : 0;
            }

            OnAdded?.Invoke(this, new AddedEventArgs <SlamTrackedObject>(new[] { item }));
        }
Exemplo n.º 30
0
        public void AddRange(IEnumerable <TCloudItem> items)
        {
            if (items is null)
            {
                return;
            }
            lock (_items)
            {
                var list = items.ToList();
                foreach (var ci in list)
                {
                    _items.Add(ci.Id, ci);
                }

                OnAdded?.Invoke(this, new AddedEventArgs <TCloudItem>(list));
            }
        }