diff --git a/Content.Server/CrystallPunk/SpawnMapBiome/StationBiomeComponent.cs b/Content.Server/CrystallPunk/SpawnMapBiome/StationBiomeComponent.cs new file mode 100644 index 0000000000..a61f30b370 --- /dev/null +++ b/Content.Server/CrystallPunk/SpawnMapBiome/StationBiomeComponent.cs @@ -0,0 +1,19 @@ +using Content.Shared.Parallax.Biomes; +using Robust.Shared.Prototypes; + +namespace Content.Server.Corvax.CrystallPunk.SpawnMapBiome; + +/// +/// allows you to initialize a planet on a specific map at initialization time. +/// + +[RegisterComponent, Access(typeof(StationBiomeSystem))] +public sealed partial class StationBiomeComponent : Component +{ + [DataField] + public ProtoId Biome = "Grasslands"; + + // If null, its random + [DataField] + public int? Seed = null; +} diff --git a/Content.Server/CrystallPunk/SpawnMapBiome/StationBiomeSystem.cs b/Content.Server/CrystallPunk/SpawnMapBiome/StationBiomeSystem.cs new file mode 100644 index 0000000000..c794474e95 --- /dev/null +++ b/Content.Server/CrystallPunk/SpawnMapBiome/StationBiomeSystem.cs @@ -0,0 +1,35 @@ +using Content.Server.Parallax; +using Content.Server.Station.Components; +using Content.Server.Station.Events; +using Content.Server.Station.Systems; +using Robust.Shared.Map; +using Robust.Shared.Prototypes; + +namespace Content.Server.Corvax.CrystallPunk.SpawnMapBiome; +public sealed partial class StationBiomeSystem : EntitySystem +{ + [Dependency] private readonly BiomeSystem _biome = default!; + [Dependency] private readonly IMapManager _mapManager = default!; + [Dependency] private readonly IPrototypeManager _proto = default!; + [Dependency] private readonly StationSystem _station = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnStationPostInit); + } + + private void OnStationPostInit(Entity map, ref StationPostInitEvent args) + { + if (!TryComp(map, out StationDataComponent? dataComp)) + return; + + var station = _station.GetLargestGrid(dataComp); + if (station == null) return; + + var mapId = Transform(station.Value).MapID; + var mapUid = _mapManager.GetMapEntityId(mapId); + + _biome.EnsurePlanet(mapUid, _proto.Index(map.Comp.Biome), map.Comp.Seed); + } +} diff --git a/Resources/Prototypes/Maps/debug.yml b/Resources/Prototypes/Maps/debug.yml index 74cbf4ecc6..d3b414a73b 100644 --- a/Resources/Prototypes/Maps/debug.yml +++ b/Resources/Prototypes/Maps/debug.yml @@ -24,6 +24,7 @@ Dev: stationProto: StandardNanotrasenStation components: + - type: StationBiome - type: StationNameSetup mapNameTemplate: "Dev" - type: StationJobs