public MapGridCellViewModel(MapTerrainEntry entry, int x, int y, MapRenderMode renderMode, IGimmickService gimmickService, IOverrideSpriteProvider spriteProvider) { _gimmickService = gimmickService; _spriteProvider = spriteProvider; TerrainEntry = entry; X = x; Y = y; SubCell0 = new(this, 0, renderMode); SubCell1 = new(this, 1, renderMode); SubCell2 = new(this, 2, renderMode); SubCell3 = new(this, 3, renderMode); SubCell4 = new(this, 4, renderMode); SubCell5 = new(this, 5, renderMode); SubCell6 = new(this, 6, renderMode); SubCell7 = new(this, 7, renderMode); SubCell8 = new(this, 8, renderMode); }
public MapGridSubCellViewModel(MapGridCellViewModel parent, int entryId, MapRenderMode renderMode) { _entryId = entryId; Parent = parent; RenderMode = renderMode; }
/// <summary> /// Renders a map from a single z,y plane /// </summary> /// <param name="map">The map to render</param> /// <param name="forAdmin">is this for admin (with edit links)</param> /// <param name="withPathways">include pathway symbols</param> /// <param name="centerRoom">the room considered "center"</param> /// <returns>the rendered map</returns> public static string RenderMap(string[,] map, bool visibileOnly, bool forAdmin, bool withPathways, IRoom centerRoom, MapRenderMode renderMode = MapRenderMode.Normal) { StringBuilder sb = new StringBuilder(); if (!withPathways) { int x, y; for (y = map.GetUpperBound(1); y >= 0; y--) { string rowString = string.Empty; for (x = 0; x < map.GetUpperBound(0); x++) { IRoom Room = LiveCache.Get <IRoom>(new LiveCacheKey(typeof(IRoom), map[x, y])); if (Room != null) { rowString += RenderRoomToAscii(Room, Room.GetPathways().Any(), Room.GetLocalePathways().Any(), !forAdmin && Room.BirthMark == centerRoom.BirthMark, forAdmin); } else { rowString += " "; } } if (!string.IsNullOrWhiteSpace(rowString.Replace(" ", ""))) { sb.AppendLine(rowString); } } } else { string[,] expandedMap = new string[(map.GetUpperBound(0) + 1) * 3 + 1, (map.GetUpperBound(1) + 1) * 3 + 1]; int x, y; int xMax = 0; for (y = map.GetUpperBound(1); y >= 0; y--) { for (x = 0; x <= map.GetUpperBound(0); x++) { IRoom Room = LiveCache.Get <IRoom>(new LiveCacheKey(typeof(IRoom), map[x, y])); if (Room != null) { if (x > xMax) { xMax = x; } expandedMap = RenderRoomAndPathwaysForMapNode(x, y, Room, centerRoom, expandedMap, Room.BirthMark == centerRoom.BirthMark, forAdmin, renderMode); } } } //3 for inflation if (withPathways) { xMax += 3; } for (y = expandedMap.GetUpperBound(1); y >= 0; y--) { string rowString = string.Empty; for (x = 0; x <= expandedMap.GetUpperBound(0); x++) { string xString = expandedMap[x, y]; if (string.IsNullOrWhiteSpace(xString)) { if (!forAdmin || x <= xMax) { rowString += " "; } } else { rowString += expandedMap[x, y]; } } if (!string.IsNullOrWhiteSpace(rowString.Replace(" ", ""))) { sb.AppendLine(rowString); } } } return(sb.ToString()); }
private static string[,] RenderRoomAndPathwaysForMapNode(int x, int y, IRoomTemplate RoomTemplate, IRoomTemplate centerRoom, string[,] expandedMap, bool currentRoom, bool forAdmin, MapRenderMode renderMode) { IEnumerable <IPathwayTemplate> pathways = RoomTemplate.GetPathways(); int expandedRoomX = x * 3 + 1; int expandedRoomY = y * 3 + 1; switch (renderMode) { case MapRenderMode.Normal: IPathwayTemplate ePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.East); IPathwayTemplate nPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.North); IPathwayTemplate nePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.NorthEast); IPathwayTemplate nwPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.NorthWest); IPathwayTemplate sPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.South); IPathwayTemplate sePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.SouthEast); IPathwayTemplate swPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.SouthWest); IPathwayTemplate wPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.West); //The room expandedMap[expandedRoomX, expandedRoomY] = RenderRoomToAscii(RoomTemplate, RoomTemplate.GetZonePathways().Any(), RoomTemplate.GetLocalePathways().Any() , !forAdmin && currentRoom, forAdmin); expandedMap[expandedRoomX - 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(nwPath, RoomTemplate.Id, MovementDirectionType.NorthWest, forAdmin); expandedMap[expandedRoomX, expandedRoomY + 1] = RenderPathwayToAsciiForModals(nPath, RoomTemplate.Id, MovementDirectionType.North, forAdmin); expandedMap[expandedRoomX + 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(nePath, RoomTemplate.Id, MovementDirectionType.NorthEast, forAdmin); expandedMap[expandedRoomX - 1, expandedRoomY] = RenderPathwayToAsciiForModals(wPath, RoomTemplate.Id, MovementDirectionType.West, forAdmin); expandedMap[expandedRoomX + 1, expandedRoomY] = RenderPathwayToAsciiForModals(ePath, RoomTemplate.Id, MovementDirectionType.East, forAdmin); expandedMap[expandedRoomX - 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(swPath, RoomTemplate.Id, MovementDirectionType.SouthWest, forAdmin); expandedMap[expandedRoomX, expandedRoomY - 1] = RenderPathwayToAsciiForModals(sPath, RoomTemplate.Id, MovementDirectionType.South, forAdmin); expandedMap[expandedRoomX + 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(sePath, RoomTemplate.Id, MovementDirectionType.SouthEast, forAdmin); break; case MapRenderMode.Upwards: IPathwayTemplate upPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.Up); IPathwayTemplate upePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpEast); IPathwayTemplate upnPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpNorth); IPathwayTemplate upnePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpNorthEast); IPathwayTemplate upnwPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpNorthWest); IPathwayTemplate upsPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpSouth); IPathwayTemplate upsePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpSouthEast); IPathwayTemplate upswPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpSouthWest); IPathwayTemplate upwPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpWest); expandedMap[expandedRoomX, expandedRoomY] = RenderPathwayToAsciiForModals(upPath, RoomTemplate.Id, MovementDirectionType.Up, forAdmin); expandedMap[expandedRoomX - 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(upnwPath, RoomTemplate.Id, MovementDirectionType.UpNorthWest, forAdmin); expandedMap[expandedRoomX, expandedRoomY + 1] = RenderPathwayToAsciiForModals(upnPath, RoomTemplate.Id, MovementDirectionType.UpNorth, forAdmin); expandedMap[expandedRoomX + 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(upnePath, RoomTemplate.Id, MovementDirectionType.UpNorthEast, forAdmin); expandedMap[expandedRoomX - 1, expandedRoomY] = RenderPathwayToAsciiForModals(upwPath, RoomTemplate.Id, MovementDirectionType.UpWest, forAdmin); expandedMap[expandedRoomX + 1, expandedRoomY] = RenderPathwayToAsciiForModals(upePath, RoomTemplate.Id, MovementDirectionType.UpEast, forAdmin); expandedMap[expandedRoomX - 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(upswPath, RoomTemplate.Id, MovementDirectionType.UpSouthWest, forAdmin); expandedMap[expandedRoomX, expandedRoomY - 1] = RenderPathwayToAsciiForModals(upsPath, RoomTemplate.Id, MovementDirectionType.UpSouth, forAdmin); expandedMap[expandedRoomX + 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(upsePath, RoomTemplate.Id, MovementDirectionType.UpSouthEast, forAdmin); break; case MapRenderMode.Downwards: IPathwayTemplate downPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.Down); IPathwayTemplate downePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownEast); IPathwayTemplate downnPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownNorth); IPathwayTemplate downnePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownNorthEast); IPathwayTemplate downnwPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownNorthWest); IPathwayTemplate downsPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownSouth); IPathwayTemplate downsePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownSouthEast); IPathwayTemplate downswPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownSouthWest); IPathwayTemplate downwPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownWest); expandedMap[expandedRoomX, expandedRoomY] = RenderPathwayToAsciiForModals(downPath, RoomTemplate.Id, MovementDirectionType.Down, forAdmin); expandedMap[expandedRoomX - 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(downnwPath, RoomTemplate.Id, MovementDirectionType.DownNorthWest, forAdmin); expandedMap[expandedRoomX, expandedRoomY + 1] = RenderPathwayToAsciiForModals(downnPath, RoomTemplate.Id, MovementDirectionType.DownNorth, forAdmin); expandedMap[expandedRoomX + 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(downnePath, RoomTemplate.Id, MovementDirectionType.DownNorthEast, forAdmin); expandedMap[expandedRoomX - 1, expandedRoomY] = RenderPathwayToAsciiForModals(downwPath, RoomTemplate.Id, MovementDirectionType.DownWest, forAdmin); expandedMap[expandedRoomX + 1, expandedRoomY] = RenderPathwayToAsciiForModals(downePath, RoomTemplate.Id, MovementDirectionType.DownEast, forAdmin); expandedMap[expandedRoomX - 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(downswPath, RoomTemplate.Id, MovementDirectionType.DownSouthWest, forAdmin); expandedMap[expandedRoomX, expandedRoomY - 1] = RenderPathwayToAsciiForModals(downsPath, RoomTemplate.Id, MovementDirectionType.DownSouth, forAdmin); expandedMap[expandedRoomX + 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(downsePath, RoomTemplate.Id, MovementDirectionType.DownSouthEast, forAdmin); break; } return(expandedMap); }
/// <summary> /// Render an ascii map of stored data rooms around a specific radius /// </summary> /// <param name="room">the room to render the radius around</param> /// <param name="radius">the radius around the room to render</param> /// <param name="forAdmin">include edit links for paths and rooms?</param> /// <param name="withPathways">include paths at all?</param> /// <returns>a single string that is an ascii map</returns> public static string RenderRadiusMap(IRoom room, int radius, bool visibleOnly = false, bool forAdmin = true, bool withPathways = true, ILocale locale = null, MapRenderMode renderMode = MapRenderMode.Normal) { StringBuilder asciiMap = new StringBuilder(); //Why? if (room == null) { //Don't show "add room" to non admins, if we're not requesting this for a locale and if the locale has actual rooms if (!forAdmin || locale == null || locale.Rooms().Count() > 0) { return(string.Empty); } return(string.Format("<a href='#' class='addData pathway AdminAddInitialRoom' localeId='{0}' title='New Room'>Add Initial Room</a>", locale.BirthMark)); } //1. Get world map ILocale ourLocale = room.ParentLocation; //2. Get slice of room from world map string[,,] map = Cartographer.TakeSliceOfMap(new Tuple <int, int>(Math.Max(room.Coordinates.X - radius, 0), room.Coordinates.X + radius) , new Tuple <int, int>(Math.Max(room.Coordinates.Y - radius, 0), room.Coordinates.Y + radius) , new Tuple <int, int>(Math.Max(room.Coordinates.Z - 1, 0), room.Coordinates.Z + 1) , ourLocale.Interior.CoordinatePlane, true); //3. Flatten the map string[,] flattenedMap = Cartographer.GetSinglePlane(map, room.Coordinates.Z); //4. Render slice of room return(RenderMap(flattenedMap, visibleOnly, forAdmin, withPathways, room, renderMode)); }