Esempio n. 1
0
        public void Delete(MapItem item)
        {
            // delete item
            if (Items.Contains(item))
            {
                Items.Remove(item);
            }

            // remove item from its nodes,
            // and delete them if they're orphaned now
            foreach (var node in item.GetItemNodes())
            {
                if (node.ForwardItem == item)
                {
                    node.ForwardItem = null;
                    node.IsRed       = false;
                }
                if (node.BackwardItem == item)
                {
                    node.BackwardItem = null;
                }
                if (node.IsOrphaned())
                {
                    Delete(node);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Deletes an item. Nodes that are only used by this item
        /// will also be deleted.
        /// </summary>
        /// <param name="item"></param>
        public void Delete(MapItem item)
        {
            // delete item from all sectors
            foreach (var sectorKvp in Sectors)
            {
                sectorKvp.Value.MapItems.Remove(item.Uid);
            }

            // remove item from its nodes,
            // and delete them if they're orphaned now
            foreach (var node in item.GetItemNodes())
            {
                if (node.ForwardItem == item)
                {
                    node.ForwardItem = null;
                    node.IsRed       = false;
                }
                if (node.BackwardItem == item)
                {
                    node.BackwardItem = null;
                }
                if (node.IsOrphaned())
                {
                    Delete(node);
                }
            }

            // delete dependent items
            if (item is Prefab pf)
            {
                foreach (var slaveItem in pf.SlaveItems)
                {
                    if (slaveItem is MapItem mapItem)
                    {
                        Delete(mapItem);
                    }
                    // if Unresolved, just ignore it
                }
            }
        }