forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rpg visual fix * Update GunByHasAmmoVisualizerSystem.cs * add licence
- Loading branch information
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
Content.Client/SS220/Weapons/Ranged/Visualizer/Components/GunByHasAmmoVisualsComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
61 changes: 61 additions & 0 deletions
61
Content.Client/SS220/Weapons/Ranged/Visualizer/Systems/GunByHasAmmoVisualizerSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters