Skip to content

Commit 34907bc

Browse files
committed
refactor(logic): ♻️ update ReferenceScanner to support excludedSlot parameter
1 parent 0227420 commit 34907bc

2 files changed

Lines changed: 11 additions & 21 deletions

File tree

src/ReferenceReplacement/Logic/ReferenceScanner.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ namespace ReferenceReplacement.Logic;
1010

1111
internal static class ReferenceScanner
1212
{
13-
public static ReferenceScanResult Scan(Slot root, IWorldElement source, IWorldElement target)
13+
public static ReferenceScanResult Scan(Slot root, IWorldElement source, IWorldElement target, Slot? excludedSlot = null)
1414
{
1515
ArgumentNullException.ThrowIfNull(root);
1616

17-
ReferenceScanSession session = new(source, target);
17+
ReferenceScanSession session = new(source, target, excludedSlot);
1818
session.VisitSlot(root, TraversalPath.FromSlot(root));
1919
return session.BuildResult();
2020
}
@@ -23,7 +23,7 @@ internal static ReferenceScanResult Scan(HierarchyBlueprint blueprintRoot, IWorl
2323
{
2424
ArgumentNullException.ThrowIfNull(blueprintRoot);
2525

26-
ReferenceScanSession session = new(source, target);
26+
ReferenceScanSession session = new(source, target, excludedSlot: null);
2727
session.VisitBlueprint(blueprintRoot, new(blueprintRoot.Label));
2828
return session.BuildResult();
2929
}
@@ -32,6 +32,7 @@ private sealed class ReferenceScanSession
3232
{
3333
private readonly IWorldElement _source;
3434
private readonly IWorldElement _target;
35+
private readonly Slot? _excludedSlot;
3536
private readonly List<SyncReferenceMatch> _matches = new();
3637
private readonly HashSet<ISyncRef> _visitedRefs = new();
3738
private readonly HashSet<object> _visitedEnumerables = new(ReferenceEqualityComparer.Instance);
@@ -40,15 +41,16 @@ private sealed class ReferenceScanSession
4041
private int _incompatibleCount;
4142
private string? _lastPath;
4243

43-
internal ReferenceScanSession(IWorldElement source, IWorldElement target)
44+
internal ReferenceScanSession(IWorldElement source, IWorldElement target, Slot? excludedSlot)
4445
{
4546
_source = source ?? throw new ArgumentNullException(nameof(source));
4647
_target = target ?? throw new ArgumentNullException(nameof(target));
48+
_excludedSlot = excludedSlot;
4749
}
4850

4951
internal void VisitSlot(Slot? slot, TraversalPath path)
5052
{
51-
if (slot == null)
53+
if (slot == null || ReferenceEquals(slot, _excludedSlot))
5254
{
5355
return;
5456
}
@@ -387,4 +389,4 @@ internal sealed class ReferenceEqualityComparer : IEqualityComparer<object>
387389
public new bool Equals(object? x, object? y) => ReferenceEquals(x, y);
388390

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

src/ReferenceReplacement/UI/ReferenceReplacementDialog.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public static ReferenceReplacementDialog Create(User owner, Slot dialogSlot)
4646
return new ReferenceReplacementDialog(owner, dialogSlot);
4747
}
4848

49-
public bool HasProcessRoot => GetProcessRootSlot() != null;
50-
5149
public bool IsAlive => !_disposed && !_rootSlot.IsDestroyed && !_rootSlot.IsRemoved;
5250

5351
public void Focus()
@@ -74,16 +72,6 @@ public void RepositionFor(User? user)
7472
_rootSlot.PointAtUserHead(float3.Backward, verticalAxisOnly: true);
7573
}
7674

77-
public void TrySetProcessRoot(Slot? slot)
78-
{
79-
if (slot == null || _processRootRef.Target != null)
80-
{
81-
return;
82-
}
83-
84-
_processRootRef.Target = slot;
85-
}
86-
8775
public void Close()
8876
{
8977
if (_disposed)
@@ -227,7 +215,7 @@ private void Analyze(bool applyChanges)
227215

228216
if (!applyChanges)
229217
{
230-
ReferenceScanResult scanResult = ReferenceScanner.Scan(root, source, target);
218+
ReferenceScanResult scanResult = ReferenceScanner.Scan(root, source, target, _rootSlot);
231219
if (scanResult.Matches.Count == 0)
232220
{
233221
UpdateStatus("No references found in the selected root.");
@@ -302,7 +290,7 @@ private bool TryResolveInputs(out Slot root, out IWorldElement source, out IWorl
302290

303291
private void ApplyReplacement(Slot root, IWorldElement source, IWorldElement target)
304292
{
305-
ReferenceScanResult scanResult = ReferenceScanner.Scan(root, source, target);
293+
ReferenceScanResult scanResult = ReferenceScanner.Scan(root, source, target, _rootSlot);
306294
if (scanResult.Matches.Count == 0)
307295
{
308296
UpdateStatus("No references found in the selected root.");
@@ -388,4 +376,4 @@ private void PrepareRootSlot(User owner)
388376
_rootSlot.LocalPosition = float3.Zero;
389377
_rootSlot.LocalRotation = floatQ.Identity;
390378
}
391-
}
379+
}

0 commit comments

Comments
 (0)