private Node[,] GetGridFromWrapper(ScenarioWrapper scenario) { nodeCount = new Vector2(scenario.Data[0].Length, scenario.Data.Count); Node[,] output = new Node[(int)nodeCount.X, (int)nodeCount.Y]; for (int i = 0; i < nodeCount.X; i++) { for (int j = 0; j < nodeCount.Y; j++) { char nodeType = scenario.Data[j][i]; output[i, j] = GetNewNode(nodeType, i, j); } } if (StartingNode == null || TargetNode == null) { throw new Exception("Scenario does not include starting and/or target positions."); } return(output); }
/// <summary> /// Represents both logical and physical grid. /// </summary> /// <param name="previewData">Information whether this grid should be a preview grid (boolean) and if so, provides appropriate dimensions for scaling</param> /// <param name="nodeSize">Target physical size of a node</param> /// <param name="scenario">Data from which to load the grid</param> public Grid(Tuple <bool, Rectangle> previewData, float nodeSize, ScenarioWrapper scenario) { LoadContent(); this.nodeSize = nodeSize; hoveredNode = new Vector2(-1, -1); nodes = GetGridFromWrapper(scenario); isPreviewMode = previewData.Item1; // Adjust the target dimensions of a screen, depending on whether it's a preview grid or not screenSizeTarget = previewData.Item1 ? new Vector2(previewData.Item2.Width, previewData.Item2.Height) : new Vector2(Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT); ScaleContent(isPreview: previewData.Item1); // Set origin in a way that the grid is centered on-screen. // If it's a preview, add preview offset from previewData. int originX = ((int)screenSizeTarget.X / 2) - ((int)GridSize.X / 2) + (previewData.Item1 ? previewData.Item2.X : 0); int originY = ((int)screenSizeTarget.Y / 2) - ((int)GridSize.Y / 2) + (previewData.Item1 ? previewData.Item2.Y : 0); gridOrigin = new Vector2(originX, originY); }