public override bool AddAdjacent(Side side, Node node)
        {
            //Printer.Info($"ADDING ADJ: {node.Print()} to {Print()}");

            bool added = false;

            if (Adjacents[side] == null)
            {
                added           = true;
                Adjacents[side] = node;
                node.AddAdjacent(Sides.GetInverse(side), this);
                if (node is IOPipeNode)
                {
                    IOPipeNode iOPipeNode = (IOPipeNode)node;
                    iOPipeNode.AddConnectedContainer(this);
                }
            }
            return(added);
        }
        public override bool RemoveAdjacent(Side side, Node node)
        {
            //Printer.Info($"removing ADJ: {node.Print()} from {Print()}");

            bool removed = false;

            if (Adjacents[side] != null)
            {
                removed         = true;
                Adjacents[side] = null;
                node.RemoveAdjacent(Sides.GetInverse(side), this);
                if (node is IOPipeNode)
                {
                    IOPipeNode iOPipeNode = (IOPipeNode)node;
                    iOPipeNode.RemoveConnectedContainer(this);
                }
            }
            return(removed);
        }
Exemple #3
0
        public static void RemoveObject(KeyValuePair <Vector2, StardewValley.Object> obj, GameLocation location)
        {
            DataAccess DataAccess = DataAccess.GetDataAccess();

            if (Globals.UltraDebug)
            {
                Printer.Info("Removing object: " + obj.Key.ToString() + obj.Value.Name);
            }
            List <Node> nodes = DataAccess.LocationNodes[location];
            Node        node  = nodes.Find(n => n.Position.Equals(obj.Key));

            if (node != null)
            {
                nodes.Remove(node);

                if (node is IOPipeNode)
                {
                    IOPipeNode IOPipeNode = (IOPipeNode)node;
                    if (IOPipeNode.ConnectedContainer != null)
                    {
                        IOPipeNode.ConnectedContainer.RemoveIOPipe(IOPipeNode);
                    }
                }
                Printer.Info((obj.Value is CustomObjectItem).ToString());
                if (obj.Value is CustomObjectItem)
                {
                    if (node.ParentNetwork != null)
                    {
                        List <Network> adjNetworks = node.Scan();
                        node.ParentNetwork.RemoveNode(node);
                        if (adjNetworks.Count > 0)
                        {
                            RemakeNetwork(node, location);
                        }
                    }
                }
                node.RemoveAllAdjacents();
            }
        }
        public void ScanMoreIOPipes()
        {
            DataAccess  DataAccess = DataAccess.GetDataAccess();
            int         x          = (int)Position.X;
            int         y          = (int)Position.Y;
            List <Node> nodes      = DataAccess.LocationNodes[Location];
            Vector2     north      = new Vector2(x, y - 1);
            Node        northNode  = nodes.Find(n => n.Position.Equals(north));

            if (northNode != null && northNode is IOPipeNode)
            {
                IOPipeNode northIOPipeNode = (IOPipeNode)northNode;
                northIOPipeNode.AddConnectedContainer(this);
            }
            Vector2 south     = new Vector2(x, y + 1);
            Node    southNode = nodes.Find(n => n.Position.Equals(south));

            if (southNode != null && northNode is IOPipeNode)
            {
                IOPipeNode southIOPipeNode = (IOPipeNode)southNode;
                southIOPipeNode.AddConnectedContainer(this);
            }
            Vector2 west     = new Vector2(x + 1, y);
            Node    westNode = nodes.Find(n => n.Position.Equals(west));

            if (westNode != null && northNode is IOPipeNode)
            {
                IOPipeNode westIOPipeNode = (IOPipeNode)westNode;
                westIOPipeNode.AddConnectedContainer(this);
            }
            Vector2 east     = new Vector2(x - 1, y);
            Node    eastNode = nodes.Find(n => n.Position.Equals(east));

            if (eastNode != null && northNode is IOPipeNode)
            {
                IOPipeNode eastIOPipeNode = (IOPipeNode)eastNode;
                eastIOPipeNode.AddConnectedContainer(this);
            }
        }