Skip to content

Commit

Permalink
shitcode pt2
Browse files Browse the repository at this point in the history
  • Loading branch information
MilonPL committed Nov 27, 2024
1 parent fc97c5f commit dc40f74
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 137 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Content.Client.DeltaV.Weapons.Ranged.Systems;
using Robust.Client.Graphics;
using Content.Client.Weapons.Ranged.Systems;
using Robust.Shared.Enums;

namespace Content.Client.Weapons.Ranged.Overlays;
namespace Content.Client.DeltaV.Weapons.Ranged.Overlays;

public sealed class TracerOverlay : Overlay
{
Expand Down
90 changes: 90 additions & 0 deletions Content.Client/DeltaV/Weapons/Ranged/Systems/TracerSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Numerics;
using Content.Client.DeltaV.Weapons.Ranged.Overlays;
using Content.Shared.DeltaV.Weapons.Ranged.Components;
using Robust.Client.Graphics;
using Robust.Shared.Map;
using Robust.Shared.Timing;
using TracerComponent = Content.Shared.DeltaV.Weapons.Ranged.Components.TracerComponent;

namespace Content.Client.DeltaV.Weapons.Ranged.Systems;

public sealed class TracerSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IOverlayManager _overlay = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;

public override void Initialize()
{
base.Initialize();
_overlay.AddOverlay(new TracerOverlay(this));

SubscribeLocalEvent<TracerComponent, ComponentStartup>(OnTracerStart);
}

private void OnTracerStart(Entity<TracerComponent> ent, ref ComponentStartup args)
{
var xform = Transform(ent);
var pos = _transform.GetWorldPosition(xform);

ent.Comp.Data = new TracerData
{
EndTime = _timing.CurTime + TimeSpan.FromSeconds(ent.Comp.Lifetime),
PositionHistory = new List<Vector2> { pos }
};
}

public override void Update(float frameTime)
{
base.Update(frameTime);

var curTime = _timing.CurTime;
var query = EntityQueryEnumerator<TracerComponent, TransformComponent>();

while (query.MoveNext(out var uid, out var tracer, out var xform))
{
if (curTime > tracer.Data.EndTime)
{
RemCompDeferred<TracerComponent>(uid);
continue;
}

var positions = tracer.Data.PositionHistory;
var currentPos = _transform.GetWorldPosition(xform);
positions.Add(currentPos);

while (positions.Count > 2 && GetTrailLength(positions) > tracer.Length)
{
positions.RemoveAt(0);
}
}
}

private static float GetTrailLength(List<Vector2> positions)
{
var length = 0f;
for (var i = 1; i < positions.Count; i++)
{
length += Vector2.Distance(positions[i - 1], positions[i]);
}
return length;
}

public void Draw(DrawingHandleWorld handle, MapId currentMap)
{
var query = EntityQueryEnumerator<TracerComponent, TransformComponent>();

while (query.MoveNext(out _, out var tracer, out var xform))
{
if (xform.MapID != currentMap)
continue;

var positions = tracer.Data.PositionHistory;
for (var i = 1; i < positions.Count; i++)
{
handle.DrawLine(positions[i - 1], positions[i], tracer.Color);
}
}
}
}

123 changes: 0 additions & 123 deletions Content.Client/Weapons/Ranged/Systems/TracerSystem.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
using System.Numerics;
using Robust.Shared.GameStates;
using Robust.Shared.Map;

namespace Content.Shared.Weapons.Ranged.Components;
namespace Content.Shared.DeltaV.Weapons.Ranged.Components;

/// <summary>
/// Added to projectiles to give them tracer effects
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[RegisterComponent, NetworkedComponent]
public sealed partial class TracerComponent : Component
{
/// <summary>
/// How long the tracer effect should remain visible for after firing
/// </summary>
[DataField, AutoNetworkedField]
[DataField]
public float Lifetime = 10f;

/// <summary>
/// The maximum length of the tracer trail
/// </summary>
[DataField, AutoNetworkedField]
[DataField]
public float Length = 2f;

/// <summary>
/// Color of the tracer line effect
/// </summary>
[DataField, AutoNetworkedField]
[DataField]
public Color Color = Color.Red;

public TracerData Data = default!;
}

public sealed class TracerData
{
public List<Vector2> PositionHistory = new();
public TimeSpan EndTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1120,32 +1120,29 @@

# so that we dont have to add the same components over and over again
- type: entity
abstract: true
id: BaseBulletTracer
name: base bullet tracer red
categories: [ HideSpawnMenu ]
components:
- type: Tracer
- type: PointLight
radius: 1.4
radius: 1.3
energy: 2
color: "#ff0000"

- type: entity
abstract: true
parent: BaseBulletTracer
id: BaseBulletTracerYellow
name: base bullet tracer yellow
categories: [ HideSpawnMenu ]
components:
- type: Tracer
color: "#ffff00"
- type: PointLight
color: "#ffff00"

- type: entity
abstract: true
parent: BaseBulletTracer
id: BaseBulletTracerGreen
name: base bullet tracer green
categories: [ HideSpawnMenu ]
components:
- type: Tracer
color: "#008000"
Expand Down

0 comments on commit dc40f74

Please sign in to comment.