1
0

DungeonData.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System.Linq;
  2. using Content.Shared.Maps;
  3. using Content.Shared.Storage;
  4. using Content.Shared.Whitelist;
  5. using Robust.Shared.Prototypes;
  6. using Robust.Shared.Utility;
  7. namespace Content.Shared.Procedural;
  8. /// <summary>
  9. /// Used to set dungeon values for all layers.
  10. /// </summary>
  11. /// <remarks>
  12. /// This lets us share data between different dungeon configs without having to repeat entire configs.
  13. /// </remarks>
  14. [DataRecord]
  15. public sealed partial class DungeonData
  16. {
  17. // I hate this but it also significantly reduces yaml bloat if we add like 10 variations on the same set of layers
  18. // e.g. science rooms, engi rooms, cargo rooms all under PlanetBase for example.
  19. // without having to do weird nesting. It also means we don't need to copy-paste the same prototype across several layers
  20. // The alternative is doing like,
  21. // 2 layer prototype, 1 layer with the specified data, 3 layer prototype, 2 layers with specified data, etc.
  22. // As long as we just keep the code clean over time it won't be bad to maintain.
  23. public static DungeonData Empty = new();
  24. public Dictionary<DungeonDataKey, Color> Colors = new();
  25. public Dictionary<DungeonDataKey, EntProtoId> Entities = new();
  26. public Dictionary<DungeonDataKey, ProtoId<EntitySpawnEntryPrototype>> SpawnGroups = new();
  27. public Dictionary<DungeonDataKey, ProtoId<ContentTileDefinition>> Tiles = new();
  28. public Dictionary<DungeonDataKey, EntityWhitelist> Whitelists = new();
  29. /// <summary>
  30. /// Applies the specified data to this data.
  31. /// </summary>
  32. public void Apply(DungeonData data)
  33. {
  34. // Copy-paste moment.
  35. foreach (var color in data.Colors)
  36. {
  37. Colors[color.Key] = color.Value;
  38. }
  39. foreach (var color in data.Entities)
  40. {
  41. Entities[color.Key] = color.Value;
  42. }
  43. foreach (var color in data.SpawnGroups)
  44. {
  45. SpawnGroups[color.Key] = color.Value;
  46. }
  47. foreach (var color in data.Tiles)
  48. {
  49. Tiles[color.Key] = color.Value;
  50. }
  51. foreach (var color in data.Whitelists)
  52. {
  53. Whitelists[color.Key] = color.Value;
  54. }
  55. }
  56. public DungeonData Clone()
  57. {
  58. return new DungeonData
  59. {
  60. // Only shallow clones but won't matter for DungeonJob purposes.
  61. Colors = Colors.ShallowClone(),
  62. Entities = Entities.ShallowClone(),
  63. SpawnGroups = SpawnGroups.ShallowClone(),
  64. Tiles = Tiles.ShallowClone(),
  65. Whitelists = Whitelists.ShallowClone(),
  66. };
  67. }
  68. }
  69. public enum DungeonDataKey : byte
  70. {
  71. // Colors
  72. Decals,
  73. // Entities
  74. Cabling,
  75. CornerWalls,
  76. Fill,
  77. Junction,
  78. Walls,
  79. // SpawnGroups
  80. CornerClutter,
  81. Entrance,
  82. EntranceFlank,
  83. WallMounts,
  84. Window,
  85. // Tiles
  86. FallbackTile,
  87. WidenTile,
  88. // Whitelists
  89. Rooms,
  90. }