private LevelDescriptionGrid2D <RoomWrapper> GetWrappedLevelDescription(LevelDescriptionGrid2D <RoomBase> originalLevelDescription) { var levelDescription = new LevelDescriptionGrid2D <RoomWrapper>(); var srcProperties = originalLevelDescription.GetType().GetProperties( BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty); var dstProperties = levelDescription.GetType().GetProperties( BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty); foreach (var srcProperty in srcProperties) { var dstProperty = dstProperties.First(x => x.Name == srcProperty.Name); if (dstProperty.CanWrite) { dstProperty.SetValue(levelDescription, srcProperty.GetValue(originalLevelDescription)); } } var id = 0; var mapping = originalLevelDescription .GetGraphWithoutCorridors() .Vertices .Select(x => (x, new RoomWrapper(id++, x.GetDisplayName()))) .ToDictionary(x => x.x, x => x.Item2); foreach (var pair in mapping) { levelDescription.AddRoom(pair.Value, originalLevelDescription.GetRoomDescription(pair.Key)); } foreach (var edge in originalLevelDescription.GetGraphWithoutCorridors().Edges) { var from = mapping[edge.From]; var to = mapping[edge.To]; levelDescription.AddConnection(from, to); } return(levelDescription); }
/// <summary> /// Gets the graph of rooms. /// </summary> /// <remarks> /// The graph is not updated when new rooms are added to the level description. /// Adding rooms to the graph does not update the level description. /// This behaviour may change in the future. /// </remarks> /// <returns></returns> public IGraph <RoomBase> GetGraph() { return(levelDescription.GetGraphWithoutCorridors()); }
public Bitmap DrawGraph(LevelDescriptionGrid2D <TRoom> levelDescription, Dictionary <TRoom, Vector2Int> positions, DungeonDrawerOptions options) { var configurations = GetConfigurations(positions); var outlines = configurations.Select(x => x.Outline + x.Position).ToList(); var boundingBox = DrawingUtils.GetBoundingBox(outlines); var(width, height, scale) = DrawingUtils.GetSize(boundingBox, options.Width, options.Height, options.Scale, options.PaddingAbsolute, options.PaddingPercentage); var offset = DrawingUtils.GetOffset(boundingBox, width, height, scale); bitmap = new Bitmap(width, height); graphics = Graphics.FromImage(bitmap); graphics.SmoothingMode = SmoothingMode.HighQuality; using (SolidBrush brush = new SolidBrush(Color.FromArgb(248, 248, 244))) { graphics.FillRectangle(brush, 0, 0, width, height); } var outlinePen = new Pen(Color.FromArgb(50, 50, 50), 0.25f) { EndCap = LineCap.Round, StartCap = LineCap.Round }; var shadePen = new Pen(Color.FromArgb(204, 206, 206), 1.3f) { EndCap = LineCap.Round, StartCap = LineCap.Round }; graphics.TranslateTransform(offset.X, offset.Y); graphics.ScaleTransform(scale, scale); foreach (var configuration in configurations) { DrawShading(GetOutline(configuration.Outline, null, configuration.Position), shadePen); } //var hatchingUsedPoints = new List<Vector2>(); //foreach (var configuration in configurations) //{ // DrawHatching(configuration.Outline + configuration.Position, hatchingUsedPoints, options.HatchingClusterOffset, options.HatchingLength); //} DrawEdges(levelDescription.GetGraphWithoutCorridors(), configurations, outlinePen); foreach (var configuration in configurations) { DrawRoomBackground(configuration.Outline + configuration.Position, options.RoomBackgroundColor); DrawGrid(configuration.Outline + configuration.Position); DrawOutline(configuration.Outline + configuration.Position, GetOutline(configuration.Outline, null, configuration.Position), outlinePen); } foreach (var configuration in configurations) { if (options.ShowRoomNames) { DrawTextOntoPolygon(configuration.Outline + configuration.Position, configuration.Room.ToString(), options.FontSize); } } shadePen.Dispose(); outlinePen.Dispose(); return(bitmap); }