Skip to content
This repository has been archived by the owner on Dec 29, 2024. It is now read-only.

[Port] Combat Indicator #12

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion Content.Client/CombatMode/CombatModeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Shared.Configuration;
using Robust.Client.GameObjects;
using Content.Shared.StatusIcon.Components;
using Content.Client.Actions;
using System.Numerics;
using Robust.Shared.GameObjects;
using Robust.Shared.Utility;

namespace Content.Client.CombatMode;

Expand All @@ -21,14 +27,17 @@ public sealed class CombatModeSystem : SharedCombatModeSystem
/// Raised whenever combat mode changes.
/// </summary>
public event Action<bool>? LocalPlayerCombatModeUpdated;
private EntityQuery<SpriteComponent> _spriteQuery; // Everwood

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<CombatModeComponent, AfterAutoHandleStateEvent>(OnHandleState);

SubscribeLocalEvent<CombatModeComponent, GetStatusIconsEvent>(UpdateCombatModeIndicator); // Everwood EDIT
Subs.CVar(_cfg, CCVars.CombatModeIndicatorsPointShow, OnShowCombatIndicatorsChanged, true);

_spriteQuery = GetEntityQuery<SpriteComponent>(); // Everwood
}

private void OnHandleState(EntityUid uid, CombatModeComponent component, ref AfterAutoHandleStateEvent args)
Expand Down Expand Up @@ -91,4 +100,27 @@ private void OnShowCombatIndicatorsChanged(bool isShow)
_overlayManager.RemoveOverlay<CombatModeIndicatorsOverlay>();
}
}

// Everwood START
private void UpdateCombatModeIndicator(EntityUid uid, CombatModeComponent comp, ref GetStatusIconsEvent _)
{
if (!_spriteQuery.TryComp(uid, out var sprite))
return;

if (comp.IsInCombatMode)
{
if (!sprite.LayerMapTryGet("combat_mode_indicator", out var layer))
{
layer = sprite.AddLayer(new SpriteSpecifier.Rsi(new ResPath("_Everwood/Effects/combat_mode.rsi"), "combat_mode"));
sprite.LayerMapSet("combat_mode_indicator", layer);
}
}
else
{
if (sprite.LayerMapTryGet("combat_mode_indicator", out var layerToRemove))
{
sprite.RemoveLayer(layerToRemove);
}
}
} // Everwood END
Comment on lines +104 to +125
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Требуются улучшения в реализации UpdateCombatModeIndicator

Выявлены следующие проблемы:

  1. Использование магических строк для имен слоев и путей
  2. Отсутствует проверка параметра comp на null
  3. Отсутствует обработка ошибок при загрузке спрайтов

Предлагаемые изменения:

