Skip to content

Commit

Permalink
messing around with shader code
Browse files Browse the repository at this point in the history
  • Loading branch information
gluesniffler committed Sep 12, 2024
1 parent 2b79fdc commit 21e3d85
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 83 deletions.
36 changes: 27 additions & 9 deletions Content.Client/DeltaV/Harpy/FlightSystem.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Robust.Client.GameObjects;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
using Robust.Client.GameObjects;
using Content.Shared.DeltaV.Harpy;
using Content.Shared.DeltaV.Harpy.Components;
using Content.Shared.DeltaV.Harpy.Events;

namespace Content.Shared.DeltaV.Harpy
namespace Content.Client.DeltaV.Harpy
{
public sealed class FlightSystem : SharedFlightSystem
{
Expand All @@ -22,22 +24,38 @@ private void OnFlight(FlightEvent args)
if (!_entityManager.TryGetComponent(uid, out SpriteComponent? sprite))
return;

var wingLayer = GetHarpyWingLayer(uid, sprite);
if (wingLayer == null)
return;
sprite.LayerSetColor(wingLayer.Value, Color.White);
if (args.Layer != string.Empty)
{
var targetLayer = GetAnimatedLayer(uid, args.Layer, sprite);
if (targetLayer == null)
return;
sprite.LayerSetColor(targetLayer.Value, Color.White);
}

if (args.IsFlying && args.IsAnimated && args.AnimationKey != "default")
{
var comp = new FlyingVisualsComponent
{
AnimationKey = args.AnimationKey,
};
AddComp(uid, comp, true);
}
if (!args.IsFlying)
{
RemComp<FlyingVisualsComponent>(uid);
}
}

public int? GetHarpyWingLayer(EntityUid harpyUid, SpriteComponent? sprite = null)
public int? GetAnimatedLayer(EntityUid uid, string targetLayer, SpriteComponent? sprite = null)
{
if (!Resolve(harpyUid, ref sprite))
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() == "/Textures/Mobs/Customization/Harpy/harpy_wings.rsi")
if (layer.Rsi?.Path.ToString() == targetLayer)
{
return index;
}
Expand Down
Empty file.
57 changes: 57 additions & 0 deletions Content.Client/DeltaV/Harpy/FlyingVisualsSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Content.Shared.DeltaV.Harpy.Events;
using Content.Shared.DeltaV.Harpy.Components;

namespace Content.Client.DeltaV.Harpy;

/// <summary>
/// Handles offsetting an entity while flying
/// </summary>
public abstract class FlyingVisualizerSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly IRobustRandom _random = default!;
private ShaderInstance _shader = default!;
public override void Initialize()
{
base.Initialize();

_shader = _protoMan.Index<ShaderPrototype>("Wave").InstanceUnique();

SubscribeLocalEvent<FlyingVisualsComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<FlyingVisualsComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<FlyingVisualsComponent, BeforePostShaderRenderEvent>(OnBeforeShaderPost);
}

private void OnStartup(EntityUid uid, FlyingVisualsComponent comp, ref ComponentStartup args)
{
_shader = _protoMan.Index<ShaderPrototype>("Wave").InstanceUnique();
comp.Offset = _random.NextFloat(0, 1000);
SetShader(uid, _shader);
}

private void OnShutdown(EntityUid uid, FlyingVisualsComponent comp, ref ComponentShutdown args)
{
SetShader(uid, null);
}

private void SetShader(Entity<SpriteComponent?> entity, ShaderInstance? instance)
{
if (!Resolve(entity, ref entity.Comp, false))
return;

entity.Comp.PostShader = instance;
entity.Comp.GetScreenTexture = instance is not null;
entity.Comp.RaiseShaderEvent = instance is not null;
}

private void OnBeforeShaderPost(EntityUid uid, FlyingVisualsComponent comp, ref BeforePostShaderRenderEvent args)
{
_shader.SetParameter("Speed", comp.Speed);
_shader.SetParameter("Dis", comp.Dis);
_shader.SetParameter("Offset", comp.Offset);
}
}
29 changes: 29 additions & 0 deletions Content.Shared/DeltaV/Harpy/Components/FlyingVisualsComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Numerics;
using Robust.Shared.GameStates;

namespace Content.Shared.DeltaV.Harpy.Components;

