Пример #1
0
 internal void DispatchObjectAdded(DisplayObject target)
 {
     if (ObjectAdded != null)
     {
         ObjectAdded.Invoke(target);
     }
 }
Пример #2
0
        /// <summary>
        /// Loads and adds an object to the simulation.
        /// </summary>
        /// <param name="object">Object to add to simulation.</param>
        public void AddObject(SimulationObject @object)
        {
            @object.OnLoad(Editor);

            if (@object is Wall)
            {
                objects.Add(@object);
            }
            else
            {
                objects.Insert(0, @object);
            }

            if (@object is ISelectable selectable && selectable.Selectable)
            {
                SelectObject(selectable);
            }

            if (@object is IPersistent)
            {
                ObjectAdded?.Invoke(this, new EventArgs());
            }

            // Cannon test
            if (@object is Cannon cannon)
            {
                cannon.Fired -= CannonFired;
                cannon.Fired += CannonFired;
            }
        }
Пример #3
0
        /// <summary>Invokes <see cref="ObjectAdded"/> and <see cref="CollectionChanged"/> events.</summary>
        /// <param name="item">Added item.</param>
        protected virtual void InvokeObjectAdded(TObject item)
        {
            Verify.Argument.IsNotNull(item, nameof(item));

            ObjectAdded?.Invoke(this, CreateEventArgs(item));
            CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(
                                          NotifyCollectionChangedAction.Add, item));
        }
Пример #4
0
        private void CreateCustomObject()
        {
            var obj = new CustomModel();

            obj.Config.ID.Generate();
            obj.GenerateNewGeolayout();
            ButtonItem item;

            if (ImportNewModel(obj))
            {
                objBank.Models.Add(obj);
                item = AddItemToList(obj);
                item.RaiseClick();
                ObjectAdded?.Invoke(this, new EventArgs());
            }
        }
Пример #5
0
        /// <summary>
        /// Sets the terrain at the given objects location to the given object, overwriting any terrain already present there.
        /// </summary>
        /// <param name="terrain">Terrain to replace the current terrain with. <paramref name="terrain"/> must have its
        /// <see cref="IGameObject.IsStatic"/> flag set to true and its <see cref="IHasLayer.Layer"/> must be 0, or an exception will be thrown.</param>
        public void SetTerrain(IGameObject terrain)
        {
            if (terrain.Layer != 0)
            {
                throw new ArgumentException($"Terrain for Map must reside on layer 0.", nameof(terrain));
            }

            if (!terrain.IsStatic)
            {
                throw new ArgumentException($"Terrain for Map must be marked static via its {nameof(IGameObject.IsStatic)} flag.", nameof(terrain));
            }

            if (terrain.CurrentMap != null)
            {
                throw new ArgumentException($"Cannot add terrain to more than one {nameof(Map)}.", nameof(terrain));
            }

            if (!this.Contains(terrain.Position))
            {
                throw new ArgumentException($"Terrain added to map must be within the bounds of that map.");
            }

            if (!terrain.IsWalkable)
            {
                foreach (var obj in Entities.GetItems(terrain.Position))
                {
                    if (!obj.IsWalkable)
                    {
                        throw new Exception("Tried to place non-walkable terrain at a location that already has another non-walkable item.");
                    }
                }
            }

            var oldTerrain = _terrain[terrain.Position];

            if (oldTerrain != null)
            {
                oldTerrain.OnMapChanged(null);
                ObjectRemoved?.Invoke(this, new ItemEventArgs <IGameObject>(oldTerrain, oldTerrain.Position));
            }

            _terrain[terrain.Position] = terrain;

            terrain.OnMapChanged(this);
            ObjectAdded?.Invoke(this, new ItemEventArgs <IGameObject>(terrain, terrain.Position));
        }
        public void Insert <T>(T obj) where T : Sprite
        {
            if (obj == null)
            {
                return;
            }

            lock (Generator.Random)
            {
                obj.Serial = Generator.GenerateNumber();
            }

            lock (syncLock)
            {
                if (obj is Aisling)
                {
                    _aislings.Add(obj);
                }

                if (obj is Monster)
                {
                    _monsters.Add(obj);
                }

                if (obj is Mundane)
                {
                    _mundanes.Add(obj);
                }

                if (obj is Money)
                {
                    _money.Add(obj);
                }

                if (obj is Item)
                {
                    _items.Add(obj);
                }

                ObjectAdded?.Invoke(obj);
            }
        }
Пример #7
0
        public static void ChangeMade(int id, Operation operation)
        {
            switch (operation)
            {
            case Operation.ADD:
                ObjectAdded?.Invoke(id);
                break;

            case Operation.REMOVE:
                ObjectDeleted?.Invoke(id);
                break;

            case Operation.VALUE_CHANGE:
                ValueChanged?.Invoke(id);
                break;

            default:
                break;
            }
        }
