Skip to content

Commit

Permalink
fix: menu assets referenced by Menu Installer aren't renamed correctly
Browse files Browse the repository at this point in the history
Closes: #1414
  • Loading branch information
bdunderscore committed Feb 1, 2025
1 parent 428a2cc commit a6cde1f
Show file tree
Hide file tree
Showing 12 changed files with 596 additions and 20 deletions.
21 changes: 9 additions & 12 deletions Editor/BuildContext.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
using System;
#if MA_VRCSDK3_AVATARS
using VRC.SDK3.Avatars.Components;
using VRC.SDK3.Avatars.ScriptableObjects;
#endif
using System;
using System.Collections.Generic;
using nadena.dev.modular_avatar.animation;
using nadena.dev.ndmf;
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;

#if MA_VRCSDK3_AVATARS
using VRC.SDK3.Avatars.Components;
using VRC.SDK3.Avatars.ScriptableObjects;
#endif

using Object = UnityEngine.Object;

namespace nadena.dev.modular_avatar.core.editor
{
internal class BuildContext
{
internal readonly nadena.dev.ndmf.BuildContext PluginBuildContext;
internal readonly ndmf.BuildContext PluginBuildContext;

#if MA_VRCSDK3_AVATARS
internal VRCAvatarDescriptor AvatarDescriptor => PluginBuildContext.AvatarDescriptor;
Expand All @@ -31,7 +29,7 @@ internal class BuildContext
internal PathMappings PathMappings =>
PluginBuildContext.Extension<AnimationServicesContext>().PathMappings;

internal UnityEngine.Object AssetContainer => PluginBuildContext.AssetContainer;
internal Object AssetContainer => PluginBuildContext.AssetContainer;

private bool SaveImmediate = false;

Expand All @@ -44,13 +42,12 @@ internal readonly Dictionary<VRCExpressionsMenu, VRCExpressionsMenu> ClonedMenus
/// replace the source menu for the purposes of identifying any other MAMIs that might install to the same
/// menu asset.
/// </summary>
internal readonly Dictionary<ModularAvatarMenuInstaller, Action<VRCExpressionsMenu.Control>> PostProcessControls
= new Dictionary<ModularAvatarMenuInstaller, Action<VRCExpressionsMenu.Control>>();
internal readonly Dictionary<Object, Action<VRCExpressionsMenu.Control>> PostProcessControls = new();
#endif
public static implicit operator BuildContext(ndmf.BuildContext ctx) =>
ctx.Extension<ModularAvatarContext>().BuildContext;

public BuildContext(nadena.dev.ndmf.BuildContext PluginBuildContext)
public BuildContext(ndmf.BuildContext PluginBuildContext)
{
this.PluginBuildContext = PluginBuildContext;
}
Expand Down
23 changes: 15 additions & 8 deletions Editor/Menu/VirtualMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using UnityEngine;
using VRC.SDK3.Avatars.Components;
using VRC.SDK3.Avatars.ScriptableObjects;
using Object = UnityEngine.Object;

namespace nadena.dev.modular_avatar.core.editor.menu
{
Expand Down Expand Up @@ -41,9 +42,9 @@ internal delegate VirtualMenuNode
private readonly ImmutableDictionary<object, ImmutableList<ModularAvatarMenuInstaller>>
_menuToInstallerMap;

private readonly ImmutableDictionary<ModularAvatarMenuInstaller, Action<VRCExpressionsMenu.Control>>
private readonly ImmutableDictionary<Object, Action<VRCExpressionsMenu.Control>>
_postProcessControls
= ImmutableDictionary<ModularAvatarMenuInstaller, Action<VRCExpressionsMenu.Control>>.Empty;
= ImmutableDictionary<Object, Action<VRCExpressionsMenu.Control>>.Empty;

private readonly VirtualMenuNode _node;
private readonly NodeForDelegate _nodeFor;
Expand Down Expand Up @@ -76,7 +77,7 @@ public NodeContextImpl(
VirtualMenuNode node,
NodeForDelegate nodeFor,
ImmutableDictionary<object, ImmutableList<ModularAvatarMenuInstaller>> menuToInstallerMap,
ImmutableDictionary<ModularAvatarMenuInstaller, Action<VRCExpressionsMenu.Control>> postProcessControls,
ImmutableDictionary<Object, Action<VRCExpressionsMenu.Control>> postProcessControls,
Action<VRCExpressionsMenu> visitedMenu,
Action<VRCExpressionsMenu.Control> postprocessor
)
Expand Down Expand Up @@ -128,7 +129,13 @@ public void PushNode(MenuSource source)
if (_visited.Contains(source)) return;
_visited.Add(source);

BuildReport.ReportingObject(source as UnityEngine.Object, () => source.Visit(this));
var sourceObj = source as Object;
var postProcessor = sourceObj != null ? _postProcessControls.GetValueOrDefault(sourceObj) : default;

using (new PostprocessorContext(this, postProcessor))
{
BuildReport.ReportingObject(source as Object, () => source.Visit(this));
}

_visited.Remove(source);
}
Expand Down Expand Up @@ -229,9 +236,9 @@ private Dictionary<object, List<ModularAvatarMenuInstaller>> _targetMenuToInstal
private Dictionary<ModularAvatarMenuInstaller, List<ModularAvatarMenuInstallTarget>> _installerToTargetComponent
= new Dictionary<ModularAvatarMenuInstaller, List<ModularAvatarMenuInstallTarget>>();

private ImmutableDictionary<ModularAvatarMenuInstaller, Action<VRCExpressionsMenu.Control>>
private ImmutableDictionary<Object, Action<VRCExpressionsMenu.Control>>
_postprocessControlsHooks =
ImmutableDictionary<ModularAvatarMenuInstaller, Action<VRCExpressionsMenu.Control>>.Empty;
ImmutableDictionary<Object, Action<VRCExpressionsMenu.Control>>.Empty;

private Dictionary<object, VirtualMenuNode> _resolvedMenu = new Dictionary<object, VirtualMenuNode>();

Expand Down Expand Up @@ -406,7 +413,7 @@ VirtualMenuNode NodeFor(object key, Action<VRCExpressionsMenu.Control> postproce

_pendingGeneration.Enqueue(() =>
{
BuildReport.ReportingObject(key as UnityEngine.Object, () =>
BuildReport.ReportingObject(key as Object, () =>
{
var context = new NodeContextImpl(node, NodeFor, menuToInstallerFiltered,
_postprocessControlsHooks,
Expand All @@ -431,7 +438,7 @@ VirtualMenuNode NodeFor(object key, Action<VRCExpressionsMenu.Control> postproce
}
}

internal VRCExpressionsMenu SerializeMenu(Action<UnityEngine.Object> SaveAsset)
internal VRCExpressionsMenu SerializeMenu(Action<Object> SaveAsset)
{
Dictionary<object, VRCExpressionsMenu> serializedMenus = new Dictionary<object, VRCExpressionsMenu>();

Expand Down
12 changes: 12 additions & 0 deletions Editor/RenameParametersHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,18 @@ GameObject obj
}
}

if (menuItem.Control.type == VRCExpressionsMenu.Control.ControlType.SubMenu)
{
_context.PostProcessControls.Add(menuItem, control =>
{
control.parameter.name = remap(remaps, control.parameter.name);
foreach (var subParam in control.subParameters)
{
subParam.name = remap(remaps, subParam.name);
}
});
}

break;
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a6cde1f

Please sign in to comment.