SimpleFloorPlanPopulatorComponent.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Linq;
  2. using Content.Server.Worldgen.Systems.Debris;
  3. using Content.Server.Worldgen.Tools;
  4. using Content.Shared.Maps;
  5. using Content.Shared.Storage;
  6. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
  7. namespace Content.Server.Worldgen.Components.Debris;
  8. /// <summary>
  9. /// This is used for populating a grid with random entities automatically.
  10. /// </summary>
  11. [RegisterComponent]
  12. [Access(typeof(SimpleFloorPlanPopulatorSystem))]
  13. public sealed partial class SimpleFloorPlanPopulatorComponent : Component
  14. {
  15. private Dictionary<string, EntitySpawnCollectionCache>? _caches;
  16. /// <summary>
  17. /// The prototype facing floor plan populator entries.
  18. /// </summary>
  19. [DataField("entries", required: true,
  20. customTypeSerializer: typeof(PrototypeIdDictionarySerializer<List<EntitySpawnEntry>, ContentTileDefinition>))]
  21. private Dictionary<string, List<EntitySpawnEntry>> _entries = default!;
  22. /// <summary>
  23. /// The spawn collections used to place entities on different tile types.
  24. /// </summary>
  25. [ViewVariables]
  26. public Dictionary<string, EntitySpawnCollectionCache> Caches
  27. {
  28. get
  29. {
  30. if (_caches is null)
  31. {
  32. _caches = _entries
  33. .Select(x =>
  34. new KeyValuePair<string, EntitySpawnCollectionCache>(x.Key,
  35. new EntitySpawnCollectionCache(x.Value)))
  36. .ToDictionary(x => x.Key, x => x.Value);
  37. }
  38. return _caches;
  39. }
  40. }
  41. }