Split cargo shuttle to its own component (#23926)
* Split cargo shuttle to its own component If mappers want 1 morbillion of them this is easier to manage. * balls
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Shuttles.Components;
|
||||
|
||||
/// <summary>
|
||||
/// GridSpawnComponent but for cargo shuttles
|
||||
/// <remarks>
|
||||
/// This exists so we don't need to make 1 change to GridSpawn for every single station's unique shuttles.
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class StationCargoShuttleComponent : Component
|
||||
{
|
||||
// If you add more than just make an abstract comp, split them, then use overloads in the system.
|
||||
// YAML is filled out so mappers don't have to read here.
|
||||
|
||||
[DataField(required: true)]
|
||||
public ResPath Path = new("/Maps/Shuttles/cargo.yml");
|
||||
}
|
||||
@@ -14,6 +14,8 @@ public sealed partial class ShuttleSystem
|
||||
private void InitializeGridFills()
|
||||
{
|
||||
SubscribeLocalEvent<GridSpawnComponent, StationPostInitEvent>(OnGridSpawnPostInit);
|
||||
SubscribeLocalEvent<StationCargoShuttleComponent, StationPostInitEvent>(OnCargoSpawnPostInit);
|
||||
|
||||
SubscribeLocalEvent<GridFillComponent, MapInitEvent>(OnGridFillMapInit);
|
||||
|
||||
_cfg.OnValueChanged(CCVars.GridFill, OnGridFillChange);
|
||||
@@ -35,6 +37,13 @@ public sealed partial class ShuttleSystem
|
||||
{
|
||||
GridSpawns(uid, comp);
|
||||
}
|
||||
|
||||
var cargoQuery = AllEntityQuery<StationCargoShuttleComponent>();
|
||||
|
||||
while (cargoQuery.MoveNext(out var uid, out var comp))
|
||||
{
|
||||
CargoSpawn(uid, comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +52,39 @@ public sealed partial class ShuttleSystem
|
||||
GridSpawns(uid, component);
|
||||
}
|
||||
|
||||
private void OnCargoSpawnPostInit(EntityUid uid, StationCargoShuttleComponent component, ref StationPostInitEvent args)
|
||||
{
|
||||
CargoSpawn(uid, component);
|
||||
}
|
||||
|
||||
private void CargoSpawn(EntityUid uid, StationCargoShuttleComponent component)
|
||||
{
|
||||
if (!_cfg.GetCVar(CCVars.GridFill))
|
||||
return;
|
||||
|
||||
if (!TryComp(uid, out StationDataComponent? dataComp))
|
||||
return;
|
||||
|
||||
var targetGrid = _station.GetLargestGrid(dataComp);
|
||||
|
||||
if (targetGrid == null)
|
||||
return;
|
||||
|
||||
var mapId = _mapManager.CreateMap();
|
||||
|
||||
if (_loader.TryLoad(mapId, component.Path.ToString(), out var ent) && ent.Count > 0)
|
||||
{
|
||||
if (TryComp<ShuttleComponent>(ent[0], out var shuttle))
|
||||
{
|
||||
TryFTLProximity(ent[0], shuttle, targetGrid.Value);
|
||||
}
|
||||
|
||||
_station.AddGridToStation(uid, ent[0]);
|
||||
}
|
||||
|
||||
_mapManager.DeleteMap(mapId);
|
||||
}
|
||||
|
||||
private void GridSpawns(EntityUid uid, GridSpawnComponent component)
|
||||
{
|
||||
if (!_cfg.GetCVar(CCVars.GridFill))
|
||||
|
||||
@@ -42,11 +42,10 @@
|
||||
id: BaseStationShuttles
|
||||
abstract: true
|
||||
components:
|
||||
- type: StationCargoShuttle
|
||||
path: /Maps/Shuttles/cargo.yml
|
||||
- type: GridSpawn
|
||||
groups:
|
||||
cargo:
|
||||
paths:
|
||||
- /Maps/Shuttles/cargo.yml
|
||||
mining:
|
||||
paths:
|
||||
- /Maps/Shuttles/mining.yml
|
||||
|
||||
Reference in New Issue
Block a user