Skip to content

Commit

Permalink
Hunger and thirst huds fix (#32832)
Browse files Browse the repository at this point in the history
* Hunger and thirst huds fix

* delete poor caching
  • Loading branch information
Kirus59 authored Nov 5, 2024
1 parent aef7dd5 commit cb59826
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Content.Client/Overlays/ShowThirstIconsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ private void OnGetStatusIconsEvent(EntityUid uid, ThirstComponent component, ref
return;

if (_thirst.TryGetStatusIconPrototype(component, out var iconPrototype))
ev.StatusIcons.Add(iconPrototype!);
ev.StatusIcons.Add(iconPrototype);
}
}
14 changes: 3 additions & 11 deletions Content.Shared/Nutrition/EntitySystems/HungerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,10 @@ public sealed class HungerSystem : EntitySystem
[ValidatePrototypeId<SatiationIconPrototype>]
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<HungerComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<HungerComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<HungerComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
Expand Down Expand Up @@ -221,13 +213,13 @@ public bool TryGetStatusIconPrototype(HungerComponent component, [NotNullWhen(tr
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;
Expand Down
27 changes: 11 additions & 16 deletions Content.Shared/Nutrition/EntitySystems/ThirstSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using System.Diagnostics.CodeAnalysis;

namespace Content.Shared.Nutrition.EntitySystems;

Expand All @@ -31,18 +32,10 @@ public sealed class ThirstSystem : EntitySystem
[ValidatePrototypeId<SatiationIconPrototype>]
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<ThirstComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
SubscribeLocalEvent<ThirstComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<ThirstComponent, RejuvenateEvent>(OnRejuvenate);
Expand Down Expand Up @@ -128,26 +121,28 @@ private bool IsMovementThreshold(ThirstThreshold threshold)
}
}

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)
Expand Down

0 comments on commit cb59826

Please sign in to comment.