+    private const string CombatModeIndicatorLayer = "combat_mode_indicator";
+    private const string CombatModeSpritePath = "_Everwood/Effects/combat_mode.rsi";
+    private const string CombatModeState = "combat_mode";

     private void UpdateCombatModeIndicator(EntityUid uid, CombatModeComponent comp, ref GetStatusIconsEvent _)
     {
+        if (comp == null)
+            return;
+
         if (!_spriteQuery.TryComp(uid, out var sprite))
             return;

         if (comp.IsInCombatMode)
         {
-            if (!sprite.LayerMapTryGet("combat_mode_indicator", out var layer))
+            if (!sprite.LayerMapTryGet(CombatModeIndicatorLayer, out var layer))
             {
+                try
+                {
-                layer = sprite.AddLayer(new SpriteSpecifier.Rsi(new ResPath("_Everwood/Effects/combat_mode.rsi"), "combat_mode"));
-                sprite.LayerMapSet("combat_mode_indicator", layer);
+                    layer = sprite.AddLayer(new SpriteSpecifier.Rsi(new ResPath(CombatModeSpritePath), CombatModeState));
+                    sprite.LayerMapSet(CombatModeIndicatorLayer, layer);
+                }
+                catch (Exception e)
+                {
+                    Logger.ErrorS("combat", $"Failed to load combat mode indicator sprite: {e}");
+                    return;
+                }
             }
         }
         else
         {
-            if (sprite.LayerMapTryGet("combat_mode_indicator", out var layerToRemove))
+            if (sprite.LayerMapTryGet(CombatModeIndicatorLayer, out var layerToRemove))
             {
                 sprite.RemoveLayer(layerToRemove);
             }
         }
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Everwood START
private void UpdateCombatModeIndicator(EntityUid uid, CombatModeComponent comp, ref GetStatusIconsEvent _)
{
if (!_spriteQuery.TryComp(uid, out var sprite))
return;
if (comp.IsInCombatMode)
{
if (!sprite.LayerMapTryGet("combat_mode_indicator", out var layer))
{
layer = sprite.AddLayer(new SpriteSpecifier.Rsi(new ResPath("_Everwood/Effects/combat_mode.rsi"), "combat_mode"));
sprite.LayerMapSet("combat_mode_indicator", layer);
}
}
else
{
if (sprite.LayerMapTryGet("combat_mode_indicator", out var layerToRemove))
{
sprite.RemoveLayer(layerToRemove);
}
}
} // Everwood END
private const string CombatModeIndicatorLayer = "combat_mode_indicator";
private const string CombatModeSpritePath = "_Everwood/Effects/combat_mode.rsi";
private const string CombatModeState = "combat_mode";
private void UpdateCombatModeIndicator(EntityUid uid, CombatModeComponent comp, ref GetStatusIconsEvent _)
{
if (comp == null)
return;
if (!_spriteQuery.TryComp(uid, out var sprite))
return;
if (comp.IsInCombatMode)
{
if (!sprite.LayerMapTryGet(CombatModeIndicatorLayer, out var layer))
{
try
{
layer = sprite.AddLayer(new SpriteSpecifier.Rsi(new ResPath(CombatModeSpritePath), CombatModeState));
sprite.LayerMapSet(CombatModeIndicatorLayer, layer);
}
catch (Exception e)
{
Logger.ErrorS("combat", $"Failed to load combat mode indicator sprite: {e}");
return;
}
}
}
else
{
if (sprite.LayerMapTryGet(CombatModeIndicatorLayer, out var layerToRemove))
{
sprite.RemoveLayer(layerToRemove);
}
}
}

}
13 changes: 11 additions & 2 deletions Content.Shared/CombatMode/SharedCombatModeSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using Content.Shared.Actions;
using Content.Shared.CombatMode; // Everwood
using Content.Shared.MouseRotator;
using Content.Shared.Movement.Components;
using Content.Shared.Popups;
using Robust.Shared.Audio; // Everwood
using Robust.Shared.Audio.Systems; // Everwood
using Robust.Shared.GameObjects; // Everwood
using Robust.Shared.Network;
using Robust.Shared.Timing;

Expand All @@ -13,6 +17,7 @@ public abstract class SharedCombatModeSystem : EntitySystem
[Dependency] private readonly INetManager _netMan = default!;
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!; // Everwood

public override void Initialize()
{
Expand Down Expand Up @@ -50,9 +55,13 @@ private void OnActionPerform(EntityUid uid, CombatModeComponent component, Toggl
if (!_netMan.IsClient || !Timing.IsFirstTimePredicted)
return;

var msg = component.IsInCombatMode ? "action-popup-combat-enabled" : "action-popup-combat-disabled";
_popup.PopupEntity(Loc.GetString(msg), args.Performer, args.Performer);
// Everwood START
_audio.PlayPvs(component.IsInCombatMode ? "/Audio/_Everwood/Effects/CombatMode/on.ogg" : "/Audio/_Ataraxia/Effects/CombatMode/off.ogg", uid);

// var msg = component.IsInCombatMode ? "action-popup-combat-enabled" : "action-popup-combat-disabled";
// _popup.PopupEntity(Loc.GetString(msg), args.Performer, args.Performer);
PuroSlavKing marked this conversation as resolved.
Show resolved Hide resolved
}
// Everwood END
PuroSlavKing marked this conversation as resolved.
Show resolved Hide resolved

public void SetCanDisarm(EntityUid entity, bool canDisarm, CombatModeComponent? component = null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- files: ["on.ogg", "off.ogg"]
license: "CC-BY-NC-SA-3.0"
copyright: 'Taken from /tg/station at commit 87c4c6ae94acd6ac8000bc0c2f43fc2cfc928224 and https://github.com/BlueMoon-Labs/MOLOT-BlueMoon-Station/blob/master/sound/machines/chime.ogg. Converted to mono by PuroSlavKing'
source: "https://github.com/tgstation/tgstation/blob/87c4c6ae94acd6ac8000bc0c2f43fc2cfc928224"
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions Resources/Textures/_Everwood/Effects/combat_mode.rsi/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Taken from https://github.com/BlueMoon-Labs/MOLOT-BlueMoon-Station/blob/master/modular_sand/icons/mob/combat_indicator.dmi | Edited by PuroSlavKing (Github)",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "combat_mode",
"delays": [
[
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1
]
]
}
]
}
Loading