public static void AssignCellData(PrototypeDungeonRoom room, string fileName) { string[] linesFromEmbeddedResource = ResourceExtractor.GetLinesFromEmbeddedResource(fileName); int width = room.Width; int height = room.Height; CellType[,] cellData = new CellType[width, height]; for (int Y = 0; Y < height; Y++) { string text = linesFromEmbeddedResource[Y]; for (int X = 0; X < width; X++) { // Corrects final row being off by one unit (read as first line in text file) if (Y == 0 && X > 0) { char c = text[X]; if (c != '-') { if (c != 'P') { if (c == 'W') { cellData[X - 1, height - Y - 1] = CellType.WALL; } } else { cellData[X - 1, height - Y - 1] = CellType.PIT; } } else { cellData[X - 1, height - Y - 1] = CellType.FLOOR; } } else { char c = text[X]; if (c != '-') { if (c != 'P') { if (c == 'W') { cellData[X, height - Y - 1] = CellType.WALL; } } else { cellData[X, height - Y - 1] = CellType.PIT; } } else { cellData[X, height - Y - 1] = CellType.FLOOR; } } } } // Set Final Cell (it was left null for some reason) string text2 = linesFromEmbeddedResource[height - 1]; char C = text2[width - 1]; if (C != '-') { if (C != 'P') { if (C == 'W') { cellData[width - 1, height - 1] = CellType.WALL; } } else { cellData[width - 1, height - 1] = CellType.PIT; } } else { cellData[width - 1, height - 1] = CellType.FLOOR; } for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { room.GetCellDataAtPoint(i, j).state = cellData[i, j]; } } room.UpdatePrecalculatedData(); }
public static void AssignCellDataForNewRoom(PrototypeDungeonRoom room, string fileName) { string[] linesFromEmbeddedResource = ResourceExtractor.GetLinesFromEmbeddedResource(fileName); int width = room.Width; int height = room.Height; FieldInfo privateField = typeof(PrototypeDungeonRoom).GetField("m_cellData", BindingFlags.Instance | BindingFlags.NonPublic); PrototypeDungeonRoomCellData[] m_cellData = new PrototypeDungeonRoomCellData[width * height]; CellType[,] cellData = new CellType[width, height]; for (int Y = 0; Y < height; Y++) { string text = linesFromEmbeddedResource[Y]; for (int X = 0; X < width; X++) { // Corrects final row being off by one unit (read as first line in text file) if (Y == 0 && X > 0) { char c = text[X]; if (c != '-') { if (c != 'P') { if (c == 'W') { cellData[X - 1, height - Y - 1] = CellType.WALL; } } else { cellData[X - 1, height - Y - 1] = CellType.PIT; } } else { cellData[X - 1, height - Y - 1] = CellType.FLOOR; } } else { char c = text[X]; if (c != '-') { if (c != 'P') { if (c == 'W') { cellData[X, height - Y - 1] = CellType.WALL; } } else { cellData[X, height - Y - 1] = CellType.PIT; } } else { cellData[X, height - Y - 1] = CellType.FLOOR; } } } } // Set Final Cell (it was left null for some reason) string text2 = linesFromEmbeddedResource[height - 1]; char C = text2[width - 1]; if (C != '-') { if (C != 'P') { if (C == 'W') { cellData[width - 1, height - 1] = CellType.WALL; } } else { cellData[width - 1, height - 1] = CellType.PIT; } } else { cellData[width - 1, height - 1] = CellType.FLOOR; } for (int X = 0; X < width; X++) { for (int Y = 0; Y < height; Y++) { m_cellData[Y * width + X] = GenerateDefaultCellData(cellData[X, Y]); } } privateField.SetValue(room, m_cellData); room.UpdatePrecalculatedData(); }