2024-01-28 17:32:55 +07:00
|
|
|
|
using Content.Client._White.Trail.Line.Manager;
|
2024-01-28 18:37:24 +07:00
|
|
|
|
using Content.Shared._White.Trail;
|
2024-01-24 12:58:57 +07:00
|
|
|
|
using Robust.Client.Graphics;
|
|
|
|
|
|
using Robust.Client.ResourceManagement;
|
2024-06-04 11:00:48 +00:00
|
|
|
|
using Robust.Shared.Configuration;
|
2024-01-24 12:58:57 +07:00
|
|
|
|
using Robust.Shared.GameStates;
|
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
|
|
2024-01-28 17:32:55 +07:00
|
|
|
|
namespace Content.Client._White.Trail;
|
2024-01-24 12:58:57 +07:00
|
|
|
|
|
|
|
|
|
|
public sealed class TrailSystem : EntitySystem
|
|
|
|
|
|
{
|
|
|
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
|
|
|
|
[Dependency] private readonly ITrailLineManager _lineManager = default!;
|
|
|
|
|
|
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
|
|
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
|
|
IoCManager.Resolve<IOverlayManager>().AddOverlay(
|
|
|
|
|
|
new TrailOverlay(
|
|
|
|
|
|
IoCManager.Resolve<IPrototypeManager>(),
|
|
|
|
|
|
IoCManager.Resolve<IResourceCache>(),
|
2024-06-04 11:00:48 +00:00
|
|
|
|
IoCManager.Resolve<IConfigurationManager>(),
|
2024-01-24 12:58:57 +07:00
|
|
|
|
_lineManager
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<TrailComponent, MoveEvent>(OnTrailMove);
|
|
|
|
|
|
SubscribeLocalEvent<TrailComponent, ComponentRemove>(OnTrailRemove);
|
|
|
|
|
|
SubscribeLocalEvent<TrailComponent, ComponentHandleState>(OnHandleState);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnHandleState(EntityUid uid, TrailComponent component, ref ComponentHandleState args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (args.Current is not TrailComponentState state)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
TrailSettings.Inject(component, state.Settings);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnTrailRemove(EntityUid uid, TrailComponent comp, ComponentRemove args)
|
|
|
|
|
|
{
|
|
|
|
|
|
_lineManager.Detach(comp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnTrailMove(EntityUid uid, TrailComponent comp, ref MoveEvent args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (comp.СreationMethod != SegmentCreationMethod.OnMove || _gameTiming.InPrediction)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
TryCreateSegment(comp, args.Component);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void TryCreateSegment(TrailComponent comp, TransformComponent xform)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (xform.MapID == MapId.Nullspace)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
comp.TrailLine ??= _lineManager.CreateTrail(comp, xform.MapID);
|
|
|
|
|
|
comp.TrailLine.TryCreateSegment(_transformSystem.GetWorldPositionRotation(xform), xform.MapID);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void FrameUpdate(float frameTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.FrameUpdate(frameTime);
|
|
|
|
|
|
|
|
|
|
|
|
_lineManager.Update(frameTime);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var (comp, xform) in EntityQuery<TrailComponent, TransformComponent>())
|
|
|
|
|
|
{
|
|
|
|
|
|
if (comp.СreationMethod == SegmentCreationMethod.OnFrameUpdate)
|
|
|
|
|
|
TryCreateSegment(comp, xform);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|