Roundstart planetmap (#2)

* planetmap component

* refactor code
This commit is contained in:
Ed
2024-03-30 01:54:31 +03:00
committed by GitHub
parent 17184ef1dd
commit 1cd8e35c25
3 changed files with 55 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
using Content.Shared.Parallax.Biomes;
using Robust.Shared.Prototypes;
namespace Content.Server.Corvax.CrystallPunk.SpawnMapBiome;
/// <summary>
/// allows you to initialize a planet on a specific map at initialization time.
/// </summary>
[RegisterComponent, Access(typeof(StationBiomeSystem))]
public sealed partial class StationBiomeComponent : Component
{
[DataField]
public ProtoId<BiomeTemplatePrototype> Biome = "Grasslands";
// If null, its random
[DataField]
public int? Seed = null;
}

View File

@@ -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<StationBiomeComponent, StationPostInitEvent>(OnStationPostInit);
}
private void OnStationPostInit(Entity<StationBiomeComponent> 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);
}
}

View File

@@ -24,6 +24,7 @@
Dev:
stationProto: StandardNanotrasenStation
components:
- type: StationBiome
- type: StationNameSetup
mapNameTemplate: "Dev"
- type: StationJobs