Skip to content

Commit

Permalink
Add the ability to debug turf icons
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit committed Jan 1, 2025
1 parent 719f315 commit dce94c8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
57 changes: 43 additions & 14 deletions OpenDreamClient/Input/ContextMenu/VerbMenuPopup.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using OpenDreamClient.Rendering;
using OpenDreamShared.Dream;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Client.ViewVariables;
using Robust.Shared.Map;

namespace OpenDreamClient.Input.ContextMenu;

Expand Down Expand Up @@ -40,26 +42,53 @@ public VerbMenuPopup(ClientVerbSystem? verbSystem, sbyte seeInvisible, ClientObj
}

#if TOOLS
// If we're compiling with TOOLS and this is an entity, provide the option to use RT's VV or our icon debugger
// We add some additional debugging tools in TOOLS mode
var iconDebugButton = AddButton("Debug Icon");

iconDebugButton.OnPressed += _ => {
DreamIcon icon;
switch (_target.Type) {
case ClientObjectReference.RefType.Entity:
var entityManager = IoCManager.Resolve<IEntityManager>();
var entityId = entityManager.GetEntity(_target.Entity);
if (!entityManager.TryGetComponent(entityId, out DMISpriteComponent? spriteComponent)) {
Logger.GetSawmill("opendream")
.Error($"Failed to get sprite component for {entityId} when trying to debug its icon");
return;
}

icon = spriteComponent.Icon;
break;
case ClientObjectReference.RefType.Turf:
var mapManager = IoCManager.Resolve<IMapManager>();
var mapId = new MapId(_target.TurfZ);
var mapPos = new Vector2(_target.TurfX - 1, _target.TurfY - 1);
if (!mapManager.TryFindGridAt(mapId, mapPos, out var gridUid, out var grid)) {
Logger.GetSawmill("opendream")
.Error($"Failed to get icon for {_target} when trying to debug its icon");
return;
}

var entitySystemManager = IoCManager.Resolve<IEntitySystemManager>();
var mapSystem = entitySystemManager.GetEntitySystem<MapSystem>();
var appearanceSystem = entitySystemManager.GetEntitySystem<ClientAppearanceSystem>();
var tileRef = mapSystem.GetTileRef(gridUid, grid, (Vector2i)mapPos);
icon = appearanceSystem.GetTurfIcon((uint)tileRef.Tile.TypeId);
break;
default:
return;
}

new IconDebugWindow(icon).Show();
};

// If this is an entity, provide the option to use RT's VV
if (_target.Type == ClientObjectReference.RefType.Entity) {
var viewVariablesButton = AddButton("RT ViewVariables");
var iconDebugButton = AddButton("Debug Icon");

viewVariablesButton.OnPressed += _ => {
IoCManager.Resolve<IClientViewVariablesManager>().OpenVV(_target.Entity);
};

iconDebugButton.OnPressed += _ => {
var entityManager = IoCManager.Resolve<IEntityManager>();
var entityId = entityManager.GetEntity(_target.Entity);
if (!entityManager.TryGetComponent(entityId, out DMISpriteComponent? spriteComponent)) {
Logger.GetSawmill("opendream")
.Error($"Failed to get sprite component for {entityId} when trying to debug its icon");
return;
}

new IconDebugWindow(spriteComponent.Icon).Show();
};
}
#endif
}
Expand Down
13 changes: 13 additions & 0 deletions OpenDreamShared/Dream/ClientObjectReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,17 @@ public bool Equals(ClientObjectReference? other) {

return Equals(other.Value);
}

public override string ToString() {
switch (Type) {
case RefType.Client:
return "client";
case RefType.Turf:
return $"turf{{{TurfX},{TurfY},{TurfZ}}}";
case RefType.Entity:
return $"entity{{{Entity}}}";
}

return "unknown ClientObjectReference";
}
}

0 comments on commit dce94c8

Please sign in to comment.