示例#1
0
        public void CommonProperties()
        {
            var objects = new LevelObjectCollection();

            for (int i = 1; i <= 45; i++)
            {
                objects.Add(new GeneralObject(i, i * 30 + 15, 75));
            }

            bool hasCommonID = objects.TryGetCommonPropertyWithID((int)ObjectProperty.ObjectID, out int ID);
            bool hasCommonX  = objects.TryGetCommonPropertyWithID((int)ObjectProperty.X, out double x);
            bool hasCommonY  = objects.TryGetCommonPropertyWithID((int)ObjectProperty.Y, out double y);

            Assert.IsFalse(hasCommonID);
            Assert.IsFalse(hasCommonX);
            Assert.IsTrue(hasCommonY);

            objects.TrySetCommonPropertyWithID((int)ObjectProperty.ObjectID, 4);
            objects.TrySetCommonPropertyWithID((int)ObjectProperty.X, 35.5);
            objects.TrySetCommonPropertyWithID((int)ObjectProperty.Y, 43.3);

            hasCommonID = objects.TryGetCommonPropertyWithID((int)ObjectProperty.ObjectID, out ID);
            hasCommonX  = objects.TryGetCommonPropertyWithID((int)ObjectProperty.X, out x);
            hasCommonY  = objects.TryGetCommonPropertyWithID((int)ObjectProperty.Y, out y);

            Assert.IsTrue(hasCommonID);
            Assert.IsTrue(hasCommonX);
            Assert.IsTrue(hasCommonY);

            var firstMove  = new MoveTrigger(2, 3);
            var secondMove = new MoveTrigger(2, 4);
            var alpha      = new AlphaTrigger(3, 4, 0.5);

            objects.AddRange(firstMove, secondMove, alpha);

            bool hasCommonDuration      = objects.TryGetCommonPropertyWithID((int)ObjectProperty.Duration, out double duration);
            bool hasCommonTargetGroupID = objects.TryGetCommonPropertyWithID((int)ObjectProperty.TargetGroupID, out int targetGroupID);

            Assert.IsFalse(hasCommonDuration);
            Assert.IsFalse(hasCommonTargetGroupID);

            objects.TrySetCommonPropertyWithID((int)ObjectProperty.Duration, 7d);
            objects.TrySetCommonPropertyWithID((int)ObjectProperty.TargetGroupID, 5);

            Assert.IsTrue(firstMove.Duration == 7);
            Assert.IsTrue(secondMove.Duration == 7);
            Assert.IsTrue(alpha.Duration == 7);

            Assert.IsTrue(firstMove.TargetGroupID == 5);
            Assert.IsTrue(secondMove.TargetGroupID == 5);
            Assert.IsTrue(alpha.TargetGroupID == 5);

            hasCommonDuration      = objects.TryGetCommonPropertyWithID((int)ObjectProperty.Duration, out duration);
            hasCommonTargetGroupID = objects.TryGetCommonPropertyWithID((int)ObjectProperty.TargetGroupID, out targetGroupID);

            Assert.IsTrue(hasCommonDuration);
            Assert.IsTrue(hasCommonTargetGroupID);
        }
示例#2
0
        public void Clone()
        {
            var objects = new LevelObjectCollection();

            for (int i = 1; i <= 45; i++)
            {
                objects.Add(new GeneralObject(i));
            }

            var cloned = objects.Clone();

            for (int i = 0; i < 45; i++)
            {
                Assert.AreEqual(objects[i], cloned[i]);
            }
        }
示例#3
0
        public static GeneralObject GetCommonAttributes(LevelObjectCollection list, short objectID)
        {
            GeneralObject common = GeneralObject.GetNewObjectInstance(objectID);

            for (int i = list.Count; i >= 0; i--)
            {
                if (list[i].ObjectID != objectID)
                {
                    list.RemoveAt(i);
                }
            }
            if (list.Count > 1)
            {
                var properties = common.GetType().GetProperties();
                foreach (var p in properties)
                {
                    if (Attribute.GetCustomAttributes(p, typeof(ObjectStringMappableAttribute), false).Count() > 0)
                    {
                        var  v        = p.GetValue(list[0]);
                        bool isCommon = true;
                        foreach (var o in list)
                        {
                            if (isCommon = (p.GetValue(o) != v))
                            {
                                break;
                            }
                        }
                        if (isCommon)
                        {
                            p.SetValue(common, v);
                        }
                    }
                }
                return(common);
            }
            else if (list.Count == 1)
            {
                return(list[0]);
            }
            else
            {
                return(null);
            }
        }
