Gas analyzer compref removal (#17992)

* Gas analyzer compref removal

* don't question it
This commit is contained in:
Nemanja
2023-07-12 15:47:45 -04:00
committed by GitHub
parent 65d069a203
commit 37e6d99e49
7 changed files with 151 additions and 164 deletions

View File

@@ -9,8 +9,7 @@ using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Player;
using static Content.Shared.Atmos.Components.SharedGasAnalyzerComponent;
using static Content.Shared.Atmos.Components.GasAnalyzerComponent;
namespace Content.Server.Atmos.EntitySystems
{
@@ -21,6 +20,7 @@ namespace Content.Server.Atmos.EntitySystems
[Dependency] private readonly AtmosphereSystem _atmo = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly UserInterfaceSystem _userInterface = default!;
[Dependency] private readonly TransformSystem _transform = default!;
public override void Initialize()
{
@@ -34,8 +34,8 @@ namespace Content.Server.Atmos.EntitySystems
public override void Update(float frameTime)
{
foreach (var analyzer in EntityQuery<ActiveGasAnalyzerComponent>())
var query = EntityQueryEnumerator<ActiveGasAnalyzerComponent>();
while (query.MoveNext(out var uid, out var analyzer))
{
// Don't update every tick
analyzer.AccumulatedFrametime += frameTime;
@@ -45,8 +45,8 @@ namespace Content.Server.Atmos.EntitySystems
analyzer.AccumulatedFrametime -= analyzer.UpdateInterval;
if (!UpdateAnalyzer(analyzer.Owner))
RemCompDeferred<ActiveGasAnalyzerComponent>(analyzer.Owner);
if (!UpdateAnalyzer(uid))
RemCompDeferred<ActiveGasAnalyzerComponent>(uid);
}
}
@@ -61,7 +61,7 @@ namespace Content.Server.Atmos.EntitySystems
return;
}
ActivateAnalyzer(uid, component, args.User, args.Target);
OpenUserInterface(args.User, component);
OpenUserInterface(uid, args.User, component);
args.Handled = true;
}
@@ -87,7 +87,7 @@ namespace Content.Server.Atmos.EntitySystems
component.LastPosition = null;
component.Enabled = true;
Dirty(component);
UpdateAppearance(component);
UpdateAppearance(uid, component);
if(!HasComp<ActiveGasAnalyzerComponent>(uid))
AddComp<ActiveGasAnalyzerComponent>(uid);
UpdateAnalyzer(uid, component);
@@ -98,7 +98,7 @@ namespace Content.Server.Atmos.EntitySystems
/// </summary>
private void OnDropped(EntityUid uid, GasAnalyzerComponent component, DroppedEvent args)
{
if(args.User is { } userId && component.Enabled)
if(args.User is var userId && component.Enabled)
_popup.PopupEntity(Loc.GetString("gas-analyzer-shutoff"), userId, userId);
DisableAnalyzer(uid, component, args.User);
}
@@ -116,7 +116,7 @@ namespace Content.Server.Atmos.EntitySystems
component.Enabled = false;
Dirty(component);
UpdateAppearance(component);
UpdateAppearance(uid, component);
RemCompDeferred<ActiveGasAnalyzerComponent>(uid);
}
@@ -130,12 +130,15 @@ namespace Content.Server.Atmos.EntitySystems
DisableAnalyzer(uid, component);
}
private void OpenUserInterface(EntityUid user, GasAnalyzerComponent component)
private void OpenUserInterface(EntityUid uid, EntityUid user, GasAnalyzerComponent? component = null)
{
if (!Resolve(uid, ref component, false))
return;
if (!TryComp<ActorComponent>(user, out var actor))
return;
_userInterface.TryOpen(component.Owner, GasAnalyzerUiKey.Key, actor.PlayerSession);
_userInterface.TryOpen(uid, GasAnalyzerUiKey.Key, actor.PlayerSession);
}
/// <summary>
@@ -157,7 +160,7 @@ namespace Content.Server.Atmos.EntitySystems
if (component.LastPosition.HasValue)
{
// Check if position is out of range => don't update and disable
if (!component.LastPosition.Value.InRange(EntityManager, userPos, SharedInteractionSystem.InteractionRange))
if (!component.LastPosition.Value.InRange(EntityManager, _transform, userPos, SharedInteractionSystem.InteractionRange))
{
if(component.User is { } userId && component.Enabled)
_popup.PopupEntity(Loc.GetString("gas-analyzer-shutoff"), userId, userId);
@@ -169,7 +172,7 @@ namespace Content.Server.Atmos.EntitySystems
var gasMixList = new List<GasMixEntry>();
// Fetch the environmental atmosphere around the scanner. This must be the first entry
var tileMixture = _atmo.GetContainingMixture(component.Owner, true);
var tileMixture = _atmo.GetContainingMixture(uid, true);
if (tileMixture != null)
{
gasMixList.Add(new GasMixEntry(Loc.GetString("gas-analyzer-window-environment-tab-label"), tileMixture.Pressure, tileMixture.Temperature,
@@ -193,7 +196,7 @@ namespace Content.Server.Atmos.EntitySystems
// gas analyzed was used on an entity, try to request gas data via event for override
var ev = new GasAnalyzerScanEvent();
RaiseLocalEvent(component.Target.Value, ev, false);
RaiseLocalEvent(component.Target.Value, ev);
if (ev.GasMixtures != null)
{
@@ -223,7 +226,7 @@ namespace Content.Server.Atmos.EntitySystems
if (gasMixList.Count == 0)
return false;
_userInterface.TrySendUiMessage(component.Owner, GasAnalyzerUiKey.Key,
_userInterface.TrySendUiMessage(uid, GasAnalyzerUiKey.Key,
new GasAnalyzerUserMessage(gasMixList.ToArray(),
component.Target != null ? Name(component.Target.Value) : string.Empty,
component.Target ?? EntityUid.Invalid,
@@ -234,9 +237,9 @@ namespace Content.Server.Atmos.EntitySystems
/// <summary>
/// Sets the appearance based on the analyzers Enabled state
/// </summary>
private void UpdateAppearance(GasAnalyzerComponent analyzer)
private void UpdateAppearance(EntityUid uid, GasAnalyzerComponent analyzer)
{
_appearance.SetData(analyzer.Owner, GasAnalyzerVisuals.Enabled, analyzer.Enabled);
_appearance.SetData(uid, GasAnalyzerVisuals.Enabled, analyzer.Enabled);
}
/// <summary>