#pragma warning restore 0649 public static BlueprintTile Null() { var nullTile = new BlueprintTile { Glyph = ' ', Foreground = "BurlyWood", Background = "Black", Name = null, Walkable = false }; return(nullTile); }
private void AddStairsLogic(T cell, BlueprintTile tile) { string stairsName = tile.Name.Equals("Stairs Up", StringComparison.OrdinalIgnoreCase) ? "Stairs Down" : "Stairs Up"; Blueprint <T> blueprint = tile.Name.Equals("Stairs Up", StringComparison.OrdinalIgnoreCase) ? StairsUpBlueprint : StairsDownBlueprint; // Initialize new blueprint with tracking of the previous GridManager.InitializeBlueprint(blueprint, true); // Make sure all entities are synced to correct blueprint EntityManager.MovePlayerToBlueprint(blueprint); // Move player var stairs = GridManager.Grid.GetCells(a => a.CellProperties.Name != null && a.CellProperties.Name.Equals(stairsName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (stairs == null) { throw new Exception($"[{GetType().Name}] No {stairsName} available for {tile.Name} at position: {cell.Position}"); } GridManager.Grid.RenderObject(UserInterfaceManager.Get <MapWindow>()); Game.Player.MoveTowards(stairs.Position, false, null, false); Game.Player.Initialize(false); }
/// <summary> /// Retrieves the cells from the blueprint.txt file and blueprint.json config file. /// Cells are not cached by default. /// </summary> /// <returns></returns> public T[] GetCells() { var name = GetType().Name; var blueprintPath = Path.Combine(BlueprintPath, name + ".txt"); var blueprintConfigPath = Path.Combine(Constants.Blueprint.BlueprintsConfigPath, Constants.Blueprint.BlueprintTiles + ".json"); if (!File.Exists(blueprintPath) || !File.Exists(blueprintConfigPath) || !File.Exists(Constants.Blueprint.SpecialCharactersPath)) { return(Array.Empty <T>()); } var specialConfig = JsonConvert.DeserializeObject <BlueprintConfig>(File.ReadAllText(Constants.Blueprint.SpecialCharactersPath)); var specialChars = specialConfig.Tiles.ToDictionary(a => a.Glyph, a => a); var config = JsonConvert.DeserializeObject <BlueprintConfig>(File.ReadAllText(blueprintConfigPath)); var tiles = config.Tiles.ToDictionary(a => (char?)a.Glyph, a => a); var nullTile = BlueprintTile.Null(); foreach (var tile in tiles) { if (tile.Key == null) { continue; } if (specialChars.ContainsKey(tile.Key.Value)) { throw new Exception("Glyph '" + tile.Key.Value + "': is reserved as a special character and cannot be used in " + name); } } var blueprint = File.ReadAllText(blueprintPath).Replace("\r", "").Split('\n'); var cells = new List <T>(); for (int y = 0; y < GridSizeY; y++) { for (int x = 0; x < GridSizeX; x++) { char?charValue; if (y >= blueprint.Length || x >= blueprint[y].Length) { charValue = null; } else { charValue = blueprint[y][x]; } var position = new Point(x, y); BlueprintTile tile = nullTile; if (charValue != null && !tiles.TryGetValue(charValue, out tile)) { throw new Exception("Glyph '" + charValue + "' was not present in the config file for blueprint: " + name); } var foregroundColor = MonoGameExtensions.GetColorByString(tile.Foreground); var backgroundColor = tile.Background != null?MonoGameExtensions.GetColorByString(tile.Background) : Color.Black; var cell = new T() { Glyph = tile.Glyph, Position = position, Foreground = foregroundColor, Background = backgroundColor, CellProperties = new EmberCell.EmberCellProperties { NormalForeground = foregroundColor, NormalBackground = backgroundColor, ForegroundFov = foregroundColor == Color.Transparent ? Color.Transparent : Color.Lerp(foregroundColor, Color.Black, .5f), BackgroundFov = backgroundColor == Color.Transparent ? Color.Transparent : Color.Lerp(backgroundColor, Color.Black, .5f), Walkable = tile.Walkable, Interactable = tile.Interactable, Name = tile.Name, BlocksFov = tile.BlocksFov, }, LightProperties = new EmberCell.LightEngineProperties { EmitsLight = tile.EmitsLight, LightRadius = tile.LightRadius, Brightness = tile.Brightness } }; if (!string.IsNullOrWhiteSpace(tile.LightColor)) { cell.LightProperties.LightColor = MonoGameExtensions.GetColorByString(tile.LightColor); } cells.Add(cell); } } return(cells.ToArray()); }