示例#4
0
 /// <summary>Creates a new instance of the <seealso cref="CustomLevelObject"/> class from the specified list of objects.</summary>
 /// <param name="levelObjects">The objects this custom object has.</param>
 public CustomLevelObject(LevelObjectCollection levelObjects)
 {
     LevelObjects = levelObjects.Clone();
     if (LevelObjects.Count > 0)
     {
         double avgX = 0;
         double avgY = 0;
         for (int i = 0; i < LevelObjects.Count; i++)
         {
             avgX += LevelObjects[i].X;
             avgY += LevelObjects[i].Y;
         }
         avgX /= LevelObjects.Count;
         avgY /= LevelObjects.Count;
         for (int i = 0; i < LevelObjects.Count; i++)
         {
             LevelObjects[i].X -= avgX;
             LevelObjects[i].Y -= avgY;
         }
     }
 }
示例#5
0
        private void InitializeObjects()
        {
            for (int i = 0; i < 5; i++)
            {
                normalBlocks[i] = new GeneralObject(1)
                {
                    GroupIDs = new int[] { i + 1 },
                    Color1ID = i + 1,
                    Color2ID = i + 21,
                };

                moveTriggers[i] = new MoveTrigger(0, i + 1);

                pickupItems[i] = new PickupItem(1275)
                {
                    TargetItemID = i + 1,
                };

                pickupTriggers[i] = new PickupTrigger(i + 1, 0);

                colorTriggers[i] = new ColorTrigger(i + 1)
                {
                    CopiedColorID = i + 21,
                };

                instantCountTriggers[i] = new InstantCountTrigger(i + 1, i + 1, 0);

                collisionBlocks[i] = new CollisionBlock
                {
                    BlockID = i + 1,
                };

                collisionTriggers[i] = new CollisionTrigger(i + 1, i + 21, i + 1);
            }

            allObjects = new LevelObjectCollection(normalBlocks.Concat(moveTriggers).Concat(pickupItems).Concat(pickupTriggers).Concat(colorTriggers).Concat(instantCountTriggers).Concat(collisionBlocks).Concat(collisionTriggers));
        }
示例#6
0
 /// <summary>Initializes a new instance of the <seealso cref="ObjectsPasted"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="centralPoint">The central point that was taken into account while performing the action.</param>
 /// <param name="action">The function that rotates the specified objects.</param>
 /// <param name="inverse">The inverse action to be performed.</param>
 public ObjectsPasted(LevelObjectCollection affectedObjects, Point centralPoint, ObjectPropertyCentralPointSetter action, ObjectsUndoableActionDelegate inverse)
     : base(affectedObjects, action, inverse)
 {
     CentralPoint = centralPoint;
 }
示例#7
0
 /// <summary>Initializes a new instance of the <seealso cref="ObjectsCreated"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="createObjectsAction">The action that creates the specified objects.</param>
 /// <param name="deleteObjectsAction">The action that deletes the created objects.</param>
 public ObjectsCreated(LevelObjectCollection affectedObjects, ObjectsUndoableActionDelegate deleteObjectsAction, ObjectsUndoableActionDelegate createObjectsAction)
     : base(affectedObjects, createObjectsAction, deleteObjectsAction)
 {
 }
示例#8
0
 /// <summary>Initiailizes a new instance of the <seealso cref="LevelActionObjectsValueCommonInverse{TValue, TDelegate}"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="action">The action to be performed.</param>
 /// <param name="inverse">The inverse action to be performed.</param>
 public LevelActionObjectsValueCommonInverse(LevelObjectCollection affectedObjects, TValue value, TDelegate action)
     : base(affectedObjects, value, action, action)
 {
 }
示例#9
0
 /// <summary>Initiailizes a new instance of the <seealso cref="LevelActionObjectsOffset{TActionDelegate, TInverseDelegate}"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="offset">The offset to apply to the specified property of the affected objects.</param>
 /// <param name="action">The action to be performed.</param>
 public LevelActionObjectsOffset(LevelObjectCollection affectedObjects, TValue offset, TActionDelegate action)
     : base(affectedObjects, action)
 {
     Offset        = offset;
     InverseOffset = GetInverseOffset();
 }
