Refactor status icons take 2, cyborgs don't see criminal status (#26207)

* Initial commit.

* review

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Krunklehorn
2024-04-17 23:20:44 -04:00
committed by GitHub
parent 020f322e27
commit 460b588de5
19 changed files with 266 additions and 203 deletions

View File

@@ -1,17 +1,22 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Alert;
using Content.Shared.Damage;
using Content.Shared.Mobs.Systems;
using Content.Shared.Movement.Systems;
using Content.Shared.Nutrition.Components;
using Content.Shared.Rejuvenate;
using Content.Shared.StatusIcon;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Shared.Nutrition.EntitySystems;
public sealed class HungerSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
@@ -19,10 +24,27 @@ public sealed class HungerSystem : EntitySystem
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifier = default!;
[Dependency] private readonly SharedJetpackSystem _jetpack = default!;
[ValidatePrototypeId<StatusIconPrototype>]
private const string HungerIconOverfedId = "HungerIconOverfed";
[ValidatePrototypeId<StatusIconPrototype>]
private const string HungerIconPeckishId = "HungerIconPeckish";
[ValidatePrototypeId<StatusIconPrototype>]
private const string HungerIconStarvingId = "HungerIconStarving";
private StatusIconPrototype? _hungerIconOverfed;
private StatusIconPrototype? _hungerIconPeckish;
private StatusIconPrototype? _hungerIconStarving;
public override void Initialize()
{
base.Initialize();
DebugTools.Assert(_prototype.TryIndex(HungerIconOverfedId, out _hungerIconOverfed) &&
_prototype.TryIndex(HungerIconPeckishId, out _hungerIconPeckish) &&
_prototype.TryIndex(HungerIconStarvingId, out _hungerIconStarving));
SubscribeLocalEvent<HungerComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<HungerComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<HungerComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
@@ -194,6 +216,27 @@ public sealed class HungerSystem : EntitySystem
}
}
public bool TryGetStatusIconPrototype(HungerComponent component, [NotNullWhen(true)] out StatusIconPrototype? prototype)
{
switch (component.CurrentThreshold)
{
case HungerThreshold.Overfed:
prototype = _hungerIconOverfed;
break;
case HungerThreshold.Peckish:
prototype = _hungerIconPeckish;
break;
case HungerThreshold.Starving:
prototype = _hungerIconStarving;
break;
default:
prototype = null;
break;
}
return prototype != null;
}
public override void Update(float frameTime)
{
base.Update(frameTime);