Beispiel #1
0
        /// <summary>
        /// The undo object is only serialized during an undo operation
        /// </summary>
        public void OnBeforeSerialize()
        {
            if (Workspace == null || Workspace.Canvas == null || Workspace.Canvas.File == null)
            {
                return;
            }

            serialized = new SerializedWorkspace
            {
                foregroundColor   = Workspace.Canvas.ForegroundColor,
                backgroundColor   = Workspace.Canvas.BackgroundColor,
                selectedFrame     = Workspace.Canvas.ActiveFrame.id,
                selectedLayer     = Workspace.Canvas.ActiveLayer.id,
                selectedAnimation = Workspace.Canvas.ActiveAnimation.id,
                animations        = Workspace.Canvas.File.animations.Select(a => new SerializedAnimation {
                    id = a.id, name = a.name
                }).ToArray(),
                frames = Workspace.Canvas.File.frames.Select(f => new SerializedFrame {
                    id = f.id, order = f.order, animation = f.animation.id
                }).ToArray(),
                layers = Workspace.Canvas.File.layers.Select(l => new SerializedLayer {
                    id = l.id, name = l.name, opacity = l.opacity, order = l.order, visible = l.visible
                }).ToArray(),
                images = Workspace.Canvas.File.images.Select(i => new SerializedImage {
                    frame = i.frame.id, layer = i.layer.id, texture = i.texture
                }).ToArray()
            };
        }
Beispiel #2
0
        /// <summary>
        /// the undo uobject is only deserialized after an undo operation.
        /// </summary>
        public void OnAfterDeserialize()
        {
            if (null == serialized || Workspace == null)
            {
                return;
            }

            Workspace.Canvas.ForegroundColor = serialized.foregroundColor;
            Workspace.Canvas.BackgroundColor = serialized.backgroundColor;

            Workspace.Canvas.File.animations = serialized.animations.Select(a => new PAAnimation
            {
                name = a.name,
                id   = a.id
            }).ToList();

            Workspace.Canvas.File.layers = serialized.layers.Select(l => new PALayer(Workspace.Canvas.File)
            {
                id      = l.id,
                name    = l.name,
                opacity = l.opacity,
                order   = l.order,
                visible = l.visible,
            }).ToList();

            Workspace.Canvas.File.frames = serialized.frames.Select(f => new PAFrame(Workspace.Canvas.File)
            {
                id        = f.id,
                animation = Workspace.Canvas.File.FindAnimation(f.animation),
                order     = f.order
            }).ToList();

            Workspace.Canvas.File.images = serialized.images.Select(i => new PAImage
            {
                frame   = Workspace.Canvas.File.FindFrame(i.frame),
                layer   = Workspace.Canvas.File.FindLayer(i.layer),
                texture = i.texture
            }).ToList();

            Workspace.RefreshLayersList();
            Workspace.RefreshFrameList();
            Workspace.RefreshAnimationList();

            Workspace.Canvas.ActiveAnimation = Workspace.Canvas.File.FindAnimation(serialized.selectedAnimation);
            Workspace.Canvas.ActiveLayer     = Workspace.Canvas.File.FindLayer(serialized.selectedLayer);
            Workspace.Canvas.ActiveFrame     = Workspace.Canvas.File.FindFrame(serialized.selectedFrame);

            Workspace.Canvas.RefreshImage();

            serialized = null;

            UndoEvent?.Invoke();
        }