Skip to content

Commit

Permalink
Is this thing even working
Browse files Browse the repository at this point in the history
  • Loading branch information
gluesniffler committed Sep 14, 2024
1 parent 0c102cb commit cfa9bc5
Show file tree
Hide file tree
Showing 10 changed files with 350 additions and 371 deletions.
98 changes: 46 additions & 52 deletions Content.Client/Flight/FlightSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,65 @@
using Content.Shared.Flight.Events;
using Content.Client.Flight.Components;

namespace Content.Client.Flight
namespace Content.Client.Flight;
public sealed class FlightSystem : SharedFlightSystem
{
public sealed class FlightSystem : SharedFlightSystem
[Dependency] private readonly IEntityManager _entityManager = default!;
public override void Initialize()
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public override void Initialize()
{
base.Initialize();

SubscribeNetworkEvent<FlightEvent>(OnFlight);
base.Initialize();

}
SubscribeNetworkEvent<FlightEvent>(OnFlight);

private void OnFlight(FlightEvent args)
{
Logger.Debug("Starting onFlight!");
var uid = GetEntity(args.Uid);
if (!_entityManager.TryGetComponent(uid, out SpriteComponent? sprite)
|| !args.IsAnimated
|| !_entityManager.TryGetComponent(uid, out FlightComponent? flight))
return;
}

private void OnFlight(FlightEvent args)
{
var uid = GetEntity(args.Uid);
if (!_entityManager.TryGetComponent(uid, out SpriteComponent? sprite)
|| !args.IsAnimated
|| !_entityManager.TryGetComponent(uid, out FlightComponent? flight))
return;

int? targetLayer = null;
if (flight.IsLayerAnimated && flight.Layer is not null)
{
targetLayer = GetAnimatedLayer(uid, flight.Layer, sprite);
if (targetLayer == null)
return;
}

if (args.IsFlying && args.IsAnimated && flight.AnimationKey != "default")
{
var comp = new FlightVisualsComponent
{
AnimateLayer = flight.IsLayerAnimated,
AnimationKey = flight.AnimationKey,
Multiplier = flight.ShaderMultiplier,
Offset = flight.ShaderOffset,
Speed = flight.ShaderSpeed,
TargetLayer = targetLayer,
};
AddComp(uid, comp);
}
if (!args.IsFlying)
RemComp<FlightVisualsComponent>(uid);
int? targetLayer = null;
if (flight.IsLayerAnimated && flight.Layer is not null)
{
targetLayer = GetAnimatedLayer(uid, flight.Layer, sprite);
if (targetLayer == null)
return;
}

public int? GetAnimatedLayer(EntityUid uid, string targetLayer, SpriteComponent? sprite = null)
if (args.IsFlying && args.IsAnimated && flight.AnimationKey != "default")
{
if (!Resolve(uid, ref sprite))
return null;

int index = 0;
foreach (var layer in sprite.AllLayers)
var comp = new FlightVisualsComponent
{
// This feels like absolute shitcode, isn't there a better way to check for it?
if (layer.Rsi?.Path.ToString() == targetLayer)
{
return index;
}
index++;
}
AnimateLayer = flight.IsLayerAnimated,
AnimationKey = flight.AnimationKey,
Multiplier = flight.ShaderMultiplier,
Offset = flight.ShaderOffset,
Speed = flight.ShaderSpeed,
TargetLayer = targetLayer,
};
AddComp(uid, comp);
}
if (!args.IsFlying)
RemComp<FlightVisualsComponent>(uid);
}

public int? GetAnimatedLayer(EntityUid uid, string targetLayer, SpriteComponent? sprite = null)
{
if (!Resolve(uid, ref sprite))
return null;

int index = 0;
foreach (var layer in sprite.AllLayers)
{
// This feels like absolute shitcode, isn't there a better way to check for it?
if (layer.Rsi?.Path.ToString() == targetLayer)
return index;
index++;
}
return null;
}
}
9 changes: 4 additions & 5 deletions Content.Client/Flight/FlyingVisualizerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,20 @@ private void AddShader(Entity<SpriteComponent?> entity, ShaderInstance? shader,
return;

if (!animateLayer)
{
entity.Comp.PostShader = shader;
}

if (animateLayer && layer is not null)
{
entity.Comp.LayerSetShader(layer.Value, shader);
}

entity.Comp.GetScreenTexture = shader is not null;
entity.Comp.RaiseShaderEvent = shader is not null;
}

/// <summary>
/// This function can be used to modify the shader's values while its running.
/// </summary>
private void OnBeforeShaderPost(EntityUid uid, FlightVisualsComponent comp, ref BeforePostShaderRenderEvent args)
{
// This function can be used to modify the shader's values while its running.
SetValues(comp, comp.Speed, comp.Offset, comp.Multiplier);
}

Expand Down
Loading

0 comments on commit cfa9bc5

Please sign in to comment.