Exemple #1
0
    public void TestBlockPlacing(
        [Values(Placeable.Side.North, Placeable.Side.East, Placeable.Side.West, Placeable.Side.South, Placeable.Side.Center)] Placeable.Side side,
        [Values(true, false)] bool allowsXZSnapping,
        [Values(true, false)] bool allowsYSnapping,
        //[Values(0f, 1f, 0.1f, -0.2f)]float blockThickness,
        [Values(0.2f)] float blockThickness,
        [Values(true, false)] bool isTrigger,
        [Values(true, false)] bool requiresSomeFoundation,
        [Values(true)] bool canBePlacedAtZeroLevelWithoutFoundation,
        [Values(true, false)] bool isFullBlock,
        //[Values(-1, 0, 1, 2)]int maxLengthWithoutSupport
        [Values(0)] int maxLengthWithoutSupport
        )
    {
        var gameObject = new GameObject("Mono holder");
        var world      = gameObject.AddComponent <MockWorld>();

        world.SetUp();


        var testBlock = new MockPlaceable("TestBlock", allowsXZSnapping, allowsYSnapping, blockThickness, isTrigger, requiresSomeFoundation, canBePlacedAtZeroLevelWithoutFoundation,
                                          isFullBlock, maxLengthWithoutSupport, null);

        // placed at 0,0,0
        testBlock.SetPosition(Vector3.zero, side);
        testBlock.Place(world);


        var placed = world.GetBlock(testBlock.GetIntegerCoords(), side);

        Assert.AreSame(testBlock, placed);
    }
Exemple #2
0
    public void TestBlockDeleting(
        [Values(Placeable.Side.North, Placeable.Side.East, Placeable.Side.West, Placeable.Side.South, Placeable.Side.Center, Placeable.Side.Top, Placeable.Side.Bottom)] Placeable.Side side,
        [Values(true, false)] bool allowsXZSnapping,
        [Values(true, false)] bool allowsYSnapping,
        //[Values(0f, 1f, 0.1f, -0.2f)]float blockThickness,
        [Values(0.2f)] float blockThickness,
        [Values(true)] bool isTrigger,
        [Values(true)] bool requiresSomeFoundation,
        [Values(true)] bool canBePlacedAtZeroLevelWithoutFoundation,
        [Values(true, false)] bool isFullBlock,
        //[Values(-1, 0, 1, 2)]int maxLengthWithoutSupport
        [Values(0, 1, 2, 3)] int maxLengthWithoutSupport
        )
    {
        var gameObject = new GameObject("Mono holder");
        var world      = gameObject.AddComponent <MockWorld>();

        world.SetUp();


        var testBlock = new MockPlaceable("TestBlock", allowsXZSnapping, allowsYSnapping, blockThickness, isTrigger, requiresSomeFoundation, canBePlacedAtZeroLevelWithoutFoundation,
                                          isFullBlock, maxLengthWithoutSupport, null);

        // placed at 0,0,0
        testBlock.SetPosition(Vector3.zero, side);

        var placedBlock = testBlock.Place(world);

        LogAssert.ignoreFailingMessages = true;
        world.Remove(placedBlock);
        LogAssert.ignoreFailingMessages = false;
        Assert.IsTrue(world.GetBlock(testBlock.GetIntegerCoords(), side) == World.AirBlock);// should be empty after deletion
    }
Exemple #3
0
    public bool TestCanBePlaced(
        Placeable.Side bottomBlockSide,
        bool isBottomBlockIsFullBlock,

        Placeable.Side testBlockSide,
        bool isTestBlockIsFullBlock,
        int maxLengthWithoutSupport
        )
    {
        var gameObject = new GameObject("Mono holder");
        var world      = gameObject.AddComponent <MockWorld>();

        world.SetUp();

        var bottomBlock = new MockPlaceable("TestBlock", allowsXZSnapping: true, allowsYSnapping: true,
                                            blockThickness: 0.2f, isTrigger: false, requiresSomeFoundation: true,
                                            canBePlacedAtZeroLevelWithoutFoundation: true, isFullBlock: isBottomBlockIsFullBlock,
                                            maxLengthWithoutSupport: maxLengthWithoutSupport, prefab: null); // sets bottom block


        bottomBlock.SetPosition(Vector3.zero, bottomBlockSide);

        bottomBlock.Place(world);

        var testBlock = new MockPlaceable("TestBlock", allowsXZSnapping: true, allowsYSnapping: true,
                                          blockThickness: 0.2f, isTrigger: false, requiresSomeFoundation: true,
                                          canBePlacedAtZeroLevelWithoutFoundation: true, isFullBlock: isTestBlockIsFullBlock,
                                          maxLengthWithoutSupport: maxLengthWithoutSupport, prefab: null);

        testBlock.SetPosition(new Vector3(0f, 1f, 0f), testBlockSide);


        return(testBlock.CanBePlaced(world));
    }
