internal CustomNodeInfo GetNodeInfo(Guid x) { CustomNodeInfo info; NodeInfos.TryGetValue(x, out info); return(info); }
public void CreateNode(Vector2 position, NodePrefabInfos infos) { int index = 0; while (_nodes.ContainsKey(index)) { index++; } Node n = Instantiate(nodePrefab); n.Editor = this; n.transform.SetParent(modelZone.transform); n.transform.localPosition = position; n.transform.localScale = Vector2.one; NodeInfos i = new NodeInfos(); i.id = index; i.posX = position.x; i.posY = position.y; n.NodeInfos = i; n.NodePrefabInfos = infos; n.NodeInfos.type = infos.nodeName; _nodes.Add(i.id, n); }
public static ExecutableNode GetNode(Fleet fleet, NodalEditor.SaveStruct data, int nodeID) { if (!data.nodes.ContainsKey(nodeID)) { throw new System.Exception("NodeID n'existe pas lors de l'instaciation d'une executionNode"); } NodeInfos n = data.nodes[nodeID]; switch (n.type) { case "Start": return(new StartNode(fleet, data, nodeID, SimulatedWideDataManager.Container)); case "End": return(new EndNode(fleet, data, nodeID, SimulatedWideDataManager.Container)); case "Explore": return(new ExploreNode(fleet, data, nodeID, SimulatedWideDataManager.Container)); case "If": return(new IfNode(fleet, data, nodeID, SimulatedWideDataManager.Container)); case "Move To": return(new MoveToNode(fleet, data, nodeID, SimulatedWideDataManager.Container)); case "NotNull": return(new NotNull(fleet, data, nodeID, SimulatedWideDataManager.Container)); case "Loop": return(new LoopNode(fleet, data, nodeID, SimulatedWideDataManager.Container)); } throw new System.Exception(n.type + " : Unkown type of executionNode"); }
/// <summary> /// Add Element /// </summary> /// <param name="AttrInfos"></param> /// <param name="NodeInfos"></param> /// <returns></returns> public XElement CreateElement(AttribInfos AttrInfos, NodeInfos NodeInfos) { XElement el = new XElement("Item"); el.SetAttributeValue("Selected", AttrInfos.Selected); el.SetAttributeValue("ProductName", AttrInfos.ProductName); this.CreateChildNode(el, "Caption", NodeInfos.Caption); this.CreateChildNode(el, "LogLevel", NodeInfos.LogLevel); this.CreateChildNode(el, "ShowUI", NodeInfos.ShowUI); this.CreateChildNode(el, "Unit", NodeInfos.Unit); this.CreateChildNode(el, "PixelType", NodeInfos.PixelType); this.CreateChildNode(el, "Brightness", NodeInfos.Brightness); this.CreateChildNode(el, "Contrast", NodeInfos.Contrast); this.CreateChildNode(el, "Resolution", NodeInfos.Resolution); this.CreateChildNode(el, "SupportedSizes", NodeInfos.SupportedSizes); this.CreateChildNode(el, "AutomaticDeskew", NodeInfos.AutomaticDeskew); this.CreateChildNode(el, "DuplexEnabled", NodeInfos.DuplexEnabled); this.CreateChildNode(el, "Left", NodeInfos.Left); this.CreateChildNode(el, "Top", NodeInfos.Top); this.CreateChildNode(el, "Width", NodeInfos.Width); this.CreateChildNode(el, "Height", NodeInfos.Height); this.CreateChildNode(el, "UseDocumentFeeder", NodeInfos.UseDocumentFeeder); this.CreateChildNode(el, "AutomaticRotate", NodeInfos.AutomaticRotate); this.CreateChildNode(el, "AutomaticBorderDetection", NodeInfos.AutomaticBorderDetection); return(el); }
// this is a terrible hack internal ObservableDictionary <string, Guid> GetAllNodeNames() { var dict = new ObservableDictionary <string, Guid>(); NodeInfos.Select(info => new KeyValuePair <string, Guid>(info.Value.Name, info.Value.Guid)) .ToList() .ForEach(dict.Add); return(dict); }
internal CustomNodeInfo GetNodeInfo(Guid x) { if (NodeInfos.ContainsKey(x)) { return(NodeInfos[x]); } else { return(null); } }
public Bookmark GetBookmark(string paramName) { NodeInfos n = _nodes.nodes[_myID]; int id = n.nodeParams.GetInt("found", -1); if (id != -1) { return(_data._bookmarks[id]); } return(null); }
private int UpdateStop(Fleet f, NodeInfos n, NodalEditor.SaveStruct data) { _container._fleets.Remove(f.ID); foreach (int shipID in f.ShipIDs) { Ship s = _container._ships[shipID]; _currentUpdate.Add(s); s.Fleet = 0; } AddLog(f, "End of flight plan"); return(0); }
/// <summary> /// Stores the path and function definition without initializing a node. Overwrites /// the existing NodeInfo if necessary /// </summary> /// <param name="guid">The unique id for the node.</param> /// <param name="path">The path for the node.</param> public void SetNodeInfo(CustomNodeInfo newInfo) { var nodeInfo = GetNodeInfo(newInfo.Guid); if (nodeInfo == null) { NodeInfos.Add(newInfo.Guid, newInfo); } else { NodeInfos[newInfo.Guid] = newInfo; } }
private int UpdateNode(Fleet f, NodeInfos n, NodalEditor.SaveStruct data) { switch (n.type) { case "Start": return(UpdateStart(f, n, data)); case "End": return(UpdateStop(f, n, data)); case "Explore": return(UpdateExplore(f, n, data)); case "Move To": return(UpdateMoveTo(f, n, data)); } throw new System.Exception("Node type unexpected " + n.type); }
private int UpdateStart(Fleet f, NodeInfos n, NodalEditor.SaveStruct data) { AddLog(f, "Starting flight plan"); foreach (LinkInfo l in data.links) { if (l.FromID == n.id && l.FromParam == "StartOutput") { f.CurrentNode = l.ToID; break; } } return(0); }
public void LoadGraph() { NodeInfos nodeInfos = JsonUtility.FromJson <NodeInfos>(nodeInfosText.text); foreach (NodeInfo nodeInfo in nodeInfos.nodes) { GameObject spawnedNode = Instantiate(nodePrefab); spawnedNode.SetActive(false); NodeBehaviour node = spawnedNode.GetComponent <NodeBehaviour>(); node.info = nodeInfo; node.graph = this; nodeMap.Add(nodeInfo.id, spawnedNode); } HashSet <int> allNodes = new HashSet <int>(); HashSet <int> destinationNodes = new HashSet <int>(); NodeConnections connectionsInfo = JsonUtility.FromJson <NodeConnections>(nodeConnectionsText.text); foreach (NodeConnection connectionInfo in connectionsInfo.connections) { if (!nodeConnections.ContainsKey(connectionInfo.source)) { nodeConnections.Add(connectionInfo.source, new List <int>()); } nodeConnections[connectionInfo.source].Add(connectionInfo.destination); allNodes.Add(connectionInfo.source); allNodes.Add(connectionInfo.destination); destinationNodes.Add(connectionInfo.destination); } allNodes.ExceptWith(destinationNodes); if (allNodes.Count != 1) { string error = ""; foreach (int nd in allNodes) { error += nd + ", "; } throw new MissingComponentException("Incorrect graph configuration, incorrect source node count : " + allNodes.Count + " - " + error); } int sourceId = new List <int>(allNodes)[0]; GameObject sourceNode = nodeMap[sourceId]; UpdateState(sourceNode); }
public CustomNodeInfo Remove(Guid guid) { var nodeInfo = GetNodeInfo(guid); if (LoadedCustomNodes.ContainsKey(guid)) { LoadedCustomNodes.Remove(guid); } if (NodeInfos.ContainsKey(guid)) { NodeInfos.Remove(guid); } return(nodeInfo); }
public override int Update(ServerUpdate serverUpdate) { NodeInfos inputNode = null; string paramName = ""; foreach (LinkInfo l in _nodes.links) { if (l.ToID == _myID && l.ToParam == TestValue) { inputNode = _nodes.nodes[l.FromID]; paramName = l.FromParam; } } if (null == inputNode) { throw new System.Exception("No input node for the IfNode"); } ExecutableNode node = GetNode(inputNode.id); IBooleanParam boolParam = node as IBooleanParam; bool result = boolParam.GetBool(paramName); if (result) { foreach (int i in _fleet.ShipIDs) { Ship ship = _data._ships[i]; ship.AddLog("Condition checked"); } MoveFlow(OutFlowTrue); } else { foreach (int i in _fleet.ShipIDs) { Ship ship = _data._ships[i]; ship.AddLog("Condition failed"); } MoveFlow(OutFlowFalse); } return(_fleet.LastUpdateFrame); }
/// <summary> /// Tells whether the custom node's unique identifier is inside of the manager (initialized or not) /// </summary> /// <param name="guid">The FunctionId</param> public bool Contains(Guid guid) { return(IsInitialized(guid) || NodeInfos.ContainsKey(guid)); }
private int UpdateMoveTo(Fleet f, NodeInfos n, NodalEditor.SaveStruct data) { //preparation des parametres if (_container._currentFrame >= f.TaskStartFrame) { int doneFrameInNode = _container._currentFrame - f.TaskStartFrame; int timeToUndock = 100; int timeToMove = timeToUndock + 500; int timeToDock = timeToMove + 100; int timeToFuel = timeToDock + 50; string lastDoneStep = f.FleetParams.GetString("lastState", "none"); switch (lastDoneStep) { case "none": { //undocking //analyse des parametres en input if (doneFrameInNode >= 0) { int hangarID = 1; foreach (LinkInfo l in data.links) { if (l.ToID == n.id && l.ToParam == "Station") { NodeInfos hangarSelectorNode = data.nodes[l.FromID]; hangarID = hangarSelectorNode.nodeParams.GetInt("HangarID"); } } f.FleetParams.Set("targetHangar", hangarID); //undocking f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Undocking"; _currentUpdate.Add(ship); }); f.FleetParams.Set("lastState", "undock"); return(f.TaskStartFrame + timeToUndock); } else { return(f.TaskStartFrame); } } case "undock": { if (doneFrameInNode >= timeToUndock) { //undock result + moving AddLog(f, "Undocked from station"); Hangar hangar = _container._hangars[f.LastHangar]; _currentUpdate.Add(hangar); f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Moving to station"; ship.Hangar = -1; _currentUpdate.Add(ship); hangar.Ships.Remove(ship.ID); }); f.FleetParams.Set("lastState", "moving"); return(f.TaskStartFrame + timeToMove); } else { return(f.TaskStartFrame + timeToUndock); } } case "moving": { if (doneFrameInNode >= timeToMove) { AddLog(f, "Moved to target station"); f.FleetParams.Set("lastState", "dock"); return(f.TaskStartFrame + timeToDock); } else { return(f.TaskStartFrame + timeToMove); } } case "dock": { if (doneFrameInNode >= timeToDock) { //docking result int hangarID = f.FleetParams.GetInt("targetHangar"); Hangar hangar = _container._hangars[hangarID]; _currentUpdate.Add(hangar); f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Docking"; ship.Hangar = hangarID; hangar.Ships.Add(ship.ID); _currentUpdate.Add(ship); }); AddLog(f, "Docked in station"); //start fueling f.FleetParams.Set("lastState", "fuel"); return(f.TaskStartFrame + timeToFuel); } else { return(f.TaskStartFrame + timeToDock); } } case "fuel": { if (doneFrameInNode >= timeToFuel) { AddLog(f, "Fueled for Y ICU"); //fueling is done f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Idle in station"; }); foreach (LinkInfo l in data.links) { if (l.FromID == n.id && l.FromParam == "MoveOutput") { f.CurrentNode = l.ToID; break; } } f.FleetParams.Set("lastState", "none"); f.TaskStartFrame = f.TaskStartFrame + timeToFuel; return(f.TaskStartFrame); } return(f.TaskStartFrame + timeToFuel); } } } return(f.TaskStartFrame); }
private int UpdateExplore(Fleet f, NodeInfos n, NodalEditor.SaveStruct data) { //preparation des parametres int doneFrameInNode = _container._currentFrame - f.TaskStartFrame; if (_container._currentFrame >= f.TaskStartFrame) { int timeToUndock = 100; int timeToMoveZone = timeToUndock + 200; int timeToExplore = timeToMoveZone + 500; int timeToMoveBack = timeToExplore + 200; int timeToDock = timeToMoveBack + 100; int timeToFuel = timeToDock + 200; string lastDoneStep = f.FleetParams.GetString("lastState", "none"); switch (lastDoneStep) { case "none": { //undocking f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Undocking"; _currentUpdate.Add(ship); }); f.FleetParams.Set("lastState", "undock"); return(f.TaskStartFrame + timeToUndock); } case "undock": { //moving to site if (doneFrameInNode >= timeToUndock) { f.FleetParams.Set("fromHangar", f.LastHangar); f.FleetParams.Set("fromStation", f.LastStation); Hangar hangar = _container._hangars[f.LastHangar]; _currentUpdate.Add(hangar); f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "moving to site"; ship.Hangar = -1; _currentUpdate.Add(ship); hangar.Ships.Remove(sID); }); AddLog(f, "undocked from station"); //prepare next step f.FleetParams.Set("lastState", "moveOut"); return(f.TaskStartFrame + timeToMoveZone); } else { return(f.TaskStartFrame + timeToUndock); } } case "moveOut": { //Exploring if (doneFrameInNode >= timeToMoveZone) { f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Exploring"; }); AddLog(f, "Moved to explore site"); f.FleetParams.Set("lastState", "explore"); return(f.TaskStartFrame + timeToExplore); } else { return(f.TaskStartFrame + timeToMoveZone); } } case "explore": { //moving back to station if (doneFrameInNode >= timeToExplore) { f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Moving back to station"; }); AddLog(f, "Done with exploration"); f.FleetParams.Set("lastState", "moveIn"); return(f.TaskStartFrame + timeToMoveBack); } else { return(f.TaskStartFrame + timeToExplore); } } case "moveIn": { //Docking if (doneFrameInNode >= timeToMoveBack) { f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Docking"; }); AddLog(f, "Returned to station"); f.FleetParams.Set("lastState", "docking"); return(f.TaskStartFrame + timeToDock); } else { return(f.TaskStartFrame + timeToMoveBack); } } case "docking": { //Fueling if (doneFrameInNode >= timeToDock) { f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Fueling"; }); AddLog(f, "Docked to station"); f.FleetParams.Set("lastState", "fueling"); return(f.TaskStartFrame + timeToFuel); } else { return(f.TaskStartFrame + timeToDock); } } case "fueling": { //next step if (doneFrameInNode >= timeToFuel) { int hangarID = f.FleetParams.GetInt("fromHangar"); Hangar hangar = _container._hangars[hangarID]; _currentUpdate.Add(hangar); f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Hangar = hangarID; _currentUpdate.Add(ship); hangar.Ships.Add(sID); }); AddLog(f, "undocked from station"); //prepare fueling AddLog(f, "Fueled for X ICU"); f.FleetParams.Set("lastState", "nextStep"); return(f.TaskStartFrame + timeToFuel); } else { return(f.TaskStartFrame + timeToFuel); } } case "nextStep": { //all done, next node if (doneFrameInNode >= timeToFuel) { f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Idle in station"; }); foreach (LinkInfo l in data.links) { if (l.FromID == n.id && l.FromParam == "ExploreOutput") { f.CurrentNode = l.ToID; break; } } f.FleetParams.Set("lastState", "none"); f.TaskStartFrame = f.TaskStartFrame + timeToFuel; return(f.TaskStartFrame + timeToFuel); } else { return(f.TaskStartFrame + timeToFuel); } }; } } return(f.TaskStartFrame); }
public override int Update(ServerUpdate serverUpdate) { if (_data._currentFrame >= _fleet.NextUpdateFrame) { string lastDoneStep = _fleet.FleetParams.GetString("currentState", "none"); switch (lastDoneStep) { case "none": { //undocking //preparer les données int hangarID = 1; foreach (LinkInfo l in _nodes.links) { if (l.ToID == _myID && l.ToParam == "Station") { NodeInfos hangarSelectorNode = _nodes.nodes[l.FromID]; hangarID = hangarSelectorNode.nodeParams.GetInt("HangarID"); } } _fleet.NextHangar = hangarID; //demarer StartUndock(serverUpdate); } break; case "undocking": { Undock(serverUpdate); NextUpdateFrame(200); //todo calculer le temps pour se rendre _fleet.ShipIDs.ForEach((sID) => { Ship ship = _data._ships[sID]; ship.Status = "Moving to station"; serverUpdate.Add(ship); }); _fleet.FleetParams.Set("currentState", "moving"); } break; case "moving": { _fleet.ShipIDs.ForEach((sID) => { Ship ship = _data._ships[sID]; ship.AddLog("Moved to target station"); serverUpdate.Add(ship); }); _fleet.FleetParams.Set("currentState", "dock"); } break; case "dock": { StartDock(serverUpdate); } break; case "docking": { Dock(serverUpdate); StartFueling(serverUpdate); } break; case "fueling": { Fuel(serverUpdate); } break; case "doneFueling": { foreach (int sID in _fleet.ShipIDs) { Ship ship = _data._ships[sID]; ship.Status = "Idle in station"; } MoveFlow("MoveOutput"); } break; } } return(_fleet.NextUpdateFrame); }
/// <summary> /// Get a function id from a guid assuming that the file is already loaded. /// </summary> /// <param name="path"></param> /// <returns></returns> public Guid GuidFromPath(string path) { var pair = NodeInfos.FirstOrDefault(x => x.Value.Path == path); return(pair.Key); }
internal CustomNodeInfo GetNodeInfo(string name) { return(NodeInfos.FirstOrDefault(x => x.Value.Name == name).Value); }
public override int Update(ServerUpdate serverUpdate) { if (_data._currentFrame < _fleet.NextUpdateFrame) { return(_fleet.NextUpdateFrame); } string currentState = _fleet.FleetParams.GetString("currentState", "none"); switch (currentState) { case "none": { Ship s1 = _data._ships[_fleet.ShipIDs[0]]; _fleet.LastHangar = s1.Hangar; Hangar h = _data._hangars[s1.Hangar]; _fleet.LastStation = h.Station; _fleet.NextHangar = _fleet.LastHangar; StartUndock(serverUpdate); } break; case "undocking": { Undock(serverUpdate); //start moveTo NextUpdateFrame(100); foreach (int sID in _fleet.ShipIDs) { Ship ship = _data._ships[sID]; ship.Hangar = -1; ship.Status = "Moving to explore site"; serverUpdate.Add(ship); } _fleet.FleetParams.Set("currentState", "moveOut"); } break; case "moveOut": { NextUpdateFrame(500); foreach (int sID in _fleet.ShipIDs) { Ship ship = _data._ships[sID]; ship.Status = "Exploring"; ship.AddLog("Moved to explore site"); serverUpdate.Add(ship); } _fleet.FleetParams.Set("currentState", "explore"); } break; case "explore": { NextUpdateFrame(200); //choisir un POI si possible bool didFound = false; Random r = new Random(); double a = r.NextDouble(); NodeInfos n = _nodes.nodes[_myID]; int sector = n.nodeParams.GetInt("zone", 0); List <PointOfInterest> possible = _data._POIs.Values.Where(p => p.FindProba > a && p.Sector == sector).ToList(); if (possible.Count > 0) { didFound = true; int index = r.Next(possible.Count); PointOfInterest found = possible[index]; Bookmark bookmark = new Bookmark(_data._bookmarkIDs++, index); bookmark.datas = found.DatasToBookmark(); _data._bookmarks.Add(bookmark.ID, bookmark); n.nodeParams.Set("found", bookmark.ID); /* * Corporation c = _container._corps[s.Corp]; * SendMailRequest request = new SendMailRequest(-1, c.Owner); * request.Message = "You found something while exploring, congrat! \n\n" + found.Description; * request.Subject = "Exploration result"; * _manager.SendRequest(request); */ } foreach (int sID in _fleet.ShipIDs) { Ship ship = _data._ships[sID]; ship.Status = "Moving back to station"; ship.AddLog("Done with exploration"); if (didFound) { ship.AddLog("And found something..."); } serverUpdate.Add(ship); } _fleet.FleetParams.Set("currentState", "moveIn"); } break; case "moveIn": { StartDock(serverUpdate); } break; case "docking": { Dock(serverUpdate); StartFueling(serverUpdate); } break; case "fueling": { Fuel(serverUpdate); } break; case "doneFueling": { foreach (int sID in _fleet.ShipIDs) { Ship ship = _data._ships[sID]; ship.Status = "Idle in station"; } MoveFlow("ExploreOutput"); } break; } return(_fleet.NextUpdateFrame); }