Skip to content

Commit

Permalink
Rpg visual fix (#1795)
Browse files Browse the repository at this point in the history
* rpg visual fix

* Update GunByHasAmmoVisualizerSystem.cs

* add licence
  • Loading branch information
FunTust authored Sep 7, 2024
1 parent a0e1a94 commit f2833cd
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using Content.Shared.Hands.Components;

namespace Content.Client.SS220.Weapons.Ranged.Visualizer.Components;

/// <summary>
/// Sets which sprite RSI is used for displaying the gun visuals and what state to use based on the ammo count.
/// </summary>
[RegisterComponent]
public sealed partial class GunByHasAmmoVisualsComponent : Component
{
/// <summary>
/// Layer to the sprite of the player that is holding this entity (while the component is toggled on).
/// </summary>
[DataField("inhandVisuals")]
public Dictionary<HandLocation, List<PrototypeLayerData>> InhandVisuals = new();

[DataField("state")] public string? PreviousState;
[ViewVariables] public int? LayerNumber;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using Content.Client.Items.Systems;
using Content.Client.SS220.Weapons.Ranged.Visualizer.Components;
using Content.Client.Weapons.Ranged.Components;
using Content.Shared.Hands;
using Content.Shared.Item;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Client.GameObjects;

namespace Content.Client.SS220.Weapons.Ranged.Visualizer.Systems;

/// <summary>
/// This handles the display of inhand sprite on guns.
/// </summary>
public sealed class GunByHasAmmoVisualizerSystem : VisualizerSystem<GunByHasAmmoVisualsComponent>
{
[Dependency] private readonly SharedItemSystem _itemSys = default!;
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<GunByHasAmmoVisualsComponent, GetInhandVisualsEvent>(OnGetHeldVisuals, after: new[] { typeof(ItemSystem) });
}

protected override void OnAppearanceChange(EntityUid uid, GunByHasAmmoVisualsComponent component, ref AppearanceChangeEvent args)
{
if (args.Sprite != null &&
component.LayerNumber == null &&
args.Sprite.LayerMapTryGet(GunVisualLayers.Base, out var layer))
{
component.LayerNumber = layer;
}
_itemSys.VisualsChanged(uid);
}

private void OnGetHeldVisuals(EntityUid uid, GunByHasAmmoVisualsComponent component, GetInhandVisualsEvent args)
{
if ( !TryComp(uid, out AppearanceComponent? appearance)
|| !AppearanceSystem.TryGetData<int>(uid, AmmoVisuals.AmmoCount, out var count, appearance)
|| component.LayerNumber == null)
return;

if (count != 0)
{
if(component.PreviousState == null)
return;
args.Layers[component.LayerNumber.Value].Item2.State = component.PreviousState;
component.PreviousState = null;
return;
}

if (!component.InhandVisuals.TryGetValue(args.Location, out var layers))
return;

foreach (var layer in layers)
{
component.PreviousState = args.Layers[component.LayerNumber.Value].Item2.State;
args.Layers[component.LayerNumber.Value].Item2.State = layer.State;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@
steps: 2
zeroVisible: false
- type: Appearance
#ss220-start fix https://github.com/SerbiaStrong-220/space-station-14/issues/1192
- type: GunByHasAmmoVisuals
inhandVisuals:
left:
- state: rocket0-inhand-left
right:
- state: rocket0-inhand-right
##ss220-end


- type: entity
name: multiple rocket launcher
Expand Down

0 comments on commit f2833cd

Please sign in to comment.