mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Add cvar_subs command
Dumb little thing, just wanted to test something.
This commit is contained in:
@@ -43,6 +43,13 @@ cmd-cvar-compl-list = List available CVars
|
||||
cmd-cvar-arg-name = <name | ?>
|
||||
cmd-cvar-value-hidden = <value hidden>
|
||||
|
||||
## 'cvar_subs' command
|
||||
cmd-cvar_subs-desc = Lists the OnValueChanged subscriptions for a CVar.
|
||||
cmd-cvar_subs-help = Usage: cvar_subs <name>
|
||||
|
||||
cmd-cvar_subs-invalid-args = Must provide exactly one argument.
|
||||
cmd-cvar_subs-arg-name = <name>
|
||||
|
||||
## 'list' command
|
||||
cmd-list-desc = Lists available commands, with optional search filter
|
||||
cmd-list-help = Usage: list [filter]
|
||||
|
||||
@@ -140,4 +140,47 @@ namespace Robust.Shared.Configuration
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class CVarSubsCommand : LocalizedCommands
|
||||
{
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
|
||||
public override string Command => "cvar_subs";
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length < 1)
|
||||
{
|
||||
shell.WriteError(Loc.GetString("cmd-cvar_subs-invalid-args"));
|
||||
return;
|
||||
}
|
||||
|
||||
var name = args[0];
|
||||
var subs = ((ConfigurationManager)_cfg).GetSubs(name);
|
||||
|
||||
foreach (var @delegate in subs)
|
||||
{
|
||||
shell.WriteLine(ShowDelegateInfo(@delegate));
|
||||
}
|
||||
}
|
||||
|
||||
private static string ShowDelegateInfo(Delegate del)
|
||||
{
|
||||
return $"{del}: {del.Method} -> {del.Target}";
|
||||
}
|
||||
|
||||
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||
{
|
||||
if (args.Length == 1)
|
||||
{
|
||||
return CompletionResult.FromHintOptions(
|
||||
_cfg.GetRegisteredCVars()
|
||||
.Select(c => new CompletionOption(c))
|
||||
.OrderBy(c => c.Value),
|
||||
Loc.GetString("cmd-cvar_subs-arg-name"));
|
||||
}
|
||||
|
||||
return CompletionResult.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -777,6 +777,24 @@ namespace Robust.Shared.Configuration
|
||||
return Convert.ChangeType(value, cVar);
|
||||
}
|
||||
|
||||
internal List<Delegate> GetSubs(string name)
|
||||
{
|
||||
using (Lock.ReadGuard())
|
||||
{
|
||||
var list = new List<Delegate>();
|
||||
|
||||
if (!_configVars.TryGetValue(name, out var cVar))
|
||||
throw new InvalidConfigurationException($"Trying to get unregistered variable '{name}'");
|
||||
|
||||
foreach (var entry in cVar.ValueChanged.Entries)
|
||||
{
|
||||
list.Add((Delegate) entry.Equality!);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Holds the data for a single configuration variable.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user