Skip to content

Commit

Permalink
Update Debug Info generation for MonkeyLoader standard
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Jan 13, 2025
1 parent 02812ab commit 9d0695a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 21 deletions.
17 changes: 17 additions & 0 deletions DynamicVariablePowerTools/DebugInfoConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using MonkeyLoader.Configuration;
using System;

namespace DynamicVariablePowerTools
{
internal sealed class DebugInfoConfig : ConfigSection
{
private static readonly DefiningConfigKey<bool> _enableLinkedComponentHierarchy = new("EnableLinkedComponentHierarchy", "Allow generating a hierarchical list of all dynamic variable components linked to a space.", () => true);
private static readonly DefiningConfigKey<bool> _enableLinkedVariablesList = new("EnableLinkedVariablesList", "Allow generating a list of all dynamic variable definitions linked to a space.", () => true);
public override string Description => "Contains the options for the available debug info buttons on DynamicVariableSpace Components.";

public bool EnableLinkedComponentHierarchy => _enableLinkedComponentHierarchy;
public bool EnableLinkedVariablesList => _enableLinkedVariablesList;
public override string Id => "DebugInfo";
public override Version Version { get; } = new Version(1, 0, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using FrooxEngine;
using FrooxEngine.UIX;
using MonkeyLoader.Resonite;
using MonkeyLoader.Resonite.UI;

namespace DynamicVariablePowerTools
{
internal sealed class DynVarSpaceTree : ResoniteInspectorMonkey<DynVarSpaceTree, BuildInspectorBodyEvent, DynamicVariableSpace>
internal sealed class DebugInfoGenerator : ConfiguredResoniteInspectorMonkey<DebugInfoGenerator, DebugInfoConfig, BuildInspectorBodyEvent, DynamicVariableSpace>
{
//[AutoRegisterConfigKey]
//private static readonly ModConfigurationKey<bool> EnableLinkedVariablesList = new("EnableLinkedVariablesList", "Allow generating a list of dynamic variable definitions for a space.", () => true);

//[AutoRegisterConfigKey]
//private static readonly ModConfigurationKey<bool> EnableVariableHierarchy = new("EnableVariableHierarchy", "Allow generating a hierarchy of dynamic variable components for a space.", () => true);
/// <inheritdoc/>
public override bool CanBeDisabled => true;

/// <inheritdoc/>
public override int Priority => -HarmonyLib.Priority.High;

/// <inheritdoc/>
Expand All @@ -28,16 +25,22 @@ protected override void Handle(BuildInspectorBodyEvent eventData)

var outputField = ui.Current.AttachComponent<ValueField<string>>();

//if (Config.GetValue(EnableLinkedVariablesList))
ui.LocalActionButton("Output names of linked Variables", _ => OutputVariableNames(space, outputField.Value));
if (ConfigSection.EnableLinkedVariablesList)
{
ui.LocalActionButton(Mod.GetLocaleString("EnableLinkedVariablesList.Button"), _ => OutputLinkedVariables(space, outputField.Value))
.WithTooltip(Mod.GetLocaleString("EnableLinkedVariablesList.Tooltip"));
}

//if (Config.GetValue(EnableVariableHierarchy))
ui.LocalActionButton("Output tree of linked Variable Hierarchy", _ => OutputVariableHierarchy(space, outputField.Value));
if (ConfigSection.EnableLinkedComponentHierarchy)
{
ui.LocalActionButton(Mod.GetLocaleString("EnableLinkedComponentHierarchy.Button"), _ => OutputComponentHierarchy(space, outputField.Value))
.WithTooltip(Mod.GetLocaleString("EnableLinkedComponentHierarchy.Tooltip"));
}

SyncMemberEditorBuilder.Build(outputField.Value, "Output", outputField.GetSyncMemberFieldInfo("Value"), ui);
}

private static void OutputVariableHierarchy(DynamicVariableSpace space, Sync<string> target)
private static void OutputComponentHierarchy(DynamicVariableSpace space, Sync<string> target)
{
space.StartTask(async () =>
{
Expand All @@ -52,9 +55,9 @@ private static void OutputVariableHierarchy(DynamicVariableSpace space, Sync<str
});
}

private static void OutputVariableNames(DynamicVariableSpace space, Sync<string> target)
private static void OutputLinkedVariables(DynamicVariableSpace space, Sync<string> target)
{
var names = new StringBuilder("Variables linked to Namespace ");
var names = new StringBuilder($"Variables linked to Namespace [{space.SpaceName}] on {space.Slot.Name}");
names.Append(space.SpaceName);
names.AppendLine(":");

Expand Down
13 changes: 11 additions & 2 deletions DynamicVariablePowerTools/Locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
"localeCode": "en",
"authors": [ "Banane9" ],
"messages": {
"FlexibleContactsSort.Pin": "Pin Contact",
"FlexibleContactsSort.Unpin": "Unpin Contact"
"DynamicVariablePowerTools.EnableLinkedVariablesList.Name": "Variable Definitions",
"DynamicVariablePowerTools.EnableLinkedVariablesList.Description": "Allow generating a list of all dynamic variable definitions linked to a space.",
"DynamicVariablePowerTools.EnableLinkedVariablesList.Button": "Output Variable Definitions",
"DynamicVariablePowerTools.EnableLinkedVariablesList.Tooltip": "Generates a list of all dynamic variable definitions linked to this space in the <i>Output</i> field.",

"DynamicVariablePowerTools.EnableLinkedComponentHierarchy.Name": "Component Hierarchy",
"DynamicVariablePowerTools.EnableLinkedComponentHierarchy.Description": "Allow generating a hierarchical list of all dynamic variable components linked to a space.",
"DynamicVariablePowerTools.EnableLinkedComponentHierarchy.Button": "Output Component Hierarchy",
"DynamicVariablePowerTools.EnableLinkedComponentHierarchy.Tooltip": "Generates a hierarchical list of all dynamic variable components linked to this space in the <i>Output</i> field.",

"DynamicVariablePowerTools.DebugInfo.Name": "Debug Info"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace DynamicVariablePowerTools
{
[HarmonyPatchCategory(nameof(RenameDirectlyLinkedDynVars))]
[HarmonyPatchCategory(nameof(RenameDirectlyLinkedVariables))]
[HarmonyPatch(typeof(DynamicVariableSpace), nameof(DynamicVariableSpace.UpdateName))]
internal sealed class RenameDirectlyLinkedDynVars : ResoniteMonkey<RenameDirectlyLinkedDynVars>
internal sealed class RenameDirectlyLinkedVariables : ResoniteMonkey<RenameDirectlyLinkedVariables>
{
//[AutoRegisterConfigKey]
//private static ModConfigurationKey<bool> ChangeDynVarNamespaces = new ModConfigurationKey<bool>("ChangeDynVarNamespaces", "Enable searching and renaming directly linked variables and drivers when namespace changes.", () => false);
Expand Down
6 changes: 4 additions & 2 deletions DynamicVariablePowerTools/SpaceTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Text;
using System.Threading.Tasks;
using FrooxEngine;
using HarmonyLib;

namespace DynamicVariablePowerTools
{
Expand Down Expand Up @@ -32,7 +31,10 @@ public bool Process()

public override string ToString()
{
var builder = new StringBuilder(_space.Slot.Name).Append(": Namespace ").AppendLine(_space.SpaceName);
var builder = new StringBuilder("Hierarchy of linked dynamic variable components of Namespace [")
.Append(_space.SpaceName)
.Append("] on ")
.AppendLine(_space.Slot.Name);

BuildString(builder, "");
builder.Remove(builder.Length - Environment.NewLine.Length, Environment.NewLine.Length);
Expand Down

0 comments on commit 9d0695a

Please sign in to comment.