void undoMove(MoveNodeAction moveNodeAction) { if (moveNodeAction == null) { return; } nodes [moveNodeAction.IndexInList].Position = moveNodeAction.From; }
void makeMove(MoveNodeAction moveNodeAction) { if (moveNodeAction == null) { return; } nodes [moveNodeAction.IndexInList].Position = moveNodeAction.To; }
void onFlagReleased(Flag flag) { Vector3 from = flag.PrevFlagPosition; Vector3 to = flag.transform.position; if (Vector3.Distance(from, to) > GlobalConst.EPSILON) { StageAction stageAction = new MoveNodeAction(flags.IndexOf(flag), from, to); stage.AddAction(stageAction); } refreshLineRenderer(); synchronizeModelWithFlags(); }
/// <summary> /// Generates <see cref="NodeAction"/> according to <see cref="NodeDifference.MovementInfo"/>. /// </summary> /// <param name="difference">The difference.</param> protected virtual void ProcessMovement(NodeDifference difference) { var source = difference.Source; var target = difference.Target; var isImmutable = Context.IsImmutable; var isChanged = (difference.MovementInfo & MovementInfo.Changed) != 0; var isCreated = (difference.MovementInfo & MovementInfo.Created) != 0; var isRemoved = (difference.MovementInfo & MovementInfo.Removed) != 0 || (isImmutable && difference.HasChanges && !isCreated); var sc = StringComparer.OrdinalIgnoreCase; switch (Stage) { case UpgradeStage.CleanupData: if (difference.IsDataChanged) { Hints.GetHints <UpdateDataHint>(difference.Source) .Where(hint => sc.Compare(hint.SourceTablePath, difference.Source.Path) == 0) .ForEach(hint => AddAction(UpgradeActionType.Regular, new DataAction { DataHint = hint })); Hints.GetHints <DeleteDataHint>(difference.Source) .Where(hint => !hint.PostCopy) .Where(hint => sc.Compare(hint.SourceTablePath, difference.Source.Path) == 0) .ForEach(hint => AddAction(UpgradeActionType.Regular, new DataAction { DataHint = hint })); } break; case UpgradeStage.Prepare: if (isRemoved && !difference.IsRemoveOnCleanup) { if (!Context.IsRemoved || difference.IsDependentOnParent) { AddAction(UpgradeActionType.PreCondition, new RemoveNodeAction { Path = (source ?? target).Path }); } } break; case UpgradeStage.Cleanup: if (!Context.IsRemoved || difference.IsDependentOnParent) { AddAction(UpgradeActionType.PreCondition, new RemoveNodeAction { Path = (source ?? target).Path }); } break; case UpgradeStage.TemporaryRename: RegisterTemporaryRename(source); var temporaryName = GetTemporaryName(source); AddAction(UpgradeActionType.Rename, new MoveNodeAction { Path = source.Path, Parent = source.Parent == null ? string.Empty : source.Parent.Path, Name = temporaryName, Index = null, NewPath = GetPathWithoutName(source) + temporaryName }); break; case UpgradeStage.CopyData: Hints.GetHints <CopyDataHint>(difference.Source) .Where(hint => sc.Compare(hint.SourceTablePath, difference.Source.Path) == 0) .ForEach(hint => AddAction(UpgradeActionType.Regular, new DataAction { DataHint = hint })); break; case UpgradeStage.PostCopyData: if (difference.IsDataChanged) { Hints.GetHints <DeleteDataHint>(difference.Source) .Where(hint => hint.PostCopy) .Where(hint => sc.Compare(hint.SourceTablePath, difference.Source.Path) == 0) .ForEach(hint => AddAction(UpgradeActionType.Regular, new DataAction { DataHint = hint })); } break; case UpgradeStage.Upgrade: if (target == null) { break; } if (isCreated) { var action = new CreateNodeAction { Path = target.Parent == null ? string.Empty : target.Parent.Path, Type = target.GetType(), Name = target.Name, Index = target.Nesting.IsNestedToCollection ? (int?)target.Index : null }; AddAction(UpgradeActionType.PostCondition, action); } else if (isChanged) { var action = new MoveNodeAction { Path = source.Path, Parent = target.Parent == null ? string.Empty : target.Parent.Path, Name = target.Name, Index = target.Nesting.IsNestedToCollection ? (int?)source.Index : null, NewPath = target.Path }; AddAction(UpgradeActionType.PostCondition, action); } break; } }