Files
RobustToolbox/Robust.Client/Debugging/DebugAnchoringSystem.cs
T
83c2a1be11 [Dependency] source generator part 2 (#6550)
* [Dependency] source generator

No more reflection, no more codegen at runtime

Also various changes to Roslyn helpers to make this easier to write.

Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback.

No fallback is available for [field: Dependency] properties, due to a Roslyn bug.

Code Fixes exist. We love Roslyn

* Apply dependencies generator changes to all code

* Release notes

* Preprocessor got hands

* Handle nullable dependencies

These are bad but gotta deal with it.

* Apply suggestions from code review

Co-authored-by: Moony <moony@hellomouse.net>

* Fine, let's not use collection expressions

---------

Co-authored-by: Moony <moony@hellomouse.net>
2026-05-08 12:38:33 +02:00

100 lines
2.8 KiB
C#

#if DEBUG
using System.Numerics;
using System.Text;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Utility;
namespace Robust.Client.Debugging
{
public sealed partial class DebugAnchoringSystem : EntitySystem
{
[Dependency] private IEyeManager _eyeManager = default!;
[Dependency] private IInputManager _inputManager = default!;
[Dependency] private IMapManager _mapManager = default!;
[Dependency] private IUserInterfaceManager _userInterface = default!;
[Dependency] private MapSystem _mapSystem = default!;
private Label? _label;
private (EntityUid GridId, TileRef Tile)? _hovered;
public bool Enabled
{
get => _enabled;
set
{
if (_enabled == value) return;
_enabled = value;
if (_enabled)
{
_label = new Label();
_userInterface.StateRoot.AddChild(_label);
}
else
{
_userInterface.StateRoot.RemoveChild(_label!);
_label = null;
_hovered = null;
}
}
}
private bool _enabled;
public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);
if (!Enabled) return;
if (_label == null)
{
DebugTools.Assert($"Debug Label for {nameof(DebugAnchoringSystem)} is null!");
return;
}
var mouseSpot = _inputManager.MouseScreenPosition;
var spot = _eyeManager.PixelToMap(mouseSpot);
if (!_mapManager.TryFindGridAt(spot, out var gridUid, out var grid))
{
_label.Text = string.Empty;
_hovered = null;
return;
}
var tile = _mapSystem.GetTileRef(gridUid, grid, spot);
_label.Position = mouseSpot.Position + new Vector2(32, 0);
if (_hovered?.GridId == gridUid && _hovered?.Tile == tile) return;
_hovered = (gridUid, tile);
var text = new StringBuilder();
foreach (var ent in _mapSystem.GetAnchoredEntities(gridUid, grid, spot))
{
if (TryComp(ent, out MetaDataComponent? meta))
{
text.AppendLine($"uid: {ent}, {meta.EntityName}");
}
else
{
text.AppendLine($"uid: {ent}, invalid");
}
}
_label.Text = text.ToString();
}
}
}
#endif