public async void SearchExample() { Control root = GetNode("SearchExample") as Control; root.SetVisible(true); Tween tween = new Tween(); AddChild(tween); Control mapContainers = root.GetNode("NodeMaps") as Control; List <NodeMap> maps = new List <NodeMap>(); int seed = 89012634; foreach (Node map in mapContainers.GetChildren()) { NodeMap temp = map.GetNode("NodeMap") as NodeMap; temp.SetHeight(61); temp.SetWidth(47); temp.ResizeBlock(); temp.seed = seed; temp.useSeed = true; maps.Add(temp); } // rename the title and size (mapContainers.GetNode("DFS/GraphTitle") as Label).Text = "DFS - " + maps[0].width + " x " + maps[0].height; (mapContainers.GetNode("BFS/GraphTitle") as Label).Text = "BFS - " + maps[1].width + " x " + maps[1].height; (mapContainers.GetNode("Dijkstra/GraphTitle") as Label).Text = "Dijkstra - " + maps[2].width + " x " + maps[2].height; (mapContainers.GetNode("AStar/GraphTitle") as Label).Text = "AStar - " + maps[3].width + " x " + maps[3].height; await ToSignal(this, "next"); Control header = root.GetNode("Header") as Control; header.SetVisible(true); tween = CommonTweenUtil.Fade(header, 0.3f, 0, 1, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); await ToSignal(this, "next"); foreach (Node map in mapContainers.GetChildren()) { tween = CommonTweenUtil.Fade(map, 0.3f, 0, 1, tween); } tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); await ToSignal(this, "next"); foreach (NodeMap map in maps) { map.seed = seed; map.GenerateMap(); } foreach (NodeMap map in maps) { activeNodeMaps[map] = true; WaitForActiveNodeMaps(map); } await ToSignal(this, "active_nodemaps_finished"); await ToSignal(this, "next"); foreach (NodeMap map in maps) { activeNodeMaps[map] = true; WaitForActiveNodeMaps(map); } // record distance here and expansion maps[0].DFS(); maps[1].BFS(); maps[2].Dijkstra(); maps[3].AStar(); await ToSignal(this, "active_nodemaps_finished"); await ToSignal(this, "next"); for (int i = 1; i < mapContainers.GetChildCount(); i++) { tween = CommonTweenUtil.Fade(mapContainers.GetChild(i), 0.3f, 1, 0, tween); } tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); await ToSignal(this, "next"); tween = CommonTweenUtil.MoveGlobal(mapContainers, new Vector2(1180, 303), 0.3f, tween, Tween.TransitionType.Quad, Tween.EaseType.In); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); await ToSignal(this, "next"); tween = CommonTweenUtil.Fade((mapContainers.GetChild(0).GetChild(0) as Label), 0.3f, 1, 0, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); NodeMap maze = maps[0]; await ToSignal(this, "next"); for (int i = 0; i < maze.width * maze.height; i++) { tween = CommonTweenUtil.SetProperty((maze.container.GetChild(i) as ColorRect), "color", maze.wallColour, 0.3f, tween); } tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); await ToSignal(this, "next"); tween = CommonTweenUtil.SetSize(mapContainers.GetChild(0).GetChild(1) as Control, new Vector2(630, 630), 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); maze.Clear(); maze.container.Set("custom_constants/vseparation", 1); maze.container.Set("custom_constants/hseparation", 1); maze.SetHeight(15); maze.SetWidth(15); maze.ResizeBlock(); await ToSignal(this, "next"); for (int i = 1; i < 15 - 1; i++) { for (int j = 1; j < 15 - 1; j++) { tween = CommonTweenUtil.SetProperty((maze.container.GetChild(i * 15 + j) as ColorRect), "color", maze.mazeColour, 0.3f, tween); } } int dstIdx = 3 * 15 + 9; int rootIdx = 7 * 15 + 3; tween = CommonTweenUtil.SetProperty((maze.container.GetChild(dstIdx) as ColorRect), "color", maze.dstColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx) as ColorRect), "color", maze.rootColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); for (int i = 1; i < 15 - 1; i++) { for (int j = 1; j < 15 - 1; j++) { maze.SetCell(i * 15 + j, true); } } maze.SetDst(dstIdx); maze.SetRoot(rootIdx); // NOW DO DFS // simulate three steps here await ToSignal(this, "next"); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); rootIdx -= 1; await ToSignal(this, "next"); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx) as ColorRect), "color", maze.expandedColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); rootIdx -= 1; await ToSignal(this, "next"); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx) as ColorRect), "color", maze.expandedColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); rootIdx += 15; await ToSignal(this, "next"); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx) as ColorRect), "color", maze.expandedColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); maze.searchTimestep = 0.1f; maze.pathTimestep = 0.1f; await ToSignal(this, "next"); maze.DFS(); await ToSignal(maze, "finished"); await ToSignal(this, "next"); maze.ResizeBlock(); for (int i = 1; i < 15 - 1; i++) { for (int j = 1; j < 15 - 1; j++) { tween = CommonTweenUtil.SetProperty((maze.container.GetChild(i * 15 + j) as ColorRect), "color", maze.mazeColour, 0.3f, tween); } } tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); await ToSignal(this, "next"); maze.GenerateMap(); await ToSignal(maze, "finished"); await ToSignal(this, "next"); maze.DFS(); await ToSignal(maze, "finished"); maze.useSeed = false; // NOW DO BFS await ToSignal(this, "next"); maze.ResizeBlock(); for (int i = 1; i < 15 - 1; i++) { for (int j = 1; j < 15 - 1; j++) { tween = CommonTweenUtil.SetProperty((maze.container.GetChild(i * 15 + j) as ColorRect), "color", maze.mazeColour, 0.3f, tween); } } dstIdx = 3 * 15 + 9; rootIdx = 7 * 15 + 3; tween = CommonTweenUtil.SetProperty((maze.container.GetChild(dstIdx) as ColorRect), "color", maze.dstColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx) as ColorRect), "color", maze.rootColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); for (int i = 1; i < 15 - 1; i++) { for (int j = 1; j < 15 - 1; j++) { maze.SetCell(i * 15 + j, true); } } maze.SetDst(dstIdx); maze.SetRoot(rootIdx); // simulate four steps here await ToSignal(this, "next"); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); rootIdx -= 15; await ToSignal(this, "next"); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx) as ColorRect), "color", maze.expandedColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); rootIdx += (1 + 15); await ToSignal(this, "next"); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx) as ColorRect), "color", maze.expandedColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); rootIdx += (-1 + 15); await ToSignal(this, "next"); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx) as ColorRect), "color", maze.expandedColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); rootIdx += (-15 - 1); await ToSignal(this, "next"); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx) as ColorRect), "color", maze.expandedColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); await ToSignal(this, "next"); maze.BFS(); await ToSignal(maze, "finished"); await ToSignal(this, "next"); maze.ResizeBlock(); for (int i = 1; i < 15 - 1; i++) { for (int j = 1; j < 15 - 1; j++) { tween = CommonTweenUtil.SetProperty((maze.container.GetChild(i * 15 + j) as ColorRect), "color", maze.mazeColour, 0.3f, tween); } } tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); await ToSignal(this, "next"); maze.GenerateMap(); await ToSignal(maze, "finished"); await ToSignal(this, "next"); maze.BFS(); await ToSignal(maze, "finished"); // NOW DO DIJKSTRA await ToSignal(this, "next"); maze.ResizeBlock(); for (int i = 1; i < 15 - 1; i++) { for (int j = 1; j < 15 - 1; j++) { tween = CommonTweenUtil.SetProperty((maze.container.GetChild(i * 15 + j) as ColorRect), "color", maze.mazeColour, 0.3f, tween); } } dstIdx = 3 * 15 + 9; rootIdx = 7 * 15 + 3; tween = CommonTweenUtil.SetProperty((maze.container.GetChild(dstIdx) as ColorRect), "color", maze.dstColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx) as ColorRect), "color", maze.rootColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); for (int i = 1; i < 15 - 1; i++) { for (int j = 1; j < 15 - 1; j++) { maze.SetCell(i * 15 + j, true); } } maze.SetDst(dstIdx); maze.SetRoot(rootIdx); // simulate four steps here await ToSignal(this, "next"); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); rootIdx -= 15; await ToSignal(this, "next"); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx) as ColorRect), "color", maze.expandedColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); rootIdx += (1 + 15); await ToSignal(this, "next"); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx) as ColorRect), "color", maze.expandedColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); rootIdx += (-1 + 15); await ToSignal(this, "next"); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx) as ColorRect), "color", maze.expandedColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); rootIdx += (-15 - 1); await ToSignal(this, "next"); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx) as ColorRect), "color", maze.expandedColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx - 1) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx + 15) as ColorRect), "color", maze.searchColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); await ToSignal(this, "next"); maze.Dijkstra(); await ToSignal(maze, "finished"); await ToSignal(this, "next"); maze.ResizeBlock(); for (int i = 1; i < 15 - 1; i++) { for (int j = 1; j < 15 - 1; j++) { tween = CommonTweenUtil.SetProperty((maze.container.GetChild(i * 15 + j) as ColorRect), "color", maze.mazeColour, 0.3f, tween); } } tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); await ToSignal(this, "next"); maze.GenerateMap(); await ToSignal(maze, "finished"); await ToSignal(this, "next"); maze.Dijkstra(); await ToSignal(maze, "finished"); // NOW DO ASTAR await ToSignal(this, "next"); maze.ResizeBlock(); for (int i = 1; i < 15 - 1; i++) { for (int j = 1; j < 15 - 1; j++) { tween = CommonTweenUtil.SetProperty((maze.container.GetChild(i * 15 + j) as ColorRect), "color", maze.mazeColour, 0.3f, tween); } } dstIdx = 3 * 15 + 9; rootIdx = 7 * 15 + 3; tween = CommonTweenUtil.SetProperty((maze.container.GetChild(dstIdx) as ColorRect), "color", maze.dstColour, 0.3f, tween); tween = CommonTweenUtil.SetProperty((maze.container.GetChild(rootIdx) as ColorRect), "color", maze.rootColour, 0.3f, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); for (int i = 1; i < 15 - 1; i++) { for (int j = 1; j < 15 - 1; j++) { maze.SetCell(i * 15 + j, true); } } maze.SetDst(dstIdx); maze.SetRoot(rootIdx); // simulate 2 steps here await ToSignal(this, "next"); maze.AStar(); await ToSignal(maze, "finished"); await ToSignal(this, "next"); maze.ResizeBlock(); for (int i = 1; i < 15 - 1; i++) { for (int j = 1; j < 15 - 1; j++) { tween = CommonTweenUtil.SetProperty((maze.container.GetChild(i * 15 + j) as ColorRect), "color", maze.mazeColour, 0.3f, tween); } } tween.Start(); await ToSignal(tween, "tween_completed"); tween.RemoveAll(); await ToSignal(this, "next"); maze.GenerateMap(); await ToSignal(maze, "finished"); await ToSignal(this, "next"); maze.AStar(); await ToSignal(maze, "finished"); await ToSignal(this, "next"); tween = CommonTweenUtil.Fade(root, 0.3f, 1, 0, tween); tween.Start(); await ToSignal(tween, "tween_completed"); tween.QueueFree(); root.SetVisible(false); EmitSignal("section_finished"); }