Esempio n. 1
0
 private void ActivateBuffer(ClipboardBuffer item)
 {
     _clipboard.Buffer = item;
     EditPaste();
 }
 public HouseGenTemplate(string name, ClipboardBuffer schematic, HouseGenTemplateData template)
 {
     _schematic = schematic;
     _name      = name;
     _data      = template;
 }
        private bool GenHouse()
        {
            Random rand = new();

            //Select house type
            int houseType    = SelectedTemplate.SelectedIndex;
            var selectedItem = HouseGenTemplates[houseType];

            var templateData      = selectedItem.Template;
            var templateSchematic = selectedItem.Schematic;

            //Retrive buffer size.
            _generatedSchematicSize.X = templateSchematic.Size.X;
            _generatedSchematicSize.Y = templateSchematic.Size.Y / templateData.Count;

            _generatedSchematic = new(_generatedSchematicSize);

            int type;

            // Process Rooms
            for (int i = 0; i < templateData.Rooms.Count; i++)
            {
                type = rand.Next(templateData.Count);

                Room room = templateData.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)templateSchematic.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);
                            return(false);
                        }
                    }
                }
            }

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

            for (int i = 0; i < templateData.Roofs.Count; i++)
            {
                Roof roof = templateData.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)templateSchematic.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);
                            return(false);
                        }
                    }
                }
            }

            byte roofColor = (byte)rand.Next(31);

            //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);
                        return(false);
                    }
                }
            }
            return(true);
        }
            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;
            }
Esempio n. 5
0
 private void RemoveSchematicFile(ClipboardBuffer buffer)
 {
     ClipboardMan.LoadedBuffers.Remove(buffer);
 }