From cb59826dcb5e1182a2fa8aaa511bc27ffcf6b98b Mon Sep 17 00:00:00 2001 From: Kirus59 <145689588+Kirus59@users.noreply.github.com> Date: Tue, 5 Nov 2024 19:58:23 +0300 Subject: [PATCH] Hunger and thirst huds fix (#32832) * Hunger and thirst huds fix * delete poor caching --- .../Overlays/ShowThirstIconsSystem.cs | 2 +- .../Nutrition/EntitySystems/HungerSystem.cs | 14 +++------- .../Nutrition/EntitySystems/ThirstSystem.cs | 27 ++++++++----------- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/Content.Client/Overlays/ShowThirstIconsSystem.cs b/Content.Client/Overlays/ShowThirstIconsSystem.cs index 44be1f7a67..9fc64165c5 100644 --- a/Content.Client/Overlays/ShowThirstIconsSystem.cs +++ b/Content.Client/Overlays/ShowThirstIconsSystem.cs @@ -22,6 +22,6 @@ public sealed class ShowThirstIconsSystem : EquipmentHudSystem] private const string HungerIconStarvingId = "HungerIconStarving"; - private SatiationIconPrototype? _hungerIconOverfed; - private SatiationIconPrototype? _hungerIconPeckish; - private SatiationIconPrototype? _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(OnMapInit); SubscribeLocalEvent(OnShutdown); SubscribeLocalEvent(OnRefreshMovespeed); @@ -221,13 +213,13 @@ public sealed class HungerSystem : EntitySystem switch (component.CurrentThreshold) { case HungerThreshold.Overfed: - prototype = _hungerIconOverfed; + _prototype.TryIndex(HungerIconOverfedId, out prototype); break; case HungerThreshold.Peckish: - prototype = _hungerIconPeckish; + _prototype.TryIndex(HungerIconPeckishId, out prototype); break; case HungerThreshold.Starving: - prototype = _hungerIconStarving; + _prototype.TryIndex(HungerIconStarvingId, out prototype); break; default: prototype = null; diff --git a/Content.Shared/Nutrition/EntitySystems/ThirstSystem.cs b/Content.Shared/Nutrition/EntitySystems/ThirstSystem.cs index aa704354ba..0b2bb2e0ef 100644 --- a/Content.Shared/Nutrition/EntitySystems/ThirstSystem.cs +++ b/Content.Shared/Nutrition/EntitySystems/ThirstSystem.cs @@ -9,6 +9,7 @@ using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Timing; using Robust.Shared.Utility; +using System.Diagnostics.CodeAnalysis; namespace Content.Shared.Nutrition.EntitySystems; @@ -31,18 +32,10 @@ public sealed class ThirstSystem : EntitySystem [ValidatePrototypeId] private const string ThirstIconParchedId = "ThirstIconParched"; - private SatiationIconPrototype? _thirstIconOverhydrated = null; - private SatiationIconPrototype? _thirstIconThirsty = null; - private SatiationIconPrototype? _thirstIconParched = null; - public override void Initialize() { base.Initialize(); - DebugTools.Assert(_prototype.TryIndex(ThirstIconOverhydratedId, out _thirstIconOverhydrated) && - _prototype.TryIndex(ThirstIconThirstyId, out _thirstIconThirsty) && - _prototype.TryIndex(ThirstIconParchedId, out _thirstIconParched)); - SubscribeLocalEvent(OnRefreshMovespeed); SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnRejuvenate); @@ -128,26 +121,28 @@ public sealed class ThirstSystem : EntitySystem } } - public bool TryGetStatusIconPrototype(ThirstComponent component, out SatiationIconPrototype? prototype) + public bool TryGetStatusIconPrototype(ThirstComponent component, [NotNullWhen(true)] out SatiationIconPrototype? prototype) { switch (component.CurrentThirstThreshold) { case ThirstThreshold.OverHydrated: - prototype = _thirstIconOverhydrated; - return true; + _prototype.TryIndex(ThirstIconOverhydratedId, out prototype); + break; case ThirstThreshold.Thirsty: - prototype = _thirstIconThirsty; - return true; + _prototype.TryIndex(ThirstIconThirstyId, out prototype); + break; case ThirstThreshold.Parched: - prototype = _thirstIconParched; - return true; + _prototype.TryIndex(ThirstIconParchedId, out prototype); + break; default: prototype = null; - return false; + break; } + + return prototype != null; } private void UpdateEffects(EntityUid uid, ThirstComponent component)