public void GivenStartNodeHasTypeButNoXPath_WhenToString_ResultIsJsonWithTypeContent() { var startNode = new StartNode(NodeType.Content, null, null); var result = startNode.ToJsonString(); result.Should().Be(@"{""type"":""content""}"); }
private void MenuItemFileSave_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = (MenuItem)sender; CheckIfSaveFileIsPossible(menuItem); string Map = string.Empty; Map += MaxX.ToString(); Map += Environment.NewLine + MaxY.ToString(); Map += Environment.NewLine + StartNode.ToString(); Map += Environment.NewLine + EndNode.ToString(); foreach (Node node in AllNodes) { if (node.IsObstacle) { Map += Environment.NewLine + node.ToString(); } } if (menuItem.Name == MenuItemFileSaveAs.Name || FilePath == string.Empty) { FileSave(menuItem, Map); } else if (menuItem.Name == MenuItemFileSave.Name) { FileSave(menuItem, Map); } }
public async Task ForcedParameterCustomType() { IScriptParser parser = new ScriptParser(); parser.Types.AddType <Transition>(); Mock <IScriptCompiler> compiler = new Mock <IScriptCompiler>(); compiler.Setup(s => s.CompileCode(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.Parse(code)); compiler.Setup(s => s.CompileCodeAsync(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.ParseAsync(code)); StartNode node = new StartNode(Guid.NewGuid(), "Start", new StartParameters { Parameters = new[] { new ParameterDeclaration { Name = "input", Type = "transition[]", Default = "[{\"Log\": \"\\\"Hello there\\\"\"}]" } } }, compiler.Object); Dictionary <string, object> variables = new Dictionary <string, object>(); await node.Execute(new WorkflowInstanceState(new WorkflowIdentifier(), null, new StateVariableProvider(variables), s => null, null, null, false), CancellationToken.None); Transition[] input = variables["input"] as Transition[]; Assert.NotNull(input); Assert.AreEqual(1, input.Length); Assert.AreEqual("\"Hello there\"", input[0].Log); }
public async Task ForcedParameterComplexType() { IScriptParser parser = new ScriptParser(); parser.Types.AddType <Campaign>(); Mock <IScriptCompiler> compiler = new Mock <IScriptCompiler>(); compiler.Setup(s => s.CompileCode(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.Parse(code)); compiler.Setup(s => s.CompileCodeAsync(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.ParseAsync(code)); StartNode node = new StartNode(Guid.NewGuid(), "Start", new StartParameters { Parameters = new[] { new ParameterDeclaration { Name = "input", Type = "campaign", } } }, compiler.Object); Dictionary <string, object> variables = new Dictionary <string, object> { ["input"] = await Json.ReadAsync(typeof(StartNodeTests).Assembly.GetManifestResourceStream("ScriptService.Tests.Data.2020-10-22_campaign.json")) }; await node.Execute(new WorkflowInstanceState(new WorkflowIdentifier(), null, new StateVariableProvider(variables), s => null, null, null, false), CancellationToken.None); Campaign campaign = variables["input"] as Campaign; Assert.NotNull(campaign); }
public async Task ForcedParameterDefaultArray() { Mock <IScriptCompiler> compiler = new Mock <IScriptCompiler>(); compiler.Setup(s => s.CompileCode(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => new ScriptParser().Parse(code)); compiler.Setup(s => s.CompileCodeAsync(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => new ScriptParser().ParseAsync(code)); StartNode node = new StartNode(Guid.NewGuid(), "Start", new StartParameters { Parameters = new[] { new ParameterDeclaration { Name = "input", Type = "int[]", Default = "[1,2,3]" } } }, compiler.Object); Dictionary <string, object> variables = new Dictionary <string, object>(); await node.Execute(new WorkflowInstanceState(new WorkflowIdentifier(), null, new StateVariableProvider(variables), s => null, null, null, false), CancellationToken.None); IEnumerable <int> input = variables["input"] as IEnumerable <int>; Assert.NotNull(input); Assert.That(new[] { 1, 2, 3 }.SequenceEqual(input)); }
public void Reset() { OnCompleted?.Invoke(this, Status); Status = NodeStatus.None; StartNode?.Reset(); Blackboard.Clear(); }
/// <summary> /// Checks if the path is ready to be found. /// </summary> private void CheckIfPathReady() { if (StartNode != null && GoalNode != null) { // Pathfinding List <ButtonNode> pathNodes = pathfinder.FindPath(); // If the path is found if (!(pathNodes is null)) { // Set up the path buttons for (int i = 0; i < pathNodes.Count; i++) { ButtonInfo pathButton = ButtonPool.sharedInstance.GetPooledButton(pathNodes[i].X - 1, pathNodes[i].Y - 1); pathButton.IsPath(true, pathNodes[i].DistanceFromStart); pathButtons.Add(pathButton); } // Adjust the text of the start and goal buttons StartNode.AddDistanceText(0); int goalNodeDistance = pathNodes[0].DistanceFromStart + 1; GoalNode.AddDistanceText(goalNodeDistance); } else { Debug.Log("Could not find a path to the goal."); } }
override public Node Cast2Node(DialogueTree _dt) { StartNode n = new StartNode(_dt, myPos); n.nodeName = name; return(n); }
private void FindKeyNodes() { for (int i = nodes.Count - 1; i > -1; i--) { if (nodes[i] == null) { nodes.RemoveAt(i); } } foreach (BaseNode node in nodes) { node.graph = this; if (node.NodeType == NodeType.Start) { startNode = (StartNode)node; } if (node.NodeType == NodeType.End) { endNode = (EndNode)node; } if (node.NodeType == NodeType.Any) { anyNode = (AnyNode)node; } } }
private void ProcessCurrentNode() { switch (currentNode.GetType()) { case var type when type == typeof(StartNode): StartNode startNode = (StartNode)currentNode; break; case var type when type == typeof(DialogNode): DialogNode dialogNode = (DialogNode)currentNode; string speech = dialogNode.currentDialog.CharacterText.Text; var character = dialogNode.currentDialog.CharacterText.Character; string speaker = character == Characters.Narrator ? "" : character.ToString(); DialogSystem.Say(speech, speaker); break; case var type when type == typeof(ChoiceNode): break; case var type when type == typeof(BranchNode): break; default: break; } }
/// <summary> /// 接続を曲線として描画 /// </summary> public void Draw() { if (EndNode == null) { throw new UnityException("No end node."); } var start = StartNode.CalculateConnectorPoint(StartPosition); var startV3 = new Vector3(start.x, start.y, 0f); var end = EndNode.CalculateConnectorPoint(EndPosition); var endV3 = new Vector3(end.x, end.y, 0f); var distanceX = Mathf.Abs(startV3.x - endV3.x); var startTan = new Vector3(StartPosition.side == JunctionSide.Left ? start.x - distanceX / 2.0f : start.x + distanceX / 2.0f, start.y, 0f); var endTan = new Vector3(EndPosition.side == JunctionSide.Left ? end.x - distanceX / 2.0f : end.x + distanceX / 2.0f, end.y, 0f); if (ConnectorManager.selected == this) { color = selectedColor; } else { color = defaultColor; } Handles.DrawBezier(startV3, endV3, startTan, endTan, color, null, 4f); }
public void GivenStartNodeHasBothTypeAndXPath_WhenToString_ResultIsJsonWithTypeContentQuerySite() { var startNode = new StartNode(NodeType.Content, null, "$site"); var result = startNode.ToJsonString(); result.Should().Be(@"{""type"":""content"",""query"":""$site""}"); }
public FSM(MonoBehaviour a) { currentNode = new StartNode(); startNode = (StartNode)currentNode; nodes = new List <FSMNode>(); agent = a; }
public virtual void UpdateAttractionForces(double defaultSpringLength, double attractionConstant) { var force = CalcAttractionForce(defaultSpringLength, attractionConstant); StartNode.AddForce(ForceType.Attraction, force); EndNode.AddForce(ForceType.Attraction, -force); }
public void TestNodeEqualsSelf() { Node start = new StartNode(new Point(-1, -1), new Point(10, 10)); Node node = new Node(new Point(1, 1), new Point(10, 10), start); Assert.IsTrue(node.Equals(node)); }
public static TreeNode GetAllTypeNode() { TypesB1Node nodeType = new TypesB1Node(); nodeType.Text = nodeType.KNXMainNumber + "." + nodeType.KNXSubNumber + " " + nodeType.Name; nodeType.Nodes.Add(SwitchNode.GetTypeNode()); nodeType.Nodes.Add(BoolNode.GetTypeNoe()); nodeType.Nodes.Add(EnableNode.GetTypeNode()); nodeType.Nodes.Add(RampNode.GetTypeNode()); nodeType.Nodes.Add(AlarmNode.GetTypeNode()); nodeType.Nodes.Add(BinaryValueNode.GetTypeNode()); nodeType.Nodes.Add(StepNode.GetTypeNode()); nodeType.Nodes.Add(UpDownNode.GetTypeNode()); nodeType.Nodes.Add(OpenCloseNode.GetTypeNode()); nodeType.Nodes.Add(StartNode.GetTypeNode()); nodeType.Nodes.Add(StateNode.GetTypeNode()); nodeType.Nodes.Add(InvertNode.GetTypeNode()); nodeType.Nodes.Add(DimSendStyleNode.GetTypeNode()); nodeType.Nodes.Add(InputSourceNode.GetTypeNode()); nodeType.Nodes.Add(ResetNode.GetTypeNode()); nodeType.Nodes.Add(AckNode.GetTypeNode()); nodeType.Nodes.Add(TriggerNode.GetTypeNode()); nodeType.Nodes.Add(OccupancyNode.GetTypeNode()); nodeType.Nodes.Add(WindowDoorNode.GetTypeNode()); nodeType.Nodes.Add(LogicalFunctionNode.GetTypeNode()); nodeType.Nodes.Add(SceneABNode.GetTypeNode()); nodeType.Nodes.Add(ShutterBlindsModeNode.GetTypeNode()); nodeType.Nodes.Add(HeatCoolNode.GetTypeNode()); return(nodeType); }
private void GenerateNodes(LevelMapSO _levelFlowSO) { //Start Data foreach (StartNodeData _data in _levelFlowSO.startNodeDatas) { StartNode _startNode = graphView.CreateStartNode(_data.position); _startNode.NodeGuid = _data.guid; _startNode.startName = _data.startName; _startNode.portSet = _data.portSet; _startNode.LoadValueIntoField(); graphView.AddElement(_startNode); } //Level Node foreach (LevelNodeData _data in _levelFlowSO.levelNodeDatas) { LevelNode _lvNode = graphView.CreateLevelNode(_data.position); _lvNode.NodeGuid = _data.guid; //_lvNode.scene = _data.scene; //_lvNode.scenePath = _data.scenePath; _lvNode.scenAssetGuid = _data.sceneAssestGuid; _lvNode.asyncType = _data.asyncType; _lvNode.loadType = _data.loadType; _lvNode.portSets = _data.portSets; _lvNode.scenePath = _data.scenePath; Debug.Log("1. GenerateNodes port count" + _data.portSets.Count); _lvNode.LoadValueIntoField(); graphView.AddElement(_lvNode); } }
public override string ToString() { return("InnovNb: " + InnovationNb + " " + "w: " + Weight.ToString() + " " + "In: {" + StartNode.ToString() + "} " + "Out: {" + EndNode.ToString() + "}"); }
protected override void DrawFields() { StartNode node = target as StartNode; base.DrawFields(); bool hasOutput = false; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Output Setting", GUILayout.MaxWidth(120f)); GUILayoutOption[] option = { GUILayout.MaxWidth(80f), GUILayout.MinWidth(40f) }; for (int i = 0; i < NetworkNode.NeighborNum; i++) { node.OutputSetting[i] = EditorGUILayout.ToggleLeft( directionString[i], node.OutputSetting[i], option); if (node.OutputSetting[i]) { hasOutput = true; } } } EditorGUILayout.EndHorizontal(); if (!hasOutput) { ShowTips("开始节点需要至少一个输出", MessageType.Warning); } else { ClearTips(); } }
//Crea el StartNode public StartNode AddStartNode(Rect rect, int id) { StartNode startNode = new StartNode(); startNode.SetWindowRect(rect).SetWindowTitle("Start").SetId(id).SetReference(this); _nodes.Add(startNode); return(startNode); }
public void TestNodeNotEquals() { Node start = new StartNode(new Point(-1, -1), new Point(10, 10)); Node node1 = new Node(new Point(1, 1), new Point(10, 10), start); Node node2 = new Node(new Point(1, 5), new Point(10, 10), start); Assert.IsFalse(node1.Equals(node2)); }
public void TestNodeEqualsSamePoint() { Node start = new StartNode(new Point(-1, -1), new Point(10, 10)); Node node1 = new Node(new Point(1, 1), new Point(10, 10), start); Node node2 = new Node(new Point(1, 1), new Point(10, 10), start); Assert.IsTrue(node1.Equals(node2)); }
/* * Initializes the dictionary scriptable object and starts the tree's execution */ public void Start() { treeDataDict = (TreeDict)ScriptableObject.CreateInstance(typeof(TreeDict)); if (StartNode) { StartCoroutine(StartNode.Execute()); } }
/// <summary> /// Compares edges using <see cref="StartNode"/>, <see cref="EndNode"/>, <see cref="Distance"/> properties. /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { var edge = obj as IEdge <T>; return(StartNode.Equals(edge.StartNode) && EndNode.Equals(edge.EndNode) && Distance.Equals(edge.Distance)); }
/// <summary> /// Inserts node from start and returns the new node /// </summary> /// <param name="nodeKey"></param> /// <param name="nodeData"></param> /// <returns></returns> public Node InsertFromStart(string nodeKey, NodeData nodeData = default) { if (graphLocked) { throw new DoubleLinkedDirectedGraphException("Graph is finished either by call to FinishGraph or implicitly by using End"); } return(StartNode.Insert(nodeKey, string.Empty, nodeData)); }
//TODO use NodeType to categorize Types. public static BaseNode CreateNode(ActionNodeData aData) { if (aData.NodeType == null) { Debug.LogError("Type not set"); return(null); } aData.GUID = string.IsNullOrEmpty(aData.GUID) ? Guid.NewGuid().ToString() : aData.GUID; aData.OutputPortIDs = aData.OutputPortIDs ?? new List <string>(); //The copy prevent the node to modify the list in the ActionNodeData List <string> copy = new List <string>(); foreach (var outputPort in aData.OutputPortIDs) { copy.Add(outputPort); } BaseNode node; Type type = Type.GetType(aData.NodeType); if (type == typeof(ChangeSceneNode)) { node = ChangeSceneNode.Create("Change Scene", aData.Position, aData.GUID, copy); } else if (type == typeof(StartNode)) { node = StartNode.Create("Start Node", aData.Position, aData.GUID, copy); } else if (type == typeof(ConditionalNode)) { node = ConditionalNode.Create("Conditional", aData.Position, aData.GUID, copy); } else if (type == typeof(MultiNode)) { node = MultiNode.Create("Multi Output", aData.Position, aData.GUID, copy); } else if (type == typeof(ExitNode)) { node = ExitNode.Create("Exit Node", aData.Position, aData.GUID, copy); } else if (type == typeof(RandomNode)) { node = RandomNode.Create("Random Node", aData.Position, aData.GUID, copy); } else if (type == typeof(TakeObjectNode)) { node = TakeObjectNode.Create("Take Object", aData.Position, aData.GUID, copy); } else { throw new NotImplementedException($"Node type {type} not handled in NodeFactory"); } node?.SetSerializedScript(aData.SerializedScript); return(node); }
/// <summary> /// Starts the conversation. /// </summary> public void Play() { StartNode startNode = CurrentNode as StartNode; if (startNode != null) { MoveToNode(startNode.Next); } }
protected override void OnClickRemoveNode(BaseNode node) { base.OnClickRemoveNode(node); if (node == StartPoint) { StartPoint = null; } }
protected void OnClickAddStartNode(Vector2 mousePosition) { if (nodes == null) { nodes = new List <BaseNode>(); } StartPoint = new StartNode(mousePosition, 200, 100, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode, OnClickDuplicateNode); nodes.Add(StartPoint); }
private void importActivityNode(SQLElement sdmContainer, MocaNode activityNodeNode) { EA.Element activityNodeElement = null; ActivityNode aNode = null; if (activityNodeNode.getAttributeOrCreate("type").Value == "start") { activityNodeElement = MainImport.getInstance().EcoreImport.getOrCreateElement(sdmContainer, activityNodeNode, Main.EAStateNodeType, Main.EAStartNodeSubtype); aNode = new StartNode(sqlRep, sqlRep.GetElementByID(activityNodeElement.ElementID)); } else if (activityNodeNode.getAttributeOrCreate("type").Value == "stop") { activityNodeElement = MainImport.getInstance().EcoreImport.getOrCreateElement(sdmContainer, activityNodeNode, Main.EAStateNodeType, Main.EAStopNodeSubtype); aNode = new StopNode(sqlRep, sqlRep.GetElementByID(activityNodeElement.ElementID)); } else if (activityNodeNode.getAttributeOrCreate("type").Value == "statement") { activityNodeElement = MainImport.getInstance().EcoreImport.getOrCreateElement(sdmContainer, activityNodeNode, Main.EAActivityType); aNode = new StatementNode(sqlRep, sqlRep.GetElementByID(activityNodeElement.ElementID)); } else if (activityNodeNode.getAttributeOrCreate("type").Value == "story") { activityNodeElement = MainImport.getInstance().EcoreImport.getOrCreateElement(sdmContainer, activityNodeNode, Main.EAActivityType); appendSdmDiagram(activityNodeElement.Name, activityNodeElement); aNode = new StoryNode(sqlRep, sqlRep.GetElementByID(activityNodeElement.ElementID)); } MocaNode outgoingEdgesNode = activityNodeNode.getChildNodeWithName(ActivityNode.OutgoingTransitionsNodeName); if (outgoingEdgesNode != null) { foreach (MocaNode outgoingEdgeNode in outgoingEdgesNode.Children) { MainImport.getInstance().ConnectorNodeToParent.Add(outgoingEdgeNode, activityNodeElement); } } MocaNode objectVariablesNode = activityNodeNode.getChildNodeWithName(StoryPattern.ObjectVariablesChildNodeName); if (objectVariablesNode != null) { foreach (MocaNode ovNode in objectVariablesNode.Children) { importObjectVariable(sqlRep.GetElementByID(activityNodeElement.ElementID), ovNode); } } aNode.deserializeFromMocaTree(activityNodeNode); MainImport.getInstance().ElementGuidToElement.Add(activityNodeElement.ElementGUID, activityNodeElement); MainImport.getInstance().OldGuidToNewGuid.Add(aNode.EaGuid, activityNodeElement.ElementGUID); MainImport.getInstance().MocaTaggableElements.Add(aNode); }
public void SimpleProcess() { var startNode = new StartNode("1. Submit claim"); var n2 = new Activity("2. Middle"); var endNode = new EndNode("3. Closed"); var t12 = new SequenceFlow(startNode, n2); var t23 = new SequenceFlow(n2, endNode); this.process = new Process(startNode); }
public void ImplicitGatewayProcess() { var startNode = new StartNode("0. Start"); var n1 = new Activity("1. Submit claim"); var n2 = new Activity("2. Child A"); var n3 = new Activity("3. Child B"); var endNode = new EndNode("4. Closed"); var ts1 = new SequenceFlow(startNode, n1); var t12 = new SequenceFlow(n1, n2); var t13 = new SequenceFlow(n1, n3); var t2e = new SequenceFlow(n2, endNode); var t3e = new SequenceFlow(n3, endNode); this.process = new Process(startNode); }
public void SplitGwProcess() { var startNode = new StartNode("1. Submit claim"); var xorGw = new ParallelGateway("X. Split"); var n2 = new Activity("2. Child A"); var n3 = new Activity("3. Child B"); var joinGw = new JoinGateway("X. Join"); var endNode = new EndNode("4. Closed"); var t1gw = new SequenceFlow(startNode, xorGw); var tgw2 = new SequenceFlow(xorGw, n2); var tgw3 = new SequenceFlow(xorGw, n3); var t2End = new SequenceFlow(n2, joinGw); var t3End = new SequenceFlow(n3, joinGw); var tJE = new SequenceFlow(joinGw, endNode); this.process = new Process(startNode); }
public void SplitConditionalProcess() { var startNode = new StartNode("1. Submit claim"); var xorGw = new SplitConditionalGateway<string>("X. Split", (e => transitionState)); var n2 = new Activity("2. Child A"); var n3 = new Activity("3. Child B"); var n4 = new Activity("4. Child C"); var joinGw = new JoinGateway("X. Join"); var endNode = new EndNode("5. Closed"); var t1gw = new SequenceFlow(startNode, xorGw); var tgw2 = new ConditionalFlow<string>(xorGw, n2, "a"); var tgw3 = new ConditionalFlow<string>(xorGw, n3, "a"); var tgw4 = new ConditionalFlow<string>(xorGw, n4, "b"); var t2Join = new SequenceFlow(n2, joinGw); var t3Join = new SequenceFlow(n3, joinGw); var t4Join = new SequenceFlow(n4, joinGw); var tJE = new SequenceFlow(joinGw, endNode); this.process = new Process(startNode); }
public void TimerEventScenario(int s) { var startNode = new StartNode("1. Submit"); var n2 = new TimerNode("2. Wait 2 seconds", new TimeSpan(0, 0, s)); var endNode = new EndNode("3. Closed"); var t12 = new SequenceFlow(startNode, n2); var t23 = new SequenceFlow(n2, endNode); this.process = new Process(startNode); }
public void XorGwProcess() { var startNode = new StartNode("1. Submit claim"); var xorGw = new ExclusiveGateway<string>("X. Decide", (e => transitionState)); var n2 = new Activity("2. Alternative A"); var n3 = new Activity("3. Alternative B"); var n4 = new Activity("D. Default"); var endNode = new EndNode("4. Closed"); var t1gw = new SequenceFlow(startNode, xorGw); var tgw2 = new ConditionalFlow<string>(xorGw, n2, "a"); var tgw3 = new ConditionalFlow<string>(xorGw, n3, "b"); var tgw4 = new DefaultFlow(xorGw, n4); var t2End = new SequenceFlow(n2, endNode); var t3End = new SequenceFlow(n3, endNode); var t4End = new SequenceFlow(n4, endNode); this.process = new Process(startNode); }