示例#10
0
 /// <summary>Initiailizes a new instance of the <seealso cref="LevelActionObjectsOffsetCentralPoint{TValue}"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="offset">The offset to apply to the specified property of the affected objects.</param>
 /// <param name="centralPoint">The central point that was taken into account while performing the action.</param>
 /// <param name="action">The action to be performed.</param>
 public LevelActionObjectsOffsetCentralPoint(LevelObjectCollection affectedObjects, TValue offset, Point?centralPoint, ObjectPropertyOffsetCentralPointSetter <TValue> action)
     : base(affectedObjects, offset, action)
 {
 }
示例#11
0
 /// <summary>Initializes a new instance of the <seealso cref="SelectedObjectsRemoved"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="deselectObjectsAction">The action that deselects the specified objects.</param>
 /// <param name="selectObjectsAction">The action that selects the specified objects.</param>
 public SelectedObjectsRemoved(LevelObjectCollection affectedObjects, ObjectsUndoableActionDelegate deselectObjectsAction, ObjectsUndoableActionDelegate selectObjectsAction)
     : base(affectedObjects, deselectObjectsAction, selectObjectsAction)
 {
 }
 /// <summary>Initializes a new instance of the <seealso cref="SelectedObjectsRemoved"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="action">The action that deselects the specified objects.</param>
 /// <param name="inverse">The action that selects the specified objects.</param>
 public LevelActionObjectsOnlyInverse(LevelObjectCollection affectedObjects, ObjectsUndoableActionDelegate action, ObjectsUndoableActionDelegate inverse)
     : base(affectedObjects, action, inverse)
 {
 }
 /// <summary>Initiailizes a new instance of the <seealso cref="LevelActionObjectsInverse{TActionDelegate, TInverseDelegate}"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="action">The action to be performed.</param>
 /// <param name="inverse">The inverse action to be performed.</param>
 public LevelActionObjectsValueInverse(LevelObjectCollection affectedObjects, TValue value, TActionDelegate action, TInverseDelegate inverse)
     : base(affectedObjects, action, inverse)
 {
     Value = value;
 }
示例#14
0
 /// <summary>Initializes a new instance of the <seealso cref="SelectedObjectsRemoved"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="deselectObjectsAction">The action that deselects all the objects.</param>
 /// <param name="selectObjectsAction">The action that selects the previously selected objects.</param>
 public AllObjectsDeselected(LevelObjectCollection affectedObjects, UndoableActionDelegate deselectObjectsAction, ObjectsUndoableActionDelegate selectObjectsAction)
     : base(affectedObjects, selectObjectsAction, deselectObjectsAction)
 {
 }
 /// <summary>Initializes a new instance of the <seealso cref="SelectedObjectsRemoved"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="action">The action to apply to the specified objects.</param>
 public LevelActionObjectsCommonInverse(LevelObjectCollection affectedObjects, TDelegate action)
     : base(affectedObjects, action)
 {
 }
 /// <summary>Initializes a new instance of the <seealso cref="LevelActionObjectsCommonInverseCentralPoint"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="centralPoint">The central point that was taken into account while performing the action.</param>
 /// <param name="action">The action to apply to the specified objects.</param>
 public LevelActionObjectsCommonInverseCentralPoint(LevelObjectCollection affectedObjects, Point?centralPoint, ObjectPropertyNullableCentralPointSetter action)
     : base(affectedObjects, action)
 {
     CentralPoint = centralPoint;
 }
 /// <summary>Initializes a new instance of the <seealso cref="ObjectsFlippedHorizontally"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="centralPoint">The central point that was taken into account while flipping the objects horizontally.</param>
 /// <param name="action">The function that rotates the specified objects.</param>
 public ObjectsFlippedHorizontally(LevelObjectCollection affectedObjects, Point?centralPoint, ObjectPropertyNullableCentralPointSetter action)
     : base(affectedObjects, centralPoint, action)
 {
 }
示例#18
0
 /// <summary>Initializes a new instance of the <seealso cref="ObjectsCopied"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="oldObjects">The objects before the action was performed that will be affected when undoing this action.</param>
 /// <param name="action">The function that rotates the specified objects.</param>
 public ObjectsCopied(LevelObjectCollection affectedObjects, LevelObjectCollection oldObjects, ObjectsUndoableActionDelegate action)
     : base(affectedObjects, oldObjects, action)
 {
 }
