Skip to content

Commit 0227420

Browse files
committed
refactor(ui): ♻️ update ReferenceReplacementDialog and manager for slot handling
1 parent 782bdc1 commit 0227420

8 files changed

Lines changed: 129 additions & 78 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This file is **authoritative and persistent** for everything under `/ReferenceRe
1212
- Private, potentially sensitive research (e.g., raw assembly dumps, exploratory notes) must live under the git-ignored `local_notes/` directory, each topic in its own markdown file to keep knowledge granular.
1313
5. **Persistence:** Any change to policies/workflow must be reflected here immediately. Subdirectories inherit these rules unless they define their own `AGENTS.md`.
1414
6. **Data model constraints:** This mod must not introduce new FrooxEngine data-model types or `SyncDelegate` definitions. All functionality must be built on existing data-model constructs to avoid sync registration overhead.
15+
7. **Design notes ban:** Do not create standalone design notes or ADR-style docs; instead, keep commits and code self-explanatory and update this AGENTS file if process rules change.
1516

1617
## Scope / Status
1718

src/ReferenceReplacement/Logic/ReferenceScanner.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.Reflection;
55
using System.Runtime.CompilerServices;
6+
67
using FrooxEngine;
78

89
namespace ReferenceReplacement.Logic;
@@ -13,7 +14,7 @@ public static ReferenceScanResult Scan(Slot root, IWorldElement source, IWorldEl
1314
{
1415
ArgumentNullException.ThrowIfNull(root);
1516

16-
var session = new ReferenceScanSession(source, target);
17+
ReferenceScanSession session = new(source, target);
1718
session.VisitSlot(root, TraversalPath.FromSlot(root));
1819
return session.BuildResult();
1920
}
@@ -22,8 +23,8 @@ internal static ReferenceScanResult Scan(HierarchyBlueprint blueprintRoot, IWorl
2223
{
2324
ArgumentNullException.ThrowIfNull(blueprintRoot);
2425

25-
var session = new ReferenceScanSession(source, target);
26-
session.VisitBlueprint(blueprintRoot, new TraversalPath(blueprintRoot.Label));
26+
ReferenceScanSession session = new(source, target);
27+
session.VisitBlueprint(blueprintRoot, new(blueprintRoot.Label));
2728
return session.BuildResult();
2829
}
2930

@@ -369,10 +370,10 @@ internal sealed record HierarchyBlueprint(string Label, IReadOnlyList<ISyncMembe
369370
{
370371
public static HierarchyBlueprint Create(string label, IEnumerable<ISyncMember> members, IEnumerable<HierarchyBlueprint>? children = null)
371372
{
372-
var memberList = members is IReadOnlyList<ISyncMember> readyMembers
373+
IReadOnlyList<ISyncMember> memberList = members is IReadOnlyList<ISyncMember> readyMembers
373374
? readyMembers
374375
: new List<ISyncMember>(members ?? Array.Empty<ISyncMember>());
375-
var childList = children is IReadOnlyList<HierarchyBlueprint> readyChildren
376+
IReadOnlyList<HierarchyBlueprint> childList = children is IReadOnlyList<HierarchyBlueprint> readyChildren
376377
? readyChildren
377378
: new List<HierarchyBlueprint>(children ?? Array.Empty<HierarchyBlueprint>());
378379
return new HierarchyBlueprint(label, memberList, childList);
@@ -386,4 +387,4 @@ internal sealed class ReferenceEqualityComparer : IEqualityComparer<object>
386387
public new bool Equals(object? x, object? y) => ReferenceEquals(x, y);
387388

388389
public int GetHashCode(object obj) => RuntimeHelpers.GetHashCode(obj);
389-
}
390+
}

src/ReferenceReplacement/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
[assembly: AssemblyVersion("0.1.0.0")]
44
[assembly: AssemblyFileVersion("0.1.0.0")]
5-
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReferenceReplacement.Tests")]
5+
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReferenceReplacement.Tests")]

src/ReferenceReplacement/ReferenceReplacementMod.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
using System;
2+
23
using FrooxEngine;
4+
35
using HarmonyLib;
6+
47
using ReferenceReplacement.UI;
8+
59
using ResoniteModLoader;
610
#if USE_RESONITE_HOT_RELOAD_LIB
711
using ResoniteHotReloadLib;
@@ -63,4 +67,4 @@ private static void RegisterCreationEntry()
6367

6468
_creationEntryRegistered = true;
6569
}
66-
}
70+
}

src/ReferenceReplacement/UI/ReferenceReplacementDialog.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
45
using Elements.Core;
6+
57
using FrooxEngine;
68
using FrooxEngine.UIX;
79
using FrooxEngine.Undo;
10+
811
using ReferenceReplacement.Logic;
912

1013
namespace ReferenceReplacement.UI;
@@ -21,11 +24,10 @@ public sealed class ReferenceReplacementDialog
2124
private Text? _detailText;
2225
private bool _disposed;
2326

24-
private ReferenceReplacementDialog(User owner)
27+
private ReferenceReplacementDialog(User owner, Slot dialogSlot)
2528
{
2629
_owner = owner ?? throw new ArgumentNullException(nameof(owner));
27-
Slot? userSpace = owner.LocalUserSpace ?? throw new InvalidOperationException("User space is unavailable.");
28-
_rootSlot = userSpace.AddSlot("Reference Replacement Dialog");
30+
_rootSlot = dialogSlot ?? throw new ArgumentNullException(nameof(dialogSlot));
2931
_rootSlot.Destroyed += OnSlotDestroyed;
3032
ClearSlot(_rootSlot);
3133

@@ -39,9 +41,9 @@ private ReferenceReplacementDialog(User owner)
3941
RepositionFor(owner);
4042
}
4143

42-
public static ReferenceReplacementDialog Create(User owner)
44+
public static ReferenceReplacementDialog Create(User owner, Slot dialogSlot)
4345
{
44-
return new ReferenceReplacementDialog(owner);
46+
return new ReferenceReplacementDialog(owner, dialogSlot);
4547
}
4648

4749
public bool HasProcessRoot => GetProcessRootSlot() != null;
@@ -217,7 +219,7 @@ private void BuildStatusSection(UIBuilder ui)
217219

218220
private void Analyze(bool applyChanges)
219221
{
220-
if (!TryResolveInputs(out var root, out var source, out var target, out var errorMessage))
222+
if (!TryResolveInputs(out Slot root, out IWorldElement source, out IWorldElement target, out string errorMessage))
221223
{
222224
UpdateStatus(errorMessage);
223225
return;
@@ -386,4 +388,4 @@ private void PrepareRootSlot(User owner)
386388
_rootSlot.LocalPosition = float3.Zero;
387389
_rootSlot.LocalRotation = floatQ.Identity;
388390
}
389-
}
391+
}
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1+
using System;
2+
13
using FrooxEngine;
24

35
namespace ReferenceReplacement.UI;
46

57
internal static class ReferenceReplacementDialogManager
68
{
7-
public static void Show(User? localUser)
9+
public static void Show(Slot creationSlot)
810
{
11+
if (creationSlot == null)
12+
{
13+
return;
14+
}
15+
16+
User? localUser = creationSlot.World?.LocalUser;
917
if (localUser == null)
1018
{
19+
creationSlot.Destroy();
1120
return;
1221
}
1322

14-
ReferenceReplacementDialog.Create(localUser);
23+
ReferenceReplacementDialog.Create(localUser, creationSlot);
1524
}
1625

1726
public static void Unregister(ReferenceReplacementDialog dialog)
1827
{
28+
ArgumentNullException.ThrowIfNull(dialog);
1929
}
2030

21-
}
31+
}

src/ReferenceReplacement/UI/ReferenceReplacementEntryPoint.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,7 @@ public static void OpenFromSlot(Slot? creationSlot)
1111
return;
1212
}
1313

14-
User? localUser = creationSlot.World?.LocalUser;
15-
if (localUser == null)
16-
{
17-
creationSlot.Destroy();
18-
return;
19-
}
20-
21-
try
22-
{
23-
ReferenceReplacementDialogManager.Show(localUser);
24-
}
25-
finally
26-
{
27-
creationSlot.Destroy();
28-
}
14+
ReferenceReplacementDialogManager.Show(creationSlot);
2915
}
3016

31-
}
17+
}

0 commit comments

Comments
 (0)