From bb82e09cb3fd07739b6b2b09147cf3811ad60382 Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Tue, 24 Sep 2024 04:54:32 +0100 Subject: [PATCH] change _active to BurningComponent --- .../Nutrition/EntitySystems/SmokingSystem.cs | 25 ++++++------------- Content.Shared/Smoking/BurningComponent.cs | 10 ++++++++ 2 files changed, 17 insertions(+), 18 deletions(-) create mode 100644 Content.Shared/Smoking/BurningComponent.cs diff --git a/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs b/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs index 0d637139d82cb2..4b027b2977a882 100644 --- a/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/SmokingSystem.cs @@ -38,11 +38,6 @@ public sealed partial class SmokingSystem : EntitySystem private float _timer; - /// - /// We keep a list of active smokables, because iterating all existing smokables would be dumb. - /// - private readonly HashSet _active = new(); - public override void Initialize() { SubscribeLocalEvent(OnSmokableIsHotEvent); @@ -57,7 +52,7 @@ public override void Initialize() public void SetSmokableState(EntityUid uid, SmokableState state, SmokableComponent? smokable = null, AppearanceComponent? appearance = null, ClothingComponent? clothing = null) { - if (!Resolve(uid, ref smokable, ref appearance, ref clothing)) + if (!Resolve(uid, ref smokable, ref appearance, ref clothing) || smokable.State == state) return; smokable.State = state; @@ -74,9 +69,9 @@ public void SetSmokableState(EntityUid uid, SmokableState state, SmokableCompone _items.SetHeldPrefix(uid, newState); if (state == SmokableState.Lit) - _active.Add(uid); + EnsureComp(uid); else - _active.Remove(uid); + RemComp(uid); } private void OnSmokableIsHotEvent(Entity entity, ref IsHotEvent args) @@ -86,7 +81,7 @@ private void OnSmokableIsHotEvent(Entity entity, ref IsHotEve private void OnSmokableShutdownEvent(Entity entity, ref ComponentShutdown args) { - _active.Remove(entity); + RemComp(entity); } private void OnSmokeableEquipEvent(Entity entity, ref GotEquippedEvent args) @@ -104,18 +99,12 @@ public override void Update(float frameTime) if (_timer < UpdateTimer) return; - // TODO Use an "active smoke" component instead, EntityQuery over that. - foreach (var uid in _active.ToArray()) + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out _, out var smokable)) { - if (!TryComp(uid, out SmokableComponent? smokable)) - { - _active.Remove(uid); - continue; - } - if (!_solutionContainerSystem.TryGetSolution(uid, smokable.Solution, out var soln, out var solution)) { - _active.Remove(uid); + SetSmokableState(uid, SmokableState.Unlit, smokable); continue; } diff --git a/Content.Shared/Smoking/BurningComponent.cs b/Content.Shared/Smoking/BurningComponent.cs new file mode 100644 index 00000000000000..c279222998eb87 --- /dev/null +++ b/Content.Shared/Smoking/BurningComponent.cs @@ -0,0 +1,10 @@ +namespace Content.Shared.Smoking; + +/// +/// Marker component used to track active burning objects. +/// +/// +/// Right now only smoking uses this, but flammable could use it as well in the future. +/// +[RegisterComponent] +public sealed partial class BurningComponent : Component;