forked from space-wizards/RobustToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugAnchoringSystem.cs
More file actions
98 lines (81 loc) · 2.78 KB
/
Copy pathDebugAnchoringSystem.cs
File metadata and controls
98 lines (81 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#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 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 (!_mapSystem.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