public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1) { //Misc asigment for refresh ToolCall = false; //Printer.Info("TO FALSE"); DataAccess DataAccess = DataAccess.GetDataAccess(); List <Node> nodes = DataAccess.LocationNodes[Game1.currentLocation]; Node node = nodes.Find(n => n.Position.Equals(TileLocation)); if (node != null && node is PPMNode) { PPMNode invis = (PPMNode)node; State = invis.State; float transparency = 1f; if (State.Equals("on")) { ItemTexture = OnTexture; transparency = 0.5f; Rectangle srcRect = new Rectangle(0, 0, 16, 32); spriteBatch.Draw(ItemTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64, y * 64 - 64)), srcRect, Color.White * transparency, 0f, Vector2.Zero, 4f, SpriteEffects.None, ((float)(y * 64 + 32) / 10000f) + 0.001f); } else if (State.Equals("off")) { ItemTexture = OffTexture; transparency = 1f; Rectangle srcRect = new Rectangle(0, 0, 16, 32); spriteBatch.Draw(ItemTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64, y * 64 - 64)), srcRect, Color.White * transparency, 0f, Vector2.Zero, 4f, SpriteEffects.None, ((float)(y * 64 + 32) / 10000f) + 0.001f); } } }
public bool AddNode(Node node) { bool added = false; if (node.ParentNetwork == this && !Nodes.Contains(node)) { added = true; Nodes.Add(node); if (node is OutputPipeNode && !Outputs.Contains(node)) { Outputs.Add((OutputPipeNode)node); } else if (node is InputPipeNode && !Inputs.Contains(node)) { Inputs.Add((InputPipeNode)node); } else if (node is ConnectorPipeNode && !Connectors.Contains(node)) { Connectors.Add((ConnectorPipeNode)node); } else if (node is PPMNode && Invis == null) { Invis = (PPMNode)node; } } else if (node.ParentNetwork != this) { //Printer.Info($"Tried to add {node.Print()} to N{ID}, but they dont match."); } return(added); }
public bool RemoveNode(Node node) { bool removed = false; if (Nodes.Contains(node)) { removed = true; Nodes.Remove(node); if (Outputs.Contains(node)) { Outputs.Remove((OutputPipeNode)node); } else if (Inputs.Contains(node)) { Inputs.Remove((InputPipeNode)node); } else if (Connectors.Contains(node)) { Connectors.Remove((ConnectorPipeNode)node); } else if (node is PPMNode && Invis != null) { Invis = null; if (IsPassable) { Deinvisibilize((PPMNode)node); } } } return(removed); }
public void Deinvisibilize(PPMNode invis) { Invis = invis; IsPassable = false; foreach (Node node in Nodes) { node.Passable = false; } }
public override bool checkForAction(Farmer who, bool justCheckingForActivity = false) { bool result = false; if (justCheckingForActivity) { result = true; } DataAccess DataAccess = DataAccess.GetDataAccess(); if (Game1.didPlayerJustRightClick(ignoreNonMouseHeldInput: true)) { //When right clicking using a tool //it calls checkforaction 2 times, dont know why. if (!ToolCall) { List <Node> nodes = DataAccess.LocationNodes[Game1.currentLocation]; Node node = nodes.Find(n => n.Position.Equals(TileLocation)); if (node != null && node is PPMNode) { PPMNode invis = (PPMNode)node; if (invis.ChangeState()) { Passable = true; } else { Passable = false; } result = false; } } if (who.CurrentTool != null && !ToolCall) { ToolCall = true; result = true; } } return(result); }
public static void AddObject(KeyValuePair <Vector2, StardewValley.Object> obj, GameLocation location) { DataAccess DataAccess = DataAccess.GetDataAccess(); if (Globals.UltraDebug) { Printer.Info("Adding new object: " + obj.Key.ToString() + obj.Value.Name); } List <Node> nodes = DataAccess.LocationNodes[location]; Node newNode = NodeFactory.CreateElement(obj.Key, location, obj.Value); if (Globals.UltraDebug) { Printer.Info("New node created: " + newNode.Print()); } int x = (int)newNode.Position.X; int y = (int)newNode.Position.Y; nodes.Add(newNode); Vector2 north = new Vector2(x, y - 1); Node northNode = nodes.Find(n => n.Position.Equals(north)); if (northNode != null) { newNode.AddAdjacent(SideStruct.GetSides().North, northNode); } Vector2 south = new Vector2(x, y + 1); Node southNode = nodes.Find(n => n.Position.Equals(south)); if (southNode != null) { newNode.AddAdjacent(SideStruct.GetSides().South, southNode); } Vector2 east = new Vector2(x + 1, y); Node eastNode = nodes.Find(n => n.Position.Equals(east)); if (eastNode != null) { newNode.AddAdjacent(SideStruct.GetSides().East, eastNode); } Vector2 west = new Vector2(x - 1, y); Node westNode = nodes.Find(n => n.Position.Equals(west)); if (westNode != null) { newNode.AddAdjacent(SideStruct.GetSides().West, westNode); } if (Globals.UltraDebug) { newNode.Print(); } if (obj.Value is CustomObjectItem) { if (Globals.UltraDebug) { Printer.Info("Assigning network to new node"); } List <Network> uncheckedAdjNetworks = newNode.Scan(); List <Network> adjNetworks = new List <Network>(); foreach (Network network in uncheckedAdjNetworks) { if (network != null) { adjNetworks.Add(network); } } if (Globals.UltraDebug) { Printer.Info("Adjacent network amount: " + adjNetworks.Count.ToString()); } if (adjNetworks.Count == 0) { if (Globals.UltraDebug) { Printer.Info("No adjacent networks, creating new one... "); } Network network = CreateLocationNetwork(location); AddNewElement(newNode, network); } else { List <Network> orderedAdjNetworks = adjNetworks.OrderByDescending(s => s.Nodes.Count).ToList(); if (Globals.UltraDebug) { Printer.Info($"Biggest network = {orderedAdjNetworks[0].ID}"); } foreach (Network network in orderedAdjNetworks) { if (Globals.UltraDebug) { Printer.Info(network.Print()); } } newNode.ParentNetwork = orderedAdjNetworks[0]; AddNewElement(newNode, orderedAdjNetworks[0]); MergeNetworks(orderedAdjNetworks, location); } if (Globals.UltraDebug) { Printer.Info($"Assigned network: [N{newNode.ParentNetwork.ID}]"); } //Another check for missmatching networks north = new Vector2(x, y - 1); northNode = nodes.Find(n => n.Position.Equals(north)); if (northNode != null) { newNode.AddAdjacent(SideStruct.GetSides().North, northNode); } south = new Vector2(x, y + 1); southNode = nodes.Find(n => n.Position.Equals(south)); if (southNode != null) { newNode.AddAdjacent(SideStruct.GetSides().South, southNode); } east = new Vector2(x + 1, y); eastNode = nodes.Find(n => n.Position.Equals(east)); if (eastNode != null) { newNode.AddAdjacent(SideStruct.GetSides().East, eastNode); } west = new Vector2(x - 1, y); westNode = nodes.Find(n => n.Position.Equals(west)); if (westNode != null) { newNode.AddAdjacent(SideStruct.GetSides().West, westNode); } } Node node = nodes.Find(n => n.Position.Equals(obj.Key)); List <Network> networks = DataAccess.LocationNetworks[node.Location]; if (node.ParentNetwork != null && !networks.Contains(node.ParentNetwork)) { networks.Add(node.ParentNetwork); } foreach (KeyValuePair <Side, Node> pair in node.Adjacents) { if (pair.Value is PPMNode) { PPMNode invisibilizerNode = (PPMNode)pair.Value; invisibilizerNode.AdjNetworks.Add(node.ParentNetwork); newNode.ParentNetwork.AddNode(invisibilizerNode); } } }