public void Run() { var levelDescription = GetLevelDescription(); var generator = new GraphBasedGeneratorGrid2D <int>(levelDescription); var layout = generator.GenerateLayout(); var drawer = new DungeonDrawer <int>(); var bitmap = drawer.DrawLayout(layout, new DungeonDrawerOptions() { Height = 1000, Width = 1000, }); bitmap.Save("minimum_room_distance.png"); }
/// <summary> /// Run the generator and export the result. /// </summary> public void Run() { var levelDescription = GetLevelDescription(); var generator = new GraphBasedGeneratorGrid2D <int>(levelDescription); var layout = generator.GenerateLayout(); var drawer = new DungeonDrawer <int>(); var bitmap = drawer.DrawLayout(layout, new DungeonDrawerOptions() { Width = 1000, Height = 1000, }); bitmap.Save("corridors.png"); #region no-clean var roomTemplates = levelDescription .GetGraph().Vertices .Select(levelDescription.GetRoomDescription) .Where(x => x.IsCorridor) .SelectMany(x => x.RoomTemplates) .Distinct() .ToList(); var roomTemplatesDrawer = new RoomTemplateDrawer(); var roomTemplatesBitmap = roomTemplatesDrawer.DrawRoomTemplates(roomTemplates, new DungeonDrawerOptions() { Width = 1200, Height = 350, FontSize = 0.7f, PaddingAbsolute = 135, ShowRoomNames = false, EnableHatching = false, }); roomTemplatesBitmap.Save(ExamplesGenerator.AssetsFolder + "/room_templates.png"); #endregion }
private void mainPictureBox_Paint(object sender, PaintEventArgs e) { if (layoutToDraw == null) { return; } if (exportShownLayoutsCheckbox.Checked) { DumpSvg(); } UpdateLayoutType(); var showNames = showRoomNamesCheckbox.Checked; var useOldPaperStyle = useOldPaperStyleCheckbox.Checked; var fixedFontSize = fixedFontSizeCheckbox.Checked ? (int?)fixedFontSizeValue.Value : null; if (firstChainToDraw == null) { firstChainToDraw = layoutToDraw; RecomputeFixedScaleAndOffset(); } else { var previousRoomsCount = firstChainToDraw.Rooms.Count(); var currentRoomsCount = layoutToDraw.Rooms.Count(); if (previousRoomsCount == currentRoomsCount) { firstChainToDraw = layoutToDraw; RecomputeFixedScaleAndOffset(); } } if (useOldPaperStyle) { //var bitmap = oldMapDrawer.DrawLayout(layoutToDraw, mainPictureBox.Width, mainPictureBox.Height, showNames, fixedFontSize); //e.Graphics.DrawImage(bitmap, new Point(0, 0)); throw new NotSupportedException(); } else { //Bitmap bitmap; //if (fixedPositionsAndScaleCheckbox.Checked) //{ // bitmap = wfLayoutDrawer.DrawLayout(layoutToDraw, mainPictureBox.Width, mainPictureBox.Height, showNames, fixedFontSize, fixedScale, fixedOffset); //} //else //{ // bitmap = wfLayoutDrawer.DrawLayout(layoutToDraw, mainPictureBox.Width, mainPictureBox.Height, showNames, fixedFontSize); //} var layoutDrawer = new DungeonDrawer <int>(); var bitmap = layoutDrawer.DrawLayout(layoutToDraw, new DungeonDrawerOptions() { Width = mainPictureBox.Width, Height = mainPictureBox.Height, ShowRoomNames = showNames, PaddingPercentage = 0.05f, EnableHatching = true, }); // e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.DrawImage(bitmap, new Point(0, 0)); } }
private void AddResults <TRoom>(StringBuilder output, IExampleGrid2D <TRoom> example) { var sourceCode = sourceCodeParser.GetMethod("GetResults", false); var results = example.GetResults().ToList(); var codeBlockHandler = new CodeBlockHandler(output); output.AppendLine("## Results"); output.AppendLine(); var resultsCounter = 0; foreach (var line in sourceCode) { var trimmed = line.Trim(); if (trimmed.StartsWith("//md")) { codeBlockHandler.Exit(); if (trimmed.Length > 5) { trimmed = trimmed.Remove(0, 5); } else { trimmed = trimmed.Remove(0, 4); } output.AppendLine(trimmed); } else if (trimmed.Contains("yield") && !trimmed.Contains("yield break")) { codeBlockHandler.Exit(); var levelDescription = results[resultsCounter]; var initStopwatch = new Stopwatch(); initStopwatch.Start(); var generator = new GraphBasedGeneratorGrid2D <TRoom>(levelDescription); generator.InjectRandomGenerator(new Random(0)); initStopwatch.Stop(); var layoutDrawer = new GraphBasedGenerator.Grid2D.Drawing.SVGLayoutDrawer <TRoom>(); var oldMapDrawer = new DungeonDrawer <TRoom>(); var times = new List <long>(); for (int i = 0; i < 4; i++) { var generatorStopwatch = new Stopwatch(); generatorStopwatch.Start(); var level = generator.GenerateLayout(); generatorStopwatch.Stop(); times.Add(generatorStopwatch.ElapsedMilliseconds); Console.WriteLine(generatorStopwatch.ElapsedMilliseconds + initStopwatch.ElapsedMilliseconds); var svg = layoutDrawer.DrawLayout(level, 800, forceSquare: true, flipY: true, fixedFontSize: 30); File.WriteAllText(Path.Combine(AssetsFolder, $"{resultsCounter}_{i}.svg"), svg); var bitmap = oldMapDrawer.DrawLayout(level, new DungeonDrawerOptions() { Width = 2000, Height = 2000, PaddingPercentage = 0.1f, }); bitmap.Save(Path.Combine(AssetsFolder, $"{resultsCounter}_{i}.png")); } var summaryDrawer = new GeneratorSummaryDrawer <TRoom>(); var summary = summaryDrawer.Draw(levelDescription, 5000, generator); summary.Save(Path.Combine(AssetsFolder, $"{resultsCounter}_summary.png")); output.AppendLine(); output.AppendLine("<Gallery cols={2}>"); for (int i = 0; i < 4; i++) { output.AppendLine( $"<GalleryImage src={{require('./{example.Options.DocsFileName}/{resultsCounter}_{i}.png').default}} />"); } output.AppendLine("</Gallery>"); output.AppendLine(); output.AppendLine("<div style={{ textAlign: 'center', marginTop: '-15px' }}>"); output.AppendLine(); output.AppendLine($"*Average time to generate the level: {((times.Average() + initStopwatch.ElapsedMilliseconds) / 1000).ToString("F", CultureInfo.InvariantCulture)}s ({((initStopwatch.ElapsedMilliseconds) / 1000d).ToString("F", CultureInfo.InvariantCulture)}s init, {((times.Average()) / 1000).ToString("F", CultureInfo.InvariantCulture)}s generation itself)*"); output.AppendLine(); output.AppendLine("</div>"); output.AppendLine(); resultsCounter++; } else if (codeBlockHandler.IsInside) { output.AppendLine(line); } else if (!string.IsNullOrEmpty(trimmed)) { codeBlockHandler.Enter(); output.AppendLine(line); } else { output.AppendLine(); } } codeBlockHandler.Exit(); }