Exemple #4
0
        public static PlacedBlock Add(GameObject go, Placeable placeable, Placeable.Side side)
        {
            var placed = go.AddComponent <PlacedBlock>();

            placed.Placeable    = placeable;
            placed.SideSnapping = side;
            return(placed);
        }
Exemple #5
0
    public void CanFullBlockBePlacedOnHalfBlockBottom(

        [Values(Placeable.Side.North, Placeable.Side.East, Placeable.Side.West, Placeable.Side.South, Placeable.Side.Center, Placeable.Side.Top, Placeable.Side.Bottom)] Placeable.Side testBlockSide,

        [Values(0)] int maxLengthWithoutSupport
        )
    {
        Assert.IsFalse(TestCanBePlaced(Placeable.Side.Bottom, false, testBlockSide, true, maxLengthWithoutSupport));
    }
Exemple #6
0
    public void CanFullBlockBePlacedOnFullBlock(
        [Values(Placeable.Side.North, Placeable.Side.East, Placeable.Side.West, Placeable.Side.South, Placeable.Side.Center, Placeable.Side.Top, Placeable.Side.Bottom)] Placeable.Side bottomBlockSide,

        [Values(Placeable.Side.North, Placeable.Side.East, Placeable.Side.West, Placeable.Side.South, Placeable.Side.Center, Placeable.Side.Top, Placeable.Side.Bottom)] Placeable.Side testBlockSide,
        [Values(true, false)] bool isTestBlockIsFullBlock,
        [Values(0)] int maxLengthWithoutSupport
        )
    {
        Assert.IsTrue(TestCanBePlaced(bottomBlockSide, true, testBlockSide, isTestBlockIsFullBlock, maxLengthWithoutSupport));
    }
Exemple #7
0
 /// <summary>
 /// null means that cell doesn't exist (wrong index)
 /// </summary>
 public virtual IPlaceable GetBlock(int x, int y, int z, Placeable.Side side)
 {
     if (IsCellExists(x, y, z))
     {
         return(map[x, y, z].Get(side));
     }
     else
     {
         return(null);
     }
 }
Exemple #8
0
        /// <summary>
        /// Coordinates check should be outside
        /// </summary>
        public virtual void Add(IPlaceable placeable, Placeable.Side sideSnapping)
        {
            var coords = placeable.GetIntegerCoords();

            if (placeable.IsFullBlock) // fill all sides
            {
                foreach (Placeable.Side eachSide in Enum.GetValues(typeof(Placeable.Side)))
                {
                    map[coords.x, coords.y, coords.z].Place(placeable, eachSide);
                }
            }
            else // fill specific part
            {
                map[coords.x, coords.y, coords.z].Place(placeable, sideSnapping);
            }
        }
Exemple #9
0
    public void CanHalfBlockBePlacedhalfBlock(
        [Values(Placeable.Side.North, Placeable.Side.East, Placeable.Side.West, Placeable.Side.South, Placeable.Side.Center, Placeable.Side.Top, Placeable.Side.Bottom)] Placeable.Side bottomBlockSide,
        [Values(Placeable.Side.North, Placeable.Side.East, Placeable.Side.West, Placeable.Side.South, Placeable.Side.Center, Placeable.Side.Top, Placeable.Side.Bottom)] Placeable.Side testBlockSide,
        [Values(0)] int maxLengthWithoutSupport
        )
    {
        var res = TestCanBePlaced(bottomBlockSide, false, testBlockSide, false, maxLengthWithoutSupport);

        if (bottomBlockSide == testBlockSide || bottomBlockSide == Placeable.Side.Top || testBlockSide == Placeable.Side.Bottom)
        {
            Assert.IsTrue(res);
        }
        else
        {
            Assert.IsFalse(res);
        }
    }
Exemple #10
0
 internal bool HasAnyNonAirBlockExcept(Vector3Int coords, Placeable.Side exceptThatBlock)
 {
     if (IsCellExists(coords.x, coords.y, coords.z))
     {
         foreach (Placeable.Side eachSide in Enum.GetValues(typeof(Placeable.Side)))
         {
             var block = map[coords.x, coords.y, coords.z].Get(eachSide);
             if (block != AirBlock && eachSide != exceptThatBlock)
             {
                 return(true);
             }
         }
         return(false);
     }
     else
     {
         return(false);
     }
 }
