Hunger and thirst huds fix (#32832)
* Hunger and thirst huds fix * delete poor caching
This commit is contained in:
@@ -22,6 +22,6 @@ public sealed class ShowThirstIconsSystem : EquipmentHudSystem<ShowThirstIconsCo
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (_thirst.TryGetStatusIconPrototype(component, out var iconPrototype))
|
if (_thirst.TryGetStatusIconPrototype(component, out var iconPrototype))
|
||||||
ev.StatusIcons.Add(iconPrototype!);
|
ev.StatusIcons.Add(iconPrototype);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,18 +33,10 @@ public sealed class HungerSystem : EntitySystem
|
|||||||
[ValidatePrototypeId<SatiationIconPrototype>]
|
[ValidatePrototypeId<SatiationIconPrototype>]
|
||||||
private const string HungerIconStarvingId = "HungerIconStarving";
|
private const string HungerIconStarvingId = "HungerIconStarving";
|
||||||
|
|
||||||
private SatiationIconPrototype? _hungerIconOverfed;
|
|
||||||
private SatiationIconPrototype? _hungerIconPeckish;
|
|
||||||
private SatiationIconPrototype? _hungerIconStarving;
|
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.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, MapInitEvent>(OnMapInit);
|
||||||
SubscribeLocalEvent<HungerComponent, ComponentShutdown>(OnShutdown);
|
SubscribeLocalEvent<HungerComponent, ComponentShutdown>(OnShutdown);
|
||||||
SubscribeLocalEvent<HungerComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
|
SubscribeLocalEvent<HungerComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
|
||||||
@@ -221,13 +213,13 @@ public sealed class HungerSystem : EntitySystem
|
|||||||
switch (component.CurrentThreshold)
|
switch (component.CurrentThreshold)
|
||||||
{
|
{
|
||||||
case HungerThreshold.Overfed:
|
case HungerThreshold.Overfed:
|
||||||
prototype = _hungerIconOverfed;
|
_prototype.TryIndex(HungerIconOverfedId, out prototype);
|
||||||
break;
|
break;
|
||||||
case HungerThreshold.Peckish:
|
case HungerThreshold.Peckish:
|
||||||
prototype = _hungerIconPeckish;
|
_prototype.TryIndex(HungerIconPeckishId, out prototype);
|
||||||
break;
|
break;
|
||||||
case HungerThreshold.Starving:
|
case HungerThreshold.Starving:
|
||||||
prototype = _hungerIconStarving;
|
_prototype.TryIndex(HungerIconStarvingId, out prototype);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
prototype = null;
|
prototype = null;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using Robust.Shared.Prototypes;
|
|||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace Content.Shared.Nutrition.EntitySystems;
|
namespace Content.Shared.Nutrition.EntitySystems;
|
||||||
|
|
||||||
@@ -31,18 +32,10 @@ public sealed class ThirstSystem : EntitySystem
|
|||||||
[ValidatePrototypeId<SatiationIconPrototype>]
|
[ValidatePrototypeId<SatiationIconPrototype>]
|
||||||
private const string ThirstIconParchedId = "ThirstIconParched";
|
private const string ThirstIconParchedId = "ThirstIconParched";
|
||||||
|
|
||||||
private SatiationIconPrototype? _thirstIconOverhydrated = null;
|
|
||||||
private SatiationIconPrototype? _thirstIconThirsty = null;
|
|
||||||
private SatiationIconPrototype? _thirstIconParched = null;
|
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.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, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
|
||||||
SubscribeLocalEvent<ThirstComponent, MapInitEvent>(OnMapInit);
|
SubscribeLocalEvent<ThirstComponent, MapInitEvent>(OnMapInit);
|
||||||
SubscribeLocalEvent<ThirstComponent, RejuvenateEvent>(OnRejuvenate);
|
SubscribeLocalEvent<ThirstComponent, RejuvenateEvent>(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)
|
switch (component.CurrentThirstThreshold)
|
||||||
{
|
{
|
||||||
case ThirstThreshold.OverHydrated:
|
case ThirstThreshold.OverHydrated:
|
||||||
prototype = _thirstIconOverhydrated;
|
_prototype.TryIndex(ThirstIconOverhydratedId, out prototype);
|
||||||
return true;
|
break;
|
||||||
|
|
||||||
case ThirstThreshold.Thirsty:
|
case ThirstThreshold.Thirsty:
|
||||||
prototype = _thirstIconThirsty;
|
_prototype.TryIndex(ThirstIconThirstyId, out prototype);
|
||||||
return true;
|
break;
|
||||||
|
|
||||||
case ThirstThreshold.Parched:
|
case ThirstThreshold.Parched:
|
||||||
prototype = _thirstIconParched;
|
_prototype.TryIndex(ThirstIconParchedId, out prototype);
|
||||||
return true;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
prototype = null;
|
prototype = null;
|
||||||
return false;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return prototype != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateEffects(EntityUid uid, ThirstComponent component)
|
private void UpdateEffects(EntityUid uid, ThirstComponent component)
|
||||||
|
|||||||
Reference in New Issue
Block a user