示例#19
0
 /// <summary>Initiailizes a new instance of the <seealso cref="LevelActionObjectsInverse{TActionDelegate, TInverseDelegate}"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="action">The action to be performed.</param>
 /// <param name="inverse">The inverse action to be performed.</param>
 public LevelActionObjectsInverse(LevelObjectCollection affectedObjects, TActionDelegate action, TInverseDelegate inverse)
     : base(affectedObjects, action)
 {
     InverseAction = inverse;
 }
示例#20
0
 /// <summary>Initializes a new instance of the <seealso cref="GroupIDsRemoved"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="action">The function that rotates the specified objects.</param>
 public GroupIDsRemoved(LevelObjectCollection affectedObjects, IEnumerable <int> groupIDs, ObjectPropertySetter <IEnumerable <int> > action, ObjectPropertySetter <IEnumerable <int> > inverse)
     : base(affectedObjects, groupIDs, action, inverse)
 {
 }
示例#21
0
 /// <summary>Initializes a new instance of the <seealso cref="MainColorIDsChanged"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="offset">The offset to apply to the specified property of the affected objects.</param>
 /// <param name="resultingColorID">The resulting value of the main color ID.</param>
 /// <param name="action">The action to be performed.</param>
 public MainColorIDsChanged(LevelObjectCollection affectedObjects, int offset, int resultingColorID, ObjectPropertyOffsetSetter <int> action)
     : base(affectedObjects, offset, resultingColorID, action)
 {
 }
示例#22
0
 /// <summary>Initializes a new instance of the <seealso cref="ObjectsScaled"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="offset">The offset to apply to the specified parameter of the affected objects.</param>
 /// <param name="centralPoint">The central point that was taken into account while scaling the objects.</param>
 /// <param name="action">The function that scales the specified objects.</param>
 public ObjectsScaled(LevelObjectCollection affectedObjects, double offset, Point?centralPoint, ObjectPropertyOffsetCentralPointSetter <double> action)
     : base(affectedObjects, offset, centralPoint, action)
 {
 }
示例#23
0
 /// <summary>Initializes a new instance of the <seealso cref="ObjectsCopyPasted"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="oldObjects">The objects before the action was performed that will be affected when undoing this action.</param>
 /// <param name="action">The action to be performed.</param>
 /// <param name="inverse">The inverse action to be performed.</param>
 public ObjectsCopyPasted(LevelObjectCollection affectedObjects, LevelObjectCollection oldObjects, ObjectsUndoableActionDelegate action, OldNewObjectsHandler inverse)
     : base(affectedObjects, oldObjects, action, inverse)
 {
 }
示例#24
0
 /// <summary>Initializes a new instance of the <seealso cref="ObjectsMoved"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="offset">The offset to apply to the specified parameter of the affected objects.</param>
 /// <param name="action">The action to be performed.</param>
 public ObjectsMoved(LevelObjectCollection affectedObjects, Point offset, ObjectPropertyOffsetSetter <Point> action)
     : base(affectedObjects, offset, action)
 {
 }