Exemple #11
0
    public void TestBlockReplacing(
        [Values(Placeable.Side.North, Placeable.Side.East, Placeable.Side.West, Placeable.Side.South, Placeable.Side.Center, Placeable.Side.Top, Placeable.Side.Bottom)] Placeable.Side blockForDeletingSide,
        [Values(true, false)] bool blockForDeletingAllowsXZSnapping,
        [Values(true, false)] bool blockForDeletingAllowsYSnapping,
        [Values(true, false)] bool blockForDeletingIsFullBlock,
        [Values(Placeable.Side.North, Placeable.Side.East, Placeable.Side.West, Placeable.Side.South, Placeable.Side.Center, Placeable.Side.Top, Placeable.Side.Bottom)] Placeable.Side testBlockSide,
        [Values(true, false)] bool testBlockAllowsXZSnapping,
        [Values(true, false)] bool testBlockAllowsYSnapping,
        [Values(true, false)] bool testBlockIsFullBlock

        )
    {
        var gameObject = new GameObject("Mono holder");
        var world      = gameObject.AddComponent <MockWorld>();

        world.SetUp();


        var blockForDeleting = new MockPlaceable("blockForDeleting", blockForDeletingAllowsXZSnapping, blockForDeletingAllowsYSnapping,
                                                 blockThickness: 0.2f, isTrigger: false, requiresSomeFoundation: true, canBePlacedAtZeroLevelWithoutFoundation: true,
                                                 isFullBlock: blockForDeletingIsFullBlock, maxLengthWithoutSupport: 0, prefab: null);

        blockForDeleting.SetPosition(new Vector3(0f, 0f, 0f), blockForDeletingSide);


        var placedBlock = blockForDeleting.Place(world);

        LogAssert.ignoreFailingMessages = true;
        world.Remove(placedBlock);
        LogAssert.ignoreFailingMessages = false;

        var testBlock = new MockPlaceable("TestBlock", testBlockAllowsXZSnapping, testBlockAllowsYSnapping,
                                          blockThickness: 0.2f, isTrigger: false, requiresSomeFoundation: true,
                                          canBePlacedAtZeroLevelWithoutFoundation: true, isFullBlock: testBlockIsFullBlock,
                                          maxLengthWithoutSupport: 0, prefab: null);

        testBlock.SetPosition(new Vector3(0f, 0f, 0f), testBlockSide);
        testBlock.Place(world);

        Assert.AreSame(testBlock, world.GetBlock(testBlock.GetIntegerCoords(), testBlockSide));// should be empty after deletion
    }
Exemple #12
0
    /// <summary>
    /// Test placing of all types ob blocks
    /// </summary>
    public void TestPlacing(
        [Values(Placeable.Side.North, Placeable.Side.East, Placeable.Side.West, Placeable.Side.South, Placeable.Side.Center)] Placeable.Side side,
        [Values(true, false)] bool allowsXZSnapping,
        [Values(true, false)] bool allowsYSnapping,
        [Values(1f)] float blockThickness,
        [Values(true, false)] bool isTrigger,
        [Values(true, false)] bool requiresSomeFoundation,
        [Values(true, false)] bool canBePlacedAtZeroLevelWithoutFoundation,
        [Values(true, false)] bool isFullBlock,
        [Values(-1, 0, 1, 2)] int maxLengthWithoutSupport)
    {
        var testableCell = new Cell();

        testableCell.Init(World.AirBlock);
        // placed at 0,0,0
        var randomBlock = new MockPlaceable("dsntmatter", allowsXZSnapping, allowsYSnapping, blockThickness, isTrigger, requiresSomeFoundation,
                                            canBePlacedAtZeroLevelWithoutFoundation, isFullBlock, maxLengthWithoutSupport, prefab: null);

        testableCell.Place(randomBlock, side);
        Assert.AreSame(randomBlock, testableCell.Get(side));
    }
Exemple #13
0
 public void Remove(Placeable.Side side)
 {
     container[(int)side] = World.AirBlock;
 }
Exemple #14
0
 public void Place(IPlaceable block, Placeable.Side side)
 {
     container[(int)side] = block;
 }
Exemple #15
0
 public IPlaceable Get(Placeable.Side side)
 {
     return(container[(int)side]);
 }
Exemple #16
0
 /// <summary>
 /// null means that cell doesn't exist (wrong index)
 /// </summary>
 public virtual IPlaceable GetBlock(Vector3Int position, Placeable.Side side)
 {
     return(GetBlock(position.x, position.y, position.z, side));
 }