Пример #8
0
        /// <summary>
        /// Constructor.  Constructs map with the given terrain layer, determining width/height based on the width/height of that terrain layer.
        /// </summary>
        /// <remarks>
        /// Because of the way polymorphism works for custom classes in C#, the <paramref name="terrainLayer"/> parameter MUST be of type
        /// <see cref="ISettableMapView{IGameObject}"/>, rather than <see cref="ISettableMapView{T}"/> where T is a type that derives from or implements
        /// <see cref="IGameObject"/>.  If you need to use a map view storing type T rather than IGameObject, use the
        /// <see cref="CreateMap{T}(ISettableMapView{T}, int, Distance, uint, uint, uint)"/> function to create the map.
        /// </remarks>
        /// <param name="terrainLayer">The <see cref="ISettableMapView{IGameObject}"/> that represents the terrain layer for this map.  After the
        /// map has been created, you should use the <see cref="SetTerrain(IGameObject)"/> function to modify the values in this map view, rather
        /// than setting the values via the map view itself -- if you re-assign the value at a location via the map view, the
        /// <see cref="ObjectAdded"/>/<see cref="ObjectRemoved"/> events are NOT guaranteed to be called, and many invariants of map may not be properly
        /// enforced.</param>
        /// <param name="numberOfEntityLayers">Number of non-terrain layers for the map.</param>
        /// <param name="distanceMeasurement"><see cref="Distance"/> measurement to use for pathing/measuring distance on the map.</param>
        /// <param name="layersBlockingWalkability">Layer mask containing those layers that should be allowed to have items that block walkability.
        /// Defaults to all layers.</param>
        /// <param name="layersBlockingTransparency">Layer mask containing those layers that should be allowed to have items that block FOV.
        /// Defaults to all layers.</param>
        /// <param name="entityLayersSupportingMultipleItems">Layer mask containing those layers that should be allowed to have multiple objects at the same
        /// location on the same layer.  Defaults to no layers.</param>
        public Map(ISettableMapView <IGameObject> terrainLayer, int numberOfEntityLayers, Distance distanceMeasurement, uint layersBlockingWalkability = uint.MaxValue,
                   uint layersBlockingTransparency = uint.MaxValue, uint entityLayersSupportingMultipleItems = 0)
        {
            _terrain = terrainLayer;
            Explored = new ArrayMap <bool>(_terrain.Width, _terrain.Height);

            _entities = new LayeredSpatialMap <IGameObject>(numberOfEntityLayers, 1, entityLayersSupportingMultipleItems);

            LayersBlockingWalkability  = layersBlockingWalkability;
            LayersBlockingTransparency = layersBlockingTransparency;

            _entities.ItemAdded   += (s, e) => ObjectAdded?.Invoke(this, e);
            _entities.ItemRemoved += (s, e) => ObjectRemoved?.Invoke(this, e);
            _entities.ItemMoved   += (s, e) => ObjectMoved?.Invoke(this, e);

            if (layersBlockingTransparency == 1)             // Only terrain so we optimize
            {
                TransparencyView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, c => _terrain[c] == null || _terrain[c].IsTransparent);
            }
            else
            {
                TransparencyView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, FullIsTransparent);
            }

            if (layersBlockingWalkability == 1)             // Similar, only terrain blocks, so optimize
            {
                WalkabilityView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, c => _terrain[c] == null || _terrain[c].IsWalkable);
            }
            else
            {
                WalkabilityView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, FullIsWalkable);
            }

            _fov  = new FOV(TransparencyView);
            AStar = new AStar(WalkabilityView, distanceMeasurement);
        }
Пример #9
0
        public static T CreateNew()
        {
            //Edge case where we have not initialized the factory with a prefab.
            if (prefab == null)
            {
                Debug.LogError("Factory must be instantiated before use. No prefab set.");
            }

            if (managers.Count == 0)
            {
                Debug.LogError($"Factory for {typeof(T).ToString()} must be instantiated before use. No managers added.");
            }

            T script;

            if (cachedObjects.Count > 0)
            {
                script = cachedObjects.Dequeue();
                script.gameObject.SetActive(true);
                script.Reset();
            }
            else
            {
                var newObj = GameObject.Instantiate(prefab);
                script            = FindScript(newObj);
                script.Destroyed += Script_Destroyed;
            }

            foreach (var manager in managers)
            {
                manager.Add(script);
            }

            ObjectAdded?.Invoke(script);
            return(script);
        }
Пример #10
0
 public static void AddObject(GameObject gameObject)
 {
     sceneObjects.Add(gameObject);
     SceneObjectListChanged?.Invoke(gameObject, new EventArgs());
     ObjectAdded?.Invoke(gameObject, new EventArgs());
 }
Пример #11
0
 public void OnObjectAdded(Album a)
 {
     ObjectAdded?.Invoke(this, new ObjectAddedEventArgs <Album>(a));
 }