示例#25
0
        public void IDMigration()
        {
            var normalBlocks         = new GeneralObject[5];
            var moveTriggers         = new MoveTrigger[5];
            var pickupItems          = new PickupItem[5];
            var pickupTriggers       = new PickupTrigger[5];
            var colorTriggers        = new ColorTrigger[5];
            var instantCountTriggers = new InstantCountTrigger[5];
            var collisionBlocks      = new CollisionBlock[5];
            var collisionTriggers    = new CollisionTrigger[5];

            for (int i = 0; i < 5; i++)
            {
                normalBlocks[i] = new GeneralObject(1)
                {
                    GroupIDs = new int[] { i + 1 },
                    Color1ID = i + 1,
                    Color2ID = i + 21,
                }
            }
            ;
            for (int i = 0; i < 5; i++)
            {
                moveTriggers[i] = new MoveTrigger(0, i + 1);
            }
            for (int i = 0; i < 5; i++)
            {
                pickupItems[i] = new PickupItem(1275)
                {
                    TargetItemID = i + 1,
                }
            }
            ;
            for (int i = 0; i < 5; i++)
            {
                pickupTriggers[i] = new PickupTrigger(i + 1, 0);
            }
            for (int i = 0; i < 5; i++)
            {
                colorTriggers[i] = new ColorTrigger(i + 1)
                {
                    CopiedColorID = i + 21,
                }
            }
            ;
            for (int i = 0; i < 5; i++)
            {
                instantCountTriggers[i] = new InstantCountTrigger(i + 1, i + 1, 0);
            }
            for (int i = 0; i < 5; i++)
            {
                collisionBlocks[i] = new CollisionBlock
                {
                    BlockID = i + 1,
                }
            }
            ;
            for (int i = 0; i < 5; i++)
            {
                collisionTriggers[i] = new CollisionTrigger(i + 1, i + 21, i + 1);
            }

            var allObjects = new LevelObjectCollection(normalBlocks.Concat(moveTriggers).Concat(pickupItems).Concat(pickupTriggers).Concat(colorTriggers).Concat(instantCountTriggers).Concat(collisionBlocks).Concat(collisionTriggers).ToList());

            var level = new Level
            {
                Name         = "ID Migration Test Level",
                Description  = "This is a test level to help testing the ID migration feature in the backend",
                LevelObjects = allObjects,
            };

            var editor = new Editor(level);

            var step0 = new SourceTargetRange(1, 5, 6);
            var step1 = new SourceTargetRange(21, 25, 46);
            var step2 = new SourceTargetRange(1, 25, 26);
            var step3 = new SourceTargetRange(8, 8, 10);

            editor.PerformGroupIDMigration(new List <SourceTargetRange> {
                step0
            });
            Assert.IsTrue(VerifyGroupIDMigration(step0.TargetFrom));
            editor.PerformColorIDMigration(new List <SourceTargetRange> {
                step2
            });
            Assert.IsTrue(VerifyColorIDMigration(step2.TargetFrom, step1.TargetFrom));
            editor.PerformItemIDMigration(new List <SourceTargetRange> {
                step0
            });
            Assert.IsTrue(VerifyItemIDMigration(step0.TargetFrom));
            editor.PerformBlockIDMigration(new List <SourceTargetRange> {
                step1
            });
            Assert.IsTrue(VerifyBlockIDMigration(step0.SourceFrom, step1.TargetFrom));
            // TODO: Add more test steps with multiple step ID migrations

            bool VerifyGroupIDMigration(int targetFrom)
            {
                for (int i = 0; i < 5; i++)
                {
                    if (normalBlocks[i].GetGroupID(0) != i + targetFrom)
                    {
                        return(false);
                    }
                }
                for (int i = 0; i < 5; i++)
                {
                    if (moveTriggers[i].TargetGroupID != i + targetFrom)
                    {
                        return(false);
                    }
                }
                for (int i = 0; i < 5; i++)
                {
                    if (instantCountTriggers[i].TargetGroupID != i + targetFrom)
                    {
                        return(false);
                    }
                }
                for (int i = 0; i < 5; i++)
                {
                    if (collisionTriggers[i].TargetGroupID != i + targetFrom)
                    {
                        return(false);
                    }
                }
                return(true);
            }

            bool VerifyColorIDMigration(int targetFromA, int targetFromB)
            {
                for (int i = 0; i < 5; i++)
                {
                    if (normalBlocks[i].Color1ID != i + targetFromA)
                    {
                        return(false);
                    }
                    if (normalBlocks[i].Color2ID != i + targetFromB)
                    {
                        return(false);
                    }
                }
                for (int i = 0; i < 5; i++)
                {
                    if (colorTriggers[i].TargetColorID != i + targetFromA)
                    {
                        return(false);
                    }
                    if (colorTriggers[i].CopiedColorID != i + targetFromB)
                    {
                        return(false);
                    }
                }
                return(true);
            }

            bool VerifyItemIDMigration(int targetFrom)
            {
                for (int i = 0; i < 5; i++)
                {
                    if (pickupItems[i].TargetItemID != i + targetFrom)
                    {
                        return(false);
                    }
                }
                for (int i = 0; i < 5; i++)
                {
                    if (pickupTriggers[i].TargetItemID != i + targetFrom)
                    {
                        return(false);
                    }
                }
                return(true);
            }

            bool VerifyBlockIDMigration(int targetFromA, int targetFromB)
            {
                for (int i = 0; i < 5; i++)
                {
                    if (collisionBlocks[i].BlockID != i + targetFromA)
                    {
                        return(false);
                    }
                }
                for (int i = 0; i < 5; i++)
                {
                    if (collisionTriggers[i].PrimaryBlockID != i + targetFromA)
                    {
                        return(false);
                    }
                    if (collisionTriggers[i].SecondaryBlockID != i + targetFromB)
                    {
                        return(false);
                    }
                }
                return(true);
            }
        }
    }
}
 /// <summary>Initiailizes a new instance of the <seealso cref="LevelActionObjectsOffsetResult{TActionDelegate}"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="offset">The offset to apply to the specified parameter of the affected objects.</param>
 /// <param name="resultingValue">The resulting value of the specified parameter after performing the action.</param>
 /// <param name="action">The action to be performed.</param>
 public LevelActionObjectsOffsetResult(LevelObjectCollection affectedObjects, TValue offset, TValue resultingValue, ObjectPropertyOffsetSetter <TValue> action)
     : base(affectedObjects, offset, action)
 {
     ResultingValue = resultingValue;
 }
