Skip to content

Commit

Permalink
This seems to fix most bugs with duplicating to multimirror.
Browse files Browse the repository at this point in the history
  • Loading branch information
andybak committed Nov 21, 2023
1 parent 0fddfad commit 401e6ff
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions Assets/Scripts/Commands/MultimirrorDuplicateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public MultimirrorDuplicateCommand(TrTransform xf, bool stampMode, BaseCommand p
else
{
targetCanvas = App.Scene.SelectionCanvas;
// If we're not stamping then we don't want to duplicate the original
matrices = matrices.Skip(1).ToList();
}

foreach (var stroke in m_SelectedStrokes)
Expand Down Expand Up @@ -110,6 +108,18 @@ public MultimirrorDuplicateCommand(TrTransform xf, bool stampMode, BaseCommand p

protected override void OnRedo()
{
if (m_SelectedStrokes != null)
{
if (m_StampMode)
{
SelectionManager.m_Instance.DeselectStrokes(m_DuplicatedStrokes);
}
else
{
SelectionManager.m_Instance.DeselectStrokes(m_SelectedStrokes);
}
}

// Place duplicated strokes.
foreach (var stroke in m_DuplicatedStrokes)
{
Expand All @@ -135,8 +145,16 @@ protected override void OnRedo()
}
TiltMeterScript.m_Instance.AdjustMeter(stroke, up: true);
}
SelectionManager.m_Instance.RegisterStrokesInSelectionCanvas(m_DuplicatedStrokes);


if (m_StampMode)
{
SelectionManager.m_Instance.RegisterStrokesInSelectionCanvas(m_SelectedStrokes);
}
else
{
SelectionManager.m_Instance.RegisterStrokesInSelectionCanvas(m_DuplicatedStrokes);
}

// Place duplicated widgets.
for (int i = 0; i < m_DuplicatedWidgets.Count; ++i)
{
Expand Down Expand Up @@ -191,7 +209,6 @@ protected override void OnUndo()
}
TiltMeterScript.m_Instance.AdjustMeter(stroke, up: false);
}
SelectionManager.m_Instance.DeregisterStrokesInSelectionCanvas(m_DuplicatedStrokes);

// Deselect selected widgets.
if (m_DuplicatedWidgets != null && !m_StampMode)
Expand All @@ -209,10 +226,20 @@ protected override void OnUndo()
// Reset the selection transform before we select strokes.
SelectionManager.m_Instance.SelectionTransform = m_Transform;

// Select strokes.
if (m_SelectedStrokes != null)
{
SelectionManager.m_Instance.SelectStrokes(m_SelectedStrokes);
if (m_StampMode)
{
// I don't think we need to do anything here
// My original stab at this below was buggy and created lots of duplicates
// SelectionManager.m_Instance.DeregisterStrokesInSelectionCanvas(m_SelectedStrokes);
// SelectionManager.m_Instance.SelectStrokes(m_DuplicatedStrokes);
}
else
{
SelectionManager.m_Instance.DeregisterStrokesInSelectionCanvas(m_DuplicatedStrokes);
SelectionManager.m_Instance.SelectStrokes(m_SelectedStrokes);
}
}

SelectionManager.m_Instance.UpdateSelectionWidget();
Expand Down

0 comments on commit 401e6ff

Please sign in to comment.