private void Generate(HouseGenTemplate template)
            {
                //Retrive buffer size.
                _generatedSchematicSize.X = template.Schematic.Size.X;
                _generatedSchematicSize.Y = template.Schematic.Size.Y / template.Data.Count;

                _generatedSchematic = new(_generatedSchematicSize);

                int type;

                // Process Rooms
                for (int i = 0; i < template.Data.Rooms.Count; i++)
                {
                    type = _rand.Next(template.Data.Count);

                    Room room = template.Data.Rooms[i];

                    for (int x = 0; x < room.Width; x++)
                    {
                        for (int y = 0; y < room.Height; y++)
                        {
                            try
                            {
                                _generatedSchematic.Tiles[x + room.X, y + room.Y] =
                                    (Tile)template.Schematic.Tiles[x + room.X, y + room.Y + (_generatedSchematicSize.Y * type)].Clone();
                            }
                            catch (IndexOutOfRangeException e)
                            {
                                MessageBox.Show(e.Message + " Check JSON Data for " + room.Name, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        }
                    }
                }

                // Process Roofs
                // Generate the random roof value once for the whole "building"
                type = _rand.Next(template.Data.Count);

                for (int i = 0; i < template.Data.Roofs.Count; i++)
                {
                    Roof roof = template.Data.Roofs[i];

                    for (int x = 0; x < roof.Width; x++)
                    {
                        for (int y = 0; y < roof.Height; y++)
                        {
                            try
                            {
                                _generatedSchematic.Tiles[x + roof.X, y + roof.Y] =
                                    (Tile)template.Schematic.Tiles[x + roof.X, y + roof.Y + (_generatedSchematicSize.Y * type)].Clone();
                            }
                            catch (IndexOutOfRangeException e)
                            {
                                MessageBox.Show(e.Message + " Check JSON Data for " + roof.Name, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        }
                    }
                }

                //Fill in any empty space of schematic outside of room definintions (empty space within bounds of roof or room should already be filled)
                for (int x2 = 0; x2 < _generatedSchematicSize.X; x2++)
                {
                    for (int y2 = 0; y2 < _generatedSchematicSize.Y; y2++)
                    {
                        try
                        {
                            if (_generatedSchematic.Tiles[x2, y2] == null)
                            {
                                _generatedSchematic.Tiles[x2, y2] = new Tile();
                            }
                        }
                        catch (IndexOutOfRangeException e)
                        {
                            MessageBox.Show(e.Message + " Check JSON Data for value 'Count' to make sure it matches with associated schematic.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                }

                _generatedSchematic.RenderBuffer();
                Preview = _generatedSchematic.Preview;
            }
 private void UpdatePreview()
 {
     _generatedSchematic.RenderBuffer();
     PreviewImage.Source = _generatedSchematic.Preview;
 }