[RegisterComponent, NetworkedComponent]
public sealed partial class FlyingVisualsComponent : Component
{
/// <summary>
/// How long does the animation last
/// </summary>
[DataField]
public float AnimationTime = 2f;

/// <summary>
/// How far it goes in any direction.
/// </summary>
[DataField]
public float Offset = 0.2f;

/// <summary>
/// How much the limbs (if there are any) rotate.
/// </summary>
[DataField]
public float Rotation = 0.5f;

[DataField]
public string AnimationKey = default;
}
8 changes: 7 additions & 1 deletion Content.Shared/DeltaV/Harpy/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ public sealed class FlightEvent : EntityEventArgs
{
public NetEntity Uid { get; }
public bool IsFlying { get; }
public bool IsAnimated { get; }
public string Layer { get; }
public string AnimationKey { get; }

public FlightEvent(NetEntity uid, bool isFlying)
public FlightEvent(NetEntity uid, bool isFlying, bool isAnimated, string layer, string animationKey)
{
Uid = uid;
IsFlying = isFlying;
IsAnimated = isAnimated;
Layer = layer;
AnimationKey = animationKey;
}
}

Expand Down
41 changes: 39 additions & 2 deletions Content.Shared/DeltaV/Harpy/FlightComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public sealed partial class FlightComponent : Component
[DataField, AutoNetworkedField]
public EntityUid? ToggleActionEntity;

/// <summary>
/// Is the user flying right now?
/// </summary>

[ViewVariables(VVAccess.ReadWrite), DataField("on"), AutoNetworkedField]
public bool On;

Expand All @@ -29,20 +33,53 @@ public sealed partial class FlightComponent : Component
public float StaminaDrainRate = 3f;

/// <summary>
/// Delay until the user becomes weightless.
/// DoAfter delay until the user becomes weightless.
/// </summary>

[ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float ActivationDelay = 1.0f;

/// <summary>
/// Path to a sound specifier or collection for the noises made during flight
/// </summary>

[DataField("flapSound")]
public SoundSpecifier FlapSound = new SoundCollectionSpecifier("WingFlaps");

/// <summary>
/// Time between flap sounds being played
/// Is the flight animated?
/// </summary>

[DataField("isAnimated")]
public bool IsAnimated = true;

/// <summary>
/// Does the animation animate a layer?.
/// </summary>

[DataField("isLayerAnimated")]
public bool IsLayerAnimated = false;

/// <summary>
/// Which RSI layer path does this animate?
/// </summary>

[DataField("layer")]
public string? Layer;

/// <summary>
/// What animation does the flight use?
/// </summary>

[DataField("animationKey")]
public string AnimationKey = "default";

/// <summary>
/// Time between sounds being played
/// </summary>
[DataField("flapInterval")]
public float FlapInterval = 1.25f;

public float TimeUntilFlap;
}
}
Empty file.
2 changes: 1 addition & 1 deletion Content.Shared/DeltaV/Harpy/SharedFlightSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void ToggleActive(EntityUid uid, bool active, FlightComponent component)
component.TimeUntilFlap = 0f;
_actionsSystem.SetToggled(component.ToggleActionEntity, component.On);
// Triggers the flight animation
RaiseNetworkEvent(new FlightEvent(GetNetEntity(uid), component.On));
RaiseNetworkEvent(new FlightEvent(GetNetEntity(uid), component.On, component.IsAnimated, component.Layer ?? string.Empty, component.AnimationKey));
_staminaSystem.ToggleStaminaDrain(uid, component.StaminaDrainRate, active);
UpdateHands(uid, active);
Dirty(uid, component);
Expand Down
69 changes: 0 additions & 69 deletions Content.Shared/DeltaV/Harpy/SharedFlyingVisualizerSystem.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Content.Shared/Gravity/SharedFloatingVisualizerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void OnFlight(FlightEvent args)
return;
floating.CanFloat = args.IsFlying;

if (args.IsFlying)
if (args.IsFlying && args.IsAnimated)
{
FloatAnimation(uid, floating.Offset, floating.AnimationKey, floating.AnimationTime);
}
Expand Down
2 changes: 2 additions & 0 deletions Resources/Prototypes/Entities/Mobs/Species/harpy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- type: Dash
dashAction: "ActionDashFlight"
- type: Flight
isLayerAnimated: true
layer: "/Textures/Mobs/Customization/Harpy/harpy_wings.rsi"
- type: Singer
proto: HarpySinger
- type: Sprite
Expand Down

0 comments on commit 21e3d85

Please sign in to comment.