add comment.

This commit is contained in:
raiti-chan 2022-12-18 19:03:13 +09:00
parent 07b9d2ae7e
commit f2aed76c5c
2 changed files with 33 additions and 1 deletions

View File

@ -6,9 +6,17 @@ namespace nadena.dev.modular_avatar.core.editor
{ {
internal static class ClonedMenuMappings internal static class ClonedMenuMappings
{ {
/// <summary>
/// Map to link the cloned menu from the clone source.
/// If one menu is specified for multiple installers, they are replicated separately, so there is a one-to-many relationship.
/// </summary>
private static readonly Dictionary<VRCExpressionsMenu, ImmutableList<VRCExpressionsMenu>> ClonedMappings = private static readonly Dictionary<VRCExpressionsMenu, ImmutableList<VRCExpressionsMenu>> ClonedMappings =
new Dictionary<VRCExpressionsMenu, ImmutableList<VRCExpressionsMenu>>(); new Dictionary<VRCExpressionsMenu, ImmutableList<VRCExpressionsMenu>>();
/// <summary>
/// Map to link the clone source from the cloned menu.
/// Map is the opposite of ClonedMappings.
/// </summary>
private static readonly Dictionary<VRCExpressionsMenu, VRCExpressionsMenu> OriginalMapping = private static readonly Dictionary<VRCExpressionsMenu, VRCExpressionsMenu> OriginalMapping =
new Dictionary<VRCExpressionsMenu, VRCExpressionsMenu>(); new Dictionary<VRCExpressionsMenu, VRCExpressionsMenu>();

View File

@ -13,16 +13,29 @@ namespace nadena.dev.modular_avatar.core.editor
public struct ChildElement public struct ChildElement
{ {
/// <summary>
/// Parent menu control name
/// </summary>
public string menuName; public string menuName;
public VRCExpressionsMenu menu; public VRCExpressionsMenu menu;
public VRCExpressionsMenu parent; public VRCExpressionsMenu parent;
/// <summary>
/// Installer to install this menu. Is null if the this menu is not installed by the installer.
/// </summary>
public ModularAvatarMenuInstaller installer; public ModularAvatarMenuInstaller installer;
/// <summary>
/// Whether the this submenu is added directly by the installer
/// </summary>
public bool isInstallerRoot; public bool isInstallerRoot;
} }
private readonly HashSet<VRCExpressionsMenu> _included; private readonly HashSet<VRCExpressionsMenu> _included;
private readonly VRCExpressionsMenu _rootMenu; private readonly VRCExpressionsMenu _rootMenu;
/// <summary>
/// Map to link child menus from parent menu
/// </summary>
private readonly Dictionary<VRCExpressionsMenu, ImmutableList<ChildElement>> _menuChildrenMap; private readonly Dictionary<VRCExpressionsMenu, ImmutableList<ChildElement>> _menuChildrenMap;
public MenuTree(VRCAvatarDescriptor descriptor) public MenuTree(VRCAvatarDescriptor descriptor)
@ -33,6 +46,7 @@ namespace nadena.dev.modular_avatar.core.editor
if (_rootMenu == null) if (_rootMenu == null)
{ {
// If the route menu is null, create a temporary menu indicating the route
_rootMenu = ScriptableObject.CreateInstance<VRCExpressionsMenu>(); _rootMenu = ScriptableObject.CreateInstance<VRCExpressionsMenu>();
} }
@ -90,6 +104,7 @@ namespace nadena.dev.modular_avatar.core.editor
continue; continue;
} }
// One installer may add multiple children, so filter to return only one.
if (returnedInstallers.Contains(childElement.installer)) continue; if (returnedInstallers.Contains(childElement.installer)) continue;
returnedInstallers.Add(childElement.installer); returnedInstallers.Add(childElement.installer);
yield return childElement; yield return childElement;
@ -122,6 +137,11 @@ namespace nadena.dev.modular_avatar.core.editor
VRCExpressionsMenu[] parentsMenus = parents.DefaultIfEmpty(installer.installTargetMenu).ToArray(); VRCExpressionsMenu[] parentsMenus = parents.DefaultIfEmpty(installer.installTargetMenu).ToArray();
bool hasChildMenu = false; bool hasChildMenu = false;
/*
* Installer adds the controls in specified menu to the installation destination.
* So, since the specified menu itself does not exist as a child menu,
* and the child menus of the specified menu are the actual child menus, a single installer may add multiple child menus.
*/
foreach (KeyValuePair<string, VRCExpressionsMenu> childMenu in childMenus) foreach (KeyValuePair<string, VRCExpressionsMenu> childMenu in childMenus)
{ {
hasChildMenu = true; hasChildMenu = true;
@ -139,6 +159,10 @@ namespace nadena.dev.modular_avatar.core.editor
} }
if (hasChildMenu) return; if (hasChildMenu) return;
/*
* If the specified menu does not have any submenus, it is not mapped as a child menu and the Installer information itself is not registered.
* Therefore, register elements that do not have child menus themselves, but only have information about the installer.
*/
foreach (VRCExpressionsMenu parentMenu in parentsMenus) foreach (VRCExpressionsMenu parentMenu in parentsMenus)
{ {
TraverseMenu(parentMenu, new ChildElement TraverseMenu(parentMenu, new ChildElement