Files
RobustToolbox/Robust.Client/ViewVariables/ViewVariablesCommand.cs
Pieter-Jan Briers 13ef4e8423 Various optimizations focused on the entity spawn panel:
Give BoxContainer a preset capacity to reduce allocations in layout.

Removed Control.GetChild(string) and similar. This was no longer used (and was a pretty bad idea in general), and the implementation had a lot of wasted book keeping to do.

Use UpdateLayout() instead of DoUpdateLayout() in Control minsize changed to avoid doing redundant layout, and by extension style & minsize, updates.

Used RemoveAllChildren instead of DisposeAllChildren in EntitySpawnWindow because it's faster (way less stuff to clear, just let the GC handle it).

Optimized ResourcePath with a better GetHashCode(), better Equals, replacement for List<T>.ToArray()

Fixed enumerator allocations in stylesheet SelectorElement matching to speed up style updates.

ResourceCache now caches fallbacks to avoid constructing Resource instance when fetching fallback explicitly.

ResourceCache now has nested dictionaries for Type -> ResourcePath -> BaseResource storage of resources.

Use calculated property instead of auto property for TextureResource.Fallback
2019-11-28 14:19:02 +01:00

125 lines
3.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using Robust.Client.Interfaces.Console;
using Robust.Client.Interfaces.UserInterface;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Reflection;
using Robust.Shared.IoC;
using Robust.Shared.IoC.Exceptions;
using Robust.Shared.Maths;
using Robust.Shared.ViewVariables;
namespace Robust.Client.ViewVariables
{
[UsedImplicitly]
public class ViewVariablesCommand : IConsoleCommand
{
public string Command => "vv";
public string Description => "Opens View Variables.";
public string Help => "Usage: vv <entity ID|IoC interface name|SIoC interface name>";
public bool Execute(IDebugConsole console, params string[] args)
{
var vvm = IoCManager.Resolve<IViewVariablesManager>();
// If you don't provide an entity ID, it opens the test class.
// Spooky huh.
if (args.Length == 0)
{
vvm.OpenVV(new VVTest());
return false;
}
var valArg = args[0];
if (valArg.StartsWith("SI"))
{
// Server-side IoC selector.
var selector = new ViewVariablesIoCSelector(valArg.Substring(1));
vvm.OpenVV(selector);
return false;
}
if (valArg.StartsWith("I"))
{
// Client-side IoC selector.
var reflection = IoCManager.Resolve<IReflectionManager>();
if (!reflection.TryLooseGetType(valArg, out var type))
{
console.AddLine("Unable to find that type.");
return false;
}
object obj;
try
{
obj = IoCManager.ResolveType(type);
}
catch (UnregisteredTypeException)
{
console.AddLine("Unable to find that type.");
return false;
}
vvm.OpenVV(obj);
return false;
}
if (valArg.StartsWith("guihover"))
{
// UI element.
var obj = IoCManager.Resolve<IUserInterfaceManager>().CurrentlyHovered;
if (obj == null)
{
console.AddLine("Not currently hovering any control.");
}
vvm.OpenVV(obj);
return false;
}
// Entity.
if (!EntityUid.TryParse(args[0], out var uid))
{
console.AddLine("Invalid specifier format.");
return false;
}
var entityManager = IoCManager.Resolve<IEntityManager>();
if (!entityManager.TryGetEntity(uid, out var entity))
{
console.AddLine("That entity does not exist.");
return false;
}
vvm.OpenVV(entity);
return false;
}
/// <summary>
/// Test class to test local VV easily without connecting to the server.
/// </summary>
private class VVTest : IEnumerable<object>
{
[ViewVariables(VVAccess.ReadWrite)] private int x = 10;
[ViewVariables]
public Dictionary<object, object> Dict => new Dictionary<object, object> {{"a", "b"}, {"c", "d"}};
[ViewVariables]
public List<object> List => new List<object> {1, 2, 3, 4, 5, 6, 7, 8, 9, x, 11, 12, 13, 14, 15, this};
[ViewVariables] private Vector2 Vector = (50, 50);
public IEnumerator<object> GetEnumerator()
{
return List.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}
}