示例#27
0
        public TestSceneIDMigrationBackend()
        {
            Children = new Drawable[]
            {
                new SpriteText
                {
                    Anchor = Anchor.Centre,
                    Origin = Anchor.Centre,
                    Font   = new FontUsage(size: 26),
                    Text   = "Nothing to see here, too bored to make friendly visualized messages indicating test cases"
                }
            };

            var normalBlocks         = new GeneralObject[5];
            var moveTriggers         = new MoveTrigger[5];
            var pickupItems          = new PickupItem[5];
            var pickupTriggers       = new PickupTrigger[5];
            var colorTriggers        = new ColorTrigger[5];
            var instantCountTriggers = new InstantCountTrigger[5];
            var collisionBlocks      = new CollisionBlock[5];
            var collisionTriggers    = new CollisionTrigger[5];

            for (var i = 0; i < 5; i++)
            {
                normalBlocks[i] = new GeneralObject(1)
                {
                    GroupIDs = new[] { i + 1 },
                    Color1ID = i + 1,
                    Color2ID = i + 21
                }
            }
            ;
            for (var i = 0; i < 5; i++)
            {
                moveTriggers[i] = new MoveTrigger(0, i + 1);
            }
            for (var i = 0; i < 5; i++)
            {
                pickupItems[i] = new PickupItem(1275)
                {
                    TargetItemID = i + 1
                }
            }
            ;
            for (var i = 0; i < 5; i++)
            {
                pickupTriggers[i] = new PickupTrigger(i + 1, 0);
            }
            for (var i = 0; i < 5; i++)
            {
                colorTriggers[i] = new ColorTrigger(i + 1)
                {
                    CopiedColorID = i + 21
                }
            }
            ;
            for (var i = 0; i < 5; i++)
            {
                instantCountTriggers[i] = new InstantCountTrigger(i + 1, i + 1, 0);
            }
            for (var i = 0; i < 5; i++)
            {
                collisionBlocks[i] = new CollisionBlock
                {
                    BlockID = i + 1
                }
            }
            ;
            for (var i = 0; i < 5; i++)
            {
                collisionTriggers[i] = new CollisionTrigger(i + 1, i + 21, i + 1);
            }

            var allObjects = new LevelObjectCollection(normalBlocks.Concat(moveTriggers).Concat(pickupItems)
                                                       .Concat(pickupTriggers).Concat(colorTriggers).Concat(instantCountTriggers).Concat(collisionBlocks)
                                                       .Concat(collisionTriggers).ToList());

            var level = new Level
            {
                Name         = "ID Migration Test Level",
                Description  = "This is a test level to help testing the ID migration feature in the backend",
                LevelObjects = allObjects
            };

            var editor = new Editor(level);

            var step0 = new SourceTargetRange(1, 5, 6);
            var step1 = new SourceTargetRange(21, 25, 46);
            var step2 = new SourceTargetRange(1, 25, 26);
            var step3 = new SourceTargetRange(8, 8, 10);

            AddStep("Perform Group ID migration 1-5 > 6-10",
                    () => editor.PerformGroupIDMigration(new List <SourceTargetRange> {
                step0
            }));
            AddAssert("Verify Group ID migration", () => VerifyGroupIDMigration(step0.TargetFrom));
            AddStep("Perform Color ID migration 1-25 > 26-50",
                    () => editor.PerformColorIDMigration(new List <SourceTargetRange> {
                step2
            }));
            AddAssert("Verify Color ID migration", () => VerifyColorIDMigration(step2.TargetFrom, step1.TargetFrom));
            AddStep("Perform Item ID migration 1-5 > 6-10",
                    () => editor.PerformItemIDMigration(new List <SourceTargetRange> {
                step0
            }));
            AddAssert("Verify Item ID migration", () => VerifyItemIDMigration(step0.TargetFrom));
            AddStep("Perform Block ID migration 21-25 > 46-50",
                    () => editor.PerformBlockIDMigration(new List <SourceTargetRange> {
                step1
            }));
            AddAssert("Verify Block ID migration", () => VerifyBlockIDMigration(step0.SourceFrom, step1.TargetFrom));
            // TODO: Add more test steps with multiple step ID migrations

            bool VerifyGroupIDMigration(int targetFrom)
            {
                for (var i = 0; i < 5; i++)
                {
                    if (normalBlocks[i].GetGroupID(0) != i + targetFrom)
                    {
                        return(false);
                    }
                }
                for (var i = 0; i < 5; i++)
                {
                    if (moveTriggers[i].TargetGroupID != i + targetFrom)
                    {
                        return(false);
                    }
                }
                for (var i = 0; i < 5; i++)
                {
                    if (instantCountTriggers[i].TargetGroupID != i + targetFrom)
                    {
                        return(false);
                    }
                }
                for (var i = 0; i < 5; i++)
                {
                    if (collisionTriggers[i].TargetGroupID != i + targetFrom)
                    {
                        return(false);
                    }
                }
                return(true);
            }

            bool VerifyColorIDMigration(int targetFromA, int targetFromB)
            {
                for (var i = 0; i < 5; i++)
                {
                    if (normalBlocks[i].Color1ID != i + targetFromA)
                    {
                        return(false);
                    }
                    if (normalBlocks[i].Color2ID != i + targetFromB)
                    {
                        return(false);
                    }
                }

                for (var i = 0; i < 5; i++)
                {
                    if (colorTriggers[i].TargetColorID != i + targetFromA)
                    {
                        return(false);
                    }
                    if (colorTriggers[i].CopiedColorID != i + targetFromB)
                    {
                        return(false);
                    }
                }

                return(true);
            }

            bool VerifyItemIDMigration(int targetFrom)
            {
                for (var i = 0; i < 5; i++)
                {
                    if (pickupItems[i].TargetItemID != i + targetFrom)
                    {
                        return(false);
                    }
                }
                for (var i = 0; i < 5; i++)
                {
                    if (pickupTriggers[i].TargetItemID != i + targetFrom)
                    {
                        return(false);
                    }
                }
                return(true);
            }

            bool VerifyBlockIDMigration(int targetFromA, int targetFromB)
            {
                for (var i = 0; i < 5; i++)
                {
                    if (collisionBlocks[i].BlockID != i + targetFromA)
                    {
                        return(false);
                    }
                }
                for (var i = 0; i < 5; i++)
                {
                    if (collisionTriggers[i].PrimaryBlockID != i + targetFromA)
                    {
                        return(false);
                    }
                    if (collisionTriggers[i].SecondaryBlockID != i + targetFromB)
                    {
                        return(false);
                    }
                }

                return(true);
            }
        }
    }
}
示例#28
0
 /// <summary>Initiailizes a new instance of the <seealso cref="LevelActionNewOldObjects{TDelegate}"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="oldObjects">The objects before the action was performed that will be affected when undoing this action.</param>
 /// <param name="action">The action to be performed.</param>
 public LevelActionNewOldObjects(LevelObjectCollection affectedObjects, LevelObjectCollection oldObjects, TDelegate action)
     : base(affectedObjects, action)
 {
     OldObjects = oldObjects;
 }
示例#29
0
 /// <summary>Initiailizes a new instance of the <seealso cref="LevelActionWithObjects{TDelegate}"/> class.</summary>
 /// <param name="affectedObjects">The objects that this action will affect.</param>
 /// <param name="action">The action to be performed.</param>
 public LevelActionWithObjects(LevelObjectCollection affectedObjects, TDelegate action)
     : base(action)
 {
     AffectedObjects = affectedObjects;
     ObjectCountStringRepresentation = GetAppropriateForm(AffectedObjects.Count, "object");
 }