Esempio n. 1
0
        public void Build_ValidOptions_MapGenerated()
        {
            Mock <IMap> map = new Mock <IMap>(MockBehavior.Strict);

            Mock <IMapTerrainGenerator> terrainGenerator = new Mock <IMapTerrainGenerator>(MockBehavior.Strict);

            terrainGenerator
            .Setup(g => g.Initialize(ref It.Ref <MapCell> .IsAny));
            terrainGenerator
            .Setup(g => g.Build(map.Object));

            Mock <IMapFactory> mapFactory = new Mock <IMapFactory>(MockBehavior.Strict);

            mapFactory
            .Setup(f => f.Create(100, 100, terrainGenerator.Object.Initialize))
            .Returns(map.Object);

            MapGeneratorOptions options = new MapGeneratorOptions(
                100,
                100
                );

            IMapGenerator generator   = new MapGenerator(mapFactory.Object);
            IMap          returnedMap = default;

            using (var gate = new AutoResetEvent(false)) {
                generator.Build(options, terrainGenerator.Object, (string message) => { }, ( IMap newMap ) => returnedMap = newMap);
                gate.WaitOne(1000);                   // Bail after one second just in case.
            }

            Assert.AreSame(returnedMap, map.Object);
        }
        protected void FinishGeneration()
        {
            if (InvokeRequired) {
                Invoke(new Action(FinishGeneration), new object[] {});
                return;
            }

            mapHtmlPath = Path.Combine(options.OutputDirectory, "Map.html");

            workerThread = null;
            progressHandler = null;
            options = null;

            elapsedTimer.Enabled = false;

            cancelButton.Visible = false;
            closeButton.Visible = true;
            openMapButton.Visible = true;

            overallProgressBar.Value = overallProgressBar.Maximum;
            subTaskProgressBar.Value = subTaskProgressBar.Maximum;
            subTaskLabel.Text = "Done";

            SystemSounds.Beep.Play();

            OnGenerationDone(EventArgs.Empty);
        }
        public MapGenerator(MapGeneratorOptions options)
        {
            if (options == null) {
                throw new ArgumentNullException("options");
            }

            this.options = options;
        }
        public void Generate(MapGeneratorOptions options)
        {
            if (workerThread != null) {
                throw new InvalidOperationException("Map generation already in progress.");
            }

            if (options == null) {
                throw new ArgumentNullException("options");
            }

            this.options = options;
            this.startTime = DateTime.Now;

            elapsedTimer.Enabled = true;

            progressHandler = new GuiMapGeneratorProgressHandler(this);

            workerThread = new Thread(new ThreadStart(GenerateWorker));
            workerThread.Start();
        }
        private void LoadSettings()
        {
            string rulesFiles = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "TerrariaMapGenerator.xml");

            if (File.Exists(rulesFiles)) {
                XmlSerializer deserializer = new XmlSerializer(typeof(MapGeneratorOptions));

                using (TextReader textReader = new StreamReader(rulesFiles)) {
                    Options = (MapGeneratorOptions) deserializer.Deserialize(textReader);
                }
            }
        }
Esempio n. 6
0
        private static void DrawMenu()
        {
            // DRAW MENU
            TypewriterText("Create your own Game Builder world with this tool!");
            TypewriterText("What kind of map would you like to create?", autoPauseAtEnd: 0);
            TypewriterText("------------------------------------------", autoPauseAtEnd: 0);
            TypewriterText("1. Default", autoPauseAtEnd: 0);
            TypewriterText("2. Custom", autoPauseAtEnd: 0);
            TypewriterText("3. Exit", autoPauseAtEnd: 0);
            TypewriterText("> ", newlines: 0, autoPauseAtEnd: 0);

            string line   = string.Empty;
            string choice = Console.ReadLine();

            if (line.Contains("3", StringComparison.OrdinalIgnoreCase))
            {
                Environment.Exit(0);
            }
            TypewriterText("", 2, autoPauseAtEnd: 0);
            TypewriterText("(To choose any default values, simply hit 'Enter')", autoPauseAtEnd: 0);

            // GET MAP GEN OPTIONS
            int    itemp;
            float  ftemp;
            double dtemp;

            try
            {
                ProgramOptions programOptions         = new ProgramOptions();
                string         programOptionsString   = string.Empty;
                string         programOptionsFilepath = Path.Combine(Directory.GetCurrentDirectory(), ProgramOptions.FILENAME);
                if (File.Exists(programOptionsFilepath))
                {
                    using (StreamReader streamReader = new StreamReader(Path.Combine(Directory.GetCurrentDirectory(), ProgramOptions.FILENAME)))
                    {
                        programOptionsString = streamReader.ReadToEnd();
                    }
                    programOptions = JsonConvert.DeserializeObject <ProgramOptions>(programOptionsString);
                }


                int width  = (programOptions != null && programOptions.Width != default(int)) ? programOptions.Width : 250; // in .voos units
                int length = (programOptions != null && programOptions.Length != default(int)) ? programOptions.Length : 250;
                MapGeneratorOptions mapOptions = new MapGeneratorOptions();
                string mapName         = $"CustomMap-{DateTime.Now.ToString("MM_dd_yyyy hh_mm tt")}";
                string mapDesc         = string.Empty;
                string outputDirectory = Romans828 ? @"D:\Program Files (x86)\Steam\steamapps\common\Game Builder\GameBuilderUserData\Games" : (programOptions != null && !string.IsNullOrEmpty(programOptions.SaveTo)) ? programOptions.SaveTo : Directory.GetCurrentDirectory();


                TypewriterText($"How wide would you like your map to be [{width}=DEFAULT])? > ", newlines: 0, autoPauseAtEnd: 0);
                line = Console.ReadLine();
                if (int.TryParse(line, out itemp))
                {
                    width = itemp;
                }

                TypewriterText($"How deep would you like your map to be [{length}=DEFAULT])? > ", newlines: 0, autoPauseAtEnd: 0);
                line = Console.ReadLine();
                if (int.TryParse(line, out itemp))
                {
                    length = itemp;
                }

                TypewriterText($"Would you like to give your map a name ['{mapName}'=DEFAULT])? > ", newlines: 0, autoPauseAtEnd: 0);
                line = Console.ReadLine();
                if (!string.IsNullOrEmpty(line))
                {
                    mapName = line;
                }

                TypewriterText($"Would you like to give your map a description? > ", newlines: 0, autoPauseAtEnd: 0);
                line = Console.ReadLine();
                if (!string.IsNullOrEmpty(line))
                {
                    mapDesc = line;
                }

                TypewriterText($"Where would you like us to save your map ['{outputDirectory}'=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                line = Console.ReadLine();
                if (!string.IsNullOrEmpty(line))
                {
                    outputDirectory = line;
                }

                string[] biomeNames = mapOptions.BiomeNames();
                for (int i = 0; i < biomeNames.Length; i++)
                {
                    biomeNames[i] = $"'{biomeNames[i][0]}'{biomeNames[i].Substring(1)}={Enum.Parse(mapOptions.Biome.GetType(), biomeNames[i])}";
                }
                TypewriterText($"What would you like your biome to be [{mapOptions.EnumName(mapOptions.Biome)}=DEFAULT ({string.Join(',', biomeNames)})]? > ", newlines: 0, autoPauseAtEnd: 0);
                line = Console.ReadLine();

                if (!string.IsNullOrEmpty(line))
                {
                    if (line.Contains("g", StringComparison.OrdinalIgnoreCase))
                    {
                        mapOptions.Biome = MapGeneratorOptions.MapBiome.Grassland;
                    }
                    else if (line.Contains("d", StringComparison.OrdinalIgnoreCase))
                    {
                        mapOptions.Biome = MapGeneratorOptions.MapBiome.Desert;
                    }
                    else if (line.Contains("t", StringComparison.OrdinalIgnoreCase))
                    {
                        mapOptions.Biome = MapGeneratorOptions.MapBiome.Tundra;
                    }
                }

                if (choice.Contains("2", StringComparison.OrdinalIgnoreCase))
                {
                    TypewriterText($"What would you like your plain frequency to be [{mapOptions.PlainFrequency}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                    line = Console.ReadLine();

                    if (!string.IsNullOrEmpty(line))
                    {
                        if (float.TryParse(line, out ftemp))
                        {
                            mapOptions.PlainFrequency = ftemp;
                        }
                    }

                    // Trees (actors)
                    TypewriterText($"Would you like trees in your map [{mapOptions.Actors}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                    line = Console.ReadLine();
                    if (!string.IsNullOrEmpty(line))
                    {
                        if (line.Contains("1") || line.Contains("t", StringComparison.OrdinalIgnoreCase) || line.Contains("y", StringComparison.OrdinalIgnoreCase))
                        {
                            mapOptions.Actors = true;
                        }
                        else
                        {
                            mapOptions.Actors = false;
                        }
                    }

                    // Lakes
                    TypewriterText($"Would you like lakes [{mapOptions.Lakes}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                    line = Console.ReadLine();

                    if (!string.IsNullOrEmpty(line))
                    {
                        if (line.Contains("1") || line.Contains("t", StringComparison.OrdinalIgnoreCase) || line.Contains("y", StringComparison.OrdinalIgnoreCase))
                        {
                            mapOptions.Lakes = true;
                        }
                        else
                        {
                            mapOptions.Lakes = false;
                        }
                    }

                    if (mapOptions.Lakes)
                    {
                        TypewriterText($"What would you like your lake frequency to be [{mapOptions.LakeFrequency}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (float.TryParse(line, out ftemp))
                            {
                                mapOptions.LakeFrequency = ftemp;
                            }
                        }

                        TypewriterText($"What would you like your lake size to be [{mapOptions.LakeSize}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (int.TryParse(line, out itemp))
                            {
                                mapOptions.LakeSize = itemp;
                            }
                        }
                    }

                    // Hills
                    TypewriterText($"Would you like hills [{mapOptions.Hills}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                    line = Console.ReadLine();

                    if (!string.IsNullOrEmpty(line))
                    {
                        if (line.Contains("1") || line.Contains("t", StringComparison.OrdinalIgnoreCase) || line.Contains("y", StringComparison.OrdinalIgnoreCase))
                        {
                            mapOptions.Hills = true;
                        }
                        else
                        {
                            mapOptions.Hills = false;
                        }
                    }

                    if (mapOptions.Hills)
                    {
                        TypewriterText($"What would you like your hill frequency to be [{mapOptions.HillFrequency}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (float.TryParse(line, out ftemp))
                            {
                                mapOptions.HillFrequency = ftemp;
                            }
                        }

                        TypewriterText($"What would you like your hill clamp to be [{mapOptions.HillClamp}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (int.TryParse(line, out itemp))
                            {
                                mapOptions.HillClamp = itemp;
                            }
                        }
                    }

                    // Mountains
                    TypewriterText($"Would you like mountains [{mapOptions.Mountains}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                    line = Console.ReadLine();

                    if (!string.IsNullOrEmpty(line))
                    {
                        if (line.Contains("1") || line.Contains("t", StringComparison.OrdinalIgnoreCase) || line.Contains("y", StringComparison.OrdinalIgnoreCase))
                        {
                            mapOptions.Mountains = true;
                        }
                        else
                        {
                            mapOptions.Mountains = false;
                        }
                    }

                    if (mapOptions.Mountains)
                    {
                        TypewriterText($"What would you like your mountain frequency to be [{mapOptions.MountainFrequency}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (float.TryParse(line, out ftemp))
                            {
                                mapOptions.MountainFrequency = ftemp;
                            }
                        }

                        TypewriterText($"What would you like your additional mountain size to be [{mapOptions.AdditionalMountainSize}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (double.TryParse(line, out dtemp))
                            {
                                mapOptions.AdditionalMountainSize = dtemp;
                            }
                        }
                    }

                    // Caves
                    TypewriterText($"Would you like caves [{mapOptions.Caves}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                    line = Console.ReadLine();

                    if (!string.IsNullOrEmpty(line))
                    {
                        if (line.Contains("1") || line.Contains("t", StringComparison.OrdinalIgnoreCase) || line.Contains("y", StringComparison.OrdinalIgnoreCase))
                        {
                            mapOptions.Caves = true;
                        }
                        else
                        {
                            mapOptions.Caves = false;
                        }
                    }

                    if (mapOptions.Caves)
                    {
                        TypewriterText($"What would you like your additional cave height to be [{mapOptions.AdditionalCaveHeight}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (int.TryParse(line, out itemp))
                            {
                                mapOptions.AdditionalCaveHeight = itemp;
                            }
                        }
                    }

                    // Tunnels
                    TypewriterText($"Would you like tunnels [{mapOptions.Tunnels}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                    line = Console.ReadLine();

                    if (!string.IsNullOrEmpty(line))
                    {
                        if (line.Contains("1") || line.Contains("t", StringComparison.OrdinalIgnoreCase) || line.Contains("y", StringComparison.OrdinalIgnoreCase))
                        {
                            mapOptions.Tunnels = true;
                        }
                        else
                        {
                            mapOptions.Tunnels = false;
                        }
                    }

                    if (mapOptions.Tunnels)
                    {
                        TypewriterText($"What is the maximum number of tunnels that you'd like [{mapOptions.TunnelWormsMax}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (int.TryParse(line, out itemp))
                            {
                                mapOptions.TunnelWormsMax = itemp;
                            }
                        }

                        TypewriterText($"What radius would you like your tunnels [{mapOptions.TunnelRadius}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (int.TryParse(line, out itemp))
                            {
                                mapOptions.TunnelRadius = itemp;
                            }
                        }

                        TypewriterText($"How long would you like your tunnels [{mapOptions.TunnelLength}=DEFAULT]? > ", newlines: 0, autoPauseAtEnd: 0);
                        line = Console.ReadLine();

                        if (!string.IsNullOrEmpty(line))
                        {
                            if (int.TryParse(line, out itemp))
                            {
                                mapOptions.TunnelLength = itemp;
                            }
                        }
                    }
                }

                TypewriterText("", 2);

                if (string.IsNullOrEmpty(mapDesc))
                {
                    mapDesc = $"Map specs => ({width}x{length}) {mapOptions.ToString()} -Built with love by Romans 8:28.";
                }

                // CREATE MAP
                // convert back to proper unit
                width  = (int)Math.Floor(width / 2.5d);
                length = (int)Math.Floor(length / 2.5d);
                BaseGenerator <short> generator = new MapGenerator((short)width, (short)length, 1, mapOptions);
                Map           map           = (Map)generator.GenerateMap();
                VoosGenerator voosGenerator = new VoosGenerator();
                voosGenerator.Generate(map, outputDirectory, mapName, mapDesc);

                TypewriterText("");
            }
            catch (Exception ex)
            {
                TypewriterText("Oops! An error occurred.", autoPauseAtEnd: 0);
                TypewriterText("Please send an entire copy of your console window to Romans 8:28 on the discord server to debug and fix this.", newlines: 2, autoPauseAtEnd: 0);
                TypewriterText($"{ex.Message}", autoPauseAtEnd: 0);
                TypewriterText($"{ex.StackTrace}", autoPauseAtEnd: 0);

                Console.ReadKey();
                Environment.Exit(0);
            }

            TypewriterText("Your map was successfully created!");
            TypewriterText("Have a nice day!");
            TypewriterText("");
            TypewriterText("Press any key to exit...");
            Console.ReadKey();
            Environment.Exit(0);
        }