Example #1
0
        public static int CountScoringTilesPerpendicular(Player player, EnumAxis direction)
        {
            int perpendicularScore = 0;

            //for this one, we don't include the actual tile itself in the score, unless the perpendicular score is greater than 1

            foreach (Tile tile in player.placedTiles)
            {
                //get the position of the tile, and look in the specified direction to see how many tiles it touches. If it doesn't touch any, the perpendicular score for that tile is 0;
                int tilePerpendicularScore = CountScoringTilesInLine(tile, direction);
                if (tilePerpendicularScore > 1 && tilePerpendicularScore < 6)
                {
                    perpendicularScore += tilePerpendicularScore;
                }
                else if (tilePerpendicularScore == 6)
                {
                    perpendicularScore += 12;
                    Console.WriteLine("Tangent Qwirkle!");
                }
                else
                {
                    continue;
                }
            }
            return(perpendicularScore);
        }
Example #2
0
        private BlockFacing(string code, byte flag, int index, int oppositeIndex, int horizontalAngleIndex, Vec3i facingVector, Vec3f planeCenter, EnumAxis axis, Cuboidf plane)
        {
            this.index                = index;
            this.meshDataIndex        = (byte)(index + 1);
            this.horizontalAngleIndex = horizontalAngleIndex;
            this.flag          = flag;
            this.code          = code;
            this.oppositeIndex = oppositeIndex;
            this.normali       = facingVector;
            this.normalf       = new Vec3f(facingVector.X, facingVector.Y, facingVector.Z);
            this.normald       = new Vec3d((double)facingVector.X, (double)facingVector.Y, (double)facingVector.Z);
            this.plane         = plane;

            normalPacked = NormalUtil.PackNormal(normalf.X, normalf.Y, normalf.Z);
            normalb      = (byte)(
                (axis == EnumAxis.Z ? 1 : 0) << 0
                    | (facingVector.Z < 0 ? 1 : 0) << 1

                    | (axis == EnumAxis.Y ? 1 : 0) << 2
                    | (facingVector.Y < 0 ? 1 : 0) << 3

                    | (axis == EnumAxis.X ? 1 : 0) << 4
                    | (facingVector.X < 0 ? 1 : 0) << 5
                );

            normalPackedFlags = VertexFlags.PackNormal(normalf);

            this.planeCenter = planeCenter;
            this.axis        = axis;
        }
        public override AssetLocation GetHorizontallyFlippedBlockCode(EnumAxis axis)
        {
            BlockFacing facing = BlockFacing.FromCode(Variant["orientation"]);

            if (facing.Axis == axis)
            {
                return(CodeWithVariant("orientation", facing.Opposite.Code));
            }
            return(Code);
        }
        public override AssetLocation GetHorizontallyFlippedBlockCode(EnumAxis axis)
        {
            BlockFacing facing = BlockFacing.FromCode(LastCodePart());

            if (facing.Axis == axis)
            {
                return(CodeWithParts(facing.Opposite.Code));
            }
            return(Code);
        }
Example #5
0
        private List <Point> ReduceToEdgePoints_WhenChangeDirection(List <Point> points)
        {
            List <Point> result = new List <Point>();

            if (points.Count <= 2)
            {
                return(points);
            }

            result.Add(points[0]);

            for (int i = 2; i < points.Count; i++)
            {
                Point p1 = points[i - 2];
                Point p2 = points[i - 1];
                Point p3 = points[i];


                EnumAxis sameAxis  = Helper_GetPointTheSameAxis(p1, p2);
                EnumAxis sameAxis2 = Helper_GetPointTheSameAxis(p2, p3);

                if (sameAxis != sameAxis2)
                {
                    result.Add(p1);
                }
                // axis are the same, must detect line
                else
                {
                    EnumAxis sameAxis3 = Helper_GetPointTheSameAxis(p1, p2, p3);
                    if (sameAxis3 == EnumAxis.Y)
                    {
                        bool xTest = !((p1.X < p2.X && p2.X < p3.X) || (p1.X > p2.X && p2.X > p3.X));

                        if (xTest)
                        {
                            result.Add(p2);
                        }
                    }
                    else if (sameAxis3 == EnumAxis.X)
                    {
                        bool yTest = !((p1.Y < p2.Y && p2.Y < p3.Y) || (p1.Y > p2.Y && p2.Y > p3.Y));

                        if (yTest)
                        {
                            result.Add(p2);
                        }
                    }
                }
            }

            result.Add(points[points.Count - 1]);

            return(result);
        }
Example #6
0
 private Direction(BlockPos pos, Vector3 vec, string name, EnumAxis axis, int opposite, int clockwise, int counterClockwise, int directionIndex, int renderMask)
 {
     this.blockPos              = pos;
     this.vector                = vec;
     this.name                  = name;
     this.axis                  = axis;
     this.oppositeIndex         = opposite;
     this.clockwiseIndex        = clockwise;
     this.counterClockwiseIndex = counterClockwise;
     this.index                 = directionIndex;
     this.renderMask            = renderMask;
 }
Example #7
0
    private Rotation(int id, string name, Vector2Int dir, EnumAxis axis, EnumRotation enumRot)
    {
        this.id      = id;
        this.name    = name;
        this.vector  = dir;
        this.vectorF = this.vector;
        this.axis    = axis;
        this.enumRot = enumRot;

        this.xDir = dir.x;
        this.yDir = dir.y;
    }
        public override AssetLocation GetHorizontallyFlippedBlockCode(EnumAxis axis, ref EnumHandling handling)
        {
            handling = EnumHandling.PreventDefault;

            BlockFacing facing = BlockFacing.FromCode(block.LastCodePart());

            if (facing.Axis == axis)
            {
                return(block.CodeWithParts(facing.Opposite.Code));
            }
            return(block.Code);
        }
Example #9
0
        // Broken!
        public float sampleAxis(float offset, EnumAxis axis)
        {
            int currentLight = this.getLightLevel(0, 0, 0);

            // Debugging.
            if (Math.Abs(offset) > 0.5f)
            {
                throw new Exception("offset our of range " + offset);
            }

            // Speedy lookup
            if (offset == 0)  // Middle of cell.
            {
                return(currentLight);
            }
            else if (offset == 0.5 || offset == -0.5f)
            {
                BlockPos pos = BlockPos.zero;
                if (axis == EnumAxis.X)
                {
                    pos = new BlockPos(1, 0, 0);
                }
                else if (axis == EnumAxis.Y)
                {
                    pos = new BlockPos(0, 1, 0);
                }
                else if (axis == EnumAxis.Z)
                {
                    pos = new BlockPos(0, 0, 1);
                }
                return((currentLight + this.getLightLevel(pos)) / 2f); // Average of the two levels.
            }
            else
            {
                float l1 = currentLight;
                float l2;
                if (axis == EnumAxis.X)
                {
                    l2 = this.getLightLevel(MathHelper.roundAwayFrom0(offset), 0, 0);
                }
                else if (axis == EnumAxis.Y)
                {
                    l2 = this.getLightLevel(0, MathHelper.roundAwayFrom0(offset), 0);
                }
                else     // EnumAxis.Z
                {
                    l2 = this.getLightLevel(0, 0, MathHelper.roundAwayFrom0(offset));
                }

                return(Mathf.Lerp(l1, l2, Mathf.Abs(offset)));
            }
        }
Example #10
0
        public override AssetLocation GetHorizontallyFlippedBlockCode(EnumAxis axis, ref EnumHandling handling)
        {
            handling = EnumHandling.PreventDefault;

            BlockFacing curFacing = BlockFacing.FromCode(block.Variant["rot"]);

            if (curFacing.Axis == axis)
            {
                return(block.CodeWithVariant("rot", curFacing.Opposite.Code));
            }

            return(block.Code);
        }
Example #11
0
    private void Shuffle()
    {
        EnumAxis axis = (EnumAxis)UnityEngine.Random.Range(0, 3);

        int slice = UnityEngine.Random.Range(0, 3);

        while (slice == lastSlice)
        {
            slice = UnityEngine.Random.Range(0, 3);
        }

        lastSlice = slice;

        EnumDirection direction = (EnumDirection)UnityEngine.Random.Range(0, 2);

        CubeController.Instance.StartRotation(axis, EnumAnimType.slice, direction, slice, 1200f);
    }
Example #12
0
    public void StartRotation(EnumAxis axis, EnumAnimType animType, EnumDirection direction, int nslice = 0, float speed = 300f)
    {
        rotationAxis      = axis;
        animationType     = animType;
        rotationDirection = direction;
        slice             = nslice;
        rotationSpeed     = speed;

        if (gameState == EnumGameState.playing)
        {
            History.Push(new Move {
                Axis      = axis,
                Type      = animationType,
                Direction = rotationDirection,
                Slice     = slice
            });
        }

        DoRotate();
    }
Example #13
0
        private int FindEdge(PixelCollection pPixels, int pBeginLine, int pEndLine, EnumAxis pAxis, int pAxisMax, EnumScanDirection pDirection)
        {
            if (pBeginLine > pEndLine && pAxis == EnumAxis.Horiztontal && pDirection == EnumScanDirection.Backward)
            {
                return(pBeginLine + EdgeSafetyBuffer);
            }

            if (pBeginLine > pEndLine && pAxis == EnumAxis.Vertical && pDirection == EnumScanDirection.Backward)
            {
                return(pBeginLine + EdgeSafetyBuffer);
            }

            var _return = 0;

            var highest = 0;

            // get all the RGB readings from the range
            var scanResults = pAxis == EnumAxis.Horiztontal ? lineRangeScan_H(pPixels, pBeginLine, pEndLine, pAxisMax) : lineRangeScan_V(pPixels, pBeginLine, pEndLine, pAxisMax);

            // find the highest value
            for (var x = 0; x < scanResults.Length; x++)
            {
                if (scanResults[x] > highest)
                {
                    highest = scanResults[x];
                    _return = pBeginLine + x;
                }
            }

            // count back the safety buffer
            if (pDirection == EnumScanDirection.Forward)
            {
                _return -= EdgeSafetyBuffer;
            }
            else
            {
                _return += EdgeSafetyBuffer;
            }

            return(_return);
        }
Example #14
0
    public void Undo()
    {
        if (state == EnumCubeAnimState.animating)
        {
            return;
        }
        if (History.Count == 0)
        {
            return;
        }

        var move = History.Pop();

        rotationAxis      = move.Axis;
        animationType     = move.Type;
        rotationDirection = move.Direction == EnumDirection.positive ? EnumDirection.negative : EnumDirection.positive;
        slice             = move.Slice.GetValueOrDefault();
        rotationSpeed     = 300f;

        DoRotate();
    }
Example #15
0
        public override bool OnWorldEditCommand(WorldEdit worldEdit, CmdArgs args)
        {
            switch (args[0])
            {
            case "imc":
                if (workspace.clipboardBlockData != null)
                {
                    this.blockDatas = new BlockSchematic[] { workspace.clipboardBlockData };
                    worldEdit.Good("Ok, using copied blockdata");
                    nextRnd = 0;
                    workspace.ResendBlockHighlights(worldEdit);
                }
                else
                {
                    worldEdit.Good("No copied block data available");
                }
                return(true);

            case "ims":
                string        exportFolderPath = worldEdit.sapi.GetOrCreateDataPath("WorldEdit");
                List <string> filenames        = new List <string>();

                for (int i = 1; i < args.Length; i++)
                {
                    string filename = Path.GetFileName(args[i]);
                    string filepath = Path.Combine(exportFolderPath, args[i]);

                    if (!filename.EndsWith("*") && !filename.EndsWith("/") && !filename.EndsWith(".json"))
                    {
                        filename += ".json";
                    }

                    try
                    {
                        string[] foundFilePaths = Directory.GetFiles(Path.GetDirectoryName(filepath), filename);

                        for (int j = 0; j < foundFilePaths.Length; j++)
                        {
                            filenames.Add(foundFilePaths[j].Substring(exportFolderPath.Length + 1));
                        }
                    } catch (Exception)
                    {
                        worldEdit.Bad("Unable to read files from this source");
                        return(true);
                    }
                }



                if (filenames.Count > 0)
                {
                    BlockDataFilenames = string.Join(",", filenames);
                    LoadBlockdatas(worldEdit.sapi, worldEdit);
                    worldEdit.Good("Ok, found " + filenames.Count + " block data source files");
                }
                else
                {
                    BlockDataFilenames = null;
                    this.blockDatas    = new BlockSchematic[0];

                    worldEdit.Good("No source files under this name/wildcard found");
                }

                nextRnd = rand.Next(blockDatas.Length);

                workspace.ResendBlockHighlights(worldEdit);

                return(true);

            case "imo":
                Origin = EnumOrigin.BottomCenter;

                if (args.Length > 1)
                {
                    int origin;
                    int.TryParse(args[1], out origin);
                    if (Enum.IsDefined(typeof(EnumOrigin), origin))
                    {
                        Origin = (EnumOrigin)origin;
                    }
                }

                worldEdit.Good("Paste origin " + Origin + " set.");

                workspace.ResendBlockHighlights(worldEdit);

                return(true);

            case "tm":
                ReplaceMode = EnumReplaceMode.Replaceable;

                if (args.Length > 1)
                {
                    int replaceable = 0;
                    int.TryParse(args[1], out replaceable);
                    if (Enum.IsDefined(typeof(EnumReplaceMode), replaceable))
                    {
                        ReplaceMode = (EnumReplaceMode)replaceable;
                    }
                }

                worldEdit.Good("Replace mode " + ReplaceMode + " set.");
                workspace.ResendBlockHighlights(worldEdit);

                return(true);

            case "imrrand":
                RandomRotate = args.Length > 1 && (args[1] == "1" || args[1] == "true" || args[1] == "on");

                worldEdit.Good("Random rotation now " + (RandomRotate ? "on" : "off"));

                SetRandomAngle(worldEdit.sapi.World);

                workspace.ResendBlockHighlights(worldEdit);

                return(true);

            case "imn":
                nextRnd = rand.Next(blockDatas.Length);
                workspace.ResendBlockHighlights(worldEdit);
                break;


            case "imr":
                if (blockDatas == null || blockDatas.Length == 0)
                {
                    worldEdit.Bad("Please define a block data source first.");
                    return(true);
                }

                int angle = 90;

                if (args.Length > 1)
                {
                    if (!int.TryParse(args[1], out angle))
                    {
                        worldEdit.Bad("Invalid Angle (not a number)");
                        return(true);
                    }
                }
                if (angle < 0)
                {
                    angle += 360;
                }

                if (angle != 0 && angle != 90 && angle != 180 && angle != 270)
                {
                    worldEdit.Bad("Invalid Angle, allowed values are -270, -180, -90, 0, 90, 180 and 270");
                    return(true);
                }

                for (int i = 0; i < blockDatas.Length; i++)
                {
                    blockDatas[i].TransformWhilePacked(worldEdit.sapi.World, EnumOrigin.BottomCenter, angle, null);
                }

                workspace.ResendBlockHighlights(worldEdit);

                worldEdit.Good("Ok, all schematics rotated by " + angle + " degrees");

                return(true);


            case "imflip":
                if (blockDatas == null || blockDatas.Length == 0)
                {
                    worldEdit.Bad("Please define a block data source first.");
                    return(true);
                }

                for (int i = 0; i < blockDatas.Length; i++)
                {
                    blockDatas[i].TransformWhilePacked(worldEdit.sapi.World, EnumOrigin.BottomCenter, 0, EnumAxis.Y);
                }

                workspace.ResendBlockHighlights(worldEdit);

                worldEdit.Good("Ok, imported sources flipped");


                return(true);


            case "immirror":
                if (blockDatas == null || blockDatas.Length == 0)
                {
                    worldEdit.Bad("Please define a block data source first.");
                    return(true);
                }

                EnumAxis axis = EnumAxis.X;
                if (args.PopWord().ToLowerInvariant() == "z")
                {
                    axis = EnumAxis.Z;
                }

                for (int i = 0; i < blockDatas.Length; i++)
                {
                    blockDatas[i].TransformWhilePacked(worldEdit.sapi.World, EnumOrigin.BottomCenter, 0, axis);
                }

                workspace.ResendBlockHighlights(worldEdit);

                worldEdit.Good("Ok, imported sources mirrored around " + axis + " axis");


                return(true);
            }

            return(false);
        }
Example #16
0
        public static int CountScoringTilesInLine(Tile tile, EnumAxis direction)
        {
            int tileCount = 0;

            var(startingR, startingC) = tile.GridXref;

            switch (direction)
            {
            case EnumAxis.Horizontal:
                for (int currentC = startingC - 1; currentC >= 0; currentC--)     //count left
                {
                    if (Grid.IsEmptyPosition(startingR, currentC))
                    {
                        break;
                    }
                    else
                    {
                        tileCount++;
                    }
                }
                for (int currentC = startingC + 1; currentC <= MainClass.GridColumns; currentC++)     //count right
                {
                    if (Grid.IsEmptyPosition(startingR, currentC))
                    {
                        break;
                    }
                    else
                    {
                        tileCount++;
                    }
                }
                tileCount++;     //count self
                return(tileCount);

            case EnumAxis.Vertical:                                           //column-wise
                for (int currentR = startingR - 1; currentR >= 0; currentR--) // count up
                {
                    if (Grid.IsEmptyPosition(currentR, startingC))
                    {
                        break;
                    }
                    else
                    {
                        tileCount++;
                    }
                }
                for (int currentR = startingR + 1; currentR <= MainClass.GridRows; currentR++)     //count down
                {
                    if (Grid.IsEmptyPosition(currentR, startingC))
                    {
                        break;
                    }
                    else
                    {
                        tileCount++;
                    }
                }
                tileCount++;     //count self
                return(tileCount);

            default:
                return(0);
            }
        }
Example #17
0
        public static bool IsValidMove(Tile newTile, int startingRow, int startingColumn, Player currentPlayer)
        {
            bool          hasNearbyTiles = false;
            int           distance       = 1;
            EnumDirection direction      = EnumDirection.Left;
            int           matchType      = 0; //0: no matchtype, 1:Colour, 2:Shape
            bool          invalidMove    = false;

            if (!Grid.IsEmptyPosition(startingRow, startingColumn))
            {
                Console.WriteLine($"A Tile already exists at {startingRow}:{startingColumn}");
                return(false);
            }

            if (Grid.IsEmpty())
            {
                return(true); //if there are no existing tiles in the grid, you can put any tile down.
            }
            do
            {
                //Is there a nearbyTile?
                bool nearbyTileExists = Grid.QueryNearbyLocation(startingRow, startingColumn, direction, distance, out Tile nearbyTile);
                if (nearbyTileExists)
                {
                    hasNearbyTiles = true;
                    // Is the nearbyTile identical to the newTile?
                    if (Tile.IsDuplicate(nearbyTile, newTile))
                    {
                        return(false); //if a nearby tile is identical , the move is invalid.
                    }
                    // If the player has already placed tiles this turn, there are some things we need to check;
                    if (currentPlayer.placedTiles.Count() > 0)
                    {
                        int i = 0;
                        // is the new tile touching a tile previously placed this turn?
                        foreach (Tile existingTile in currentPlayer.placedTiles)
                        {
                            if (Tile.TouchingChecker(startingRow, startingColumn, existingTile) == false && i >= currentPlayer.placedTiles.Count() - 1)
                            {
                                Console.WriteLine("All tiles placed in a turn must touch each other.");
                                return(false); // all tiles placed in a turn must touch each other;
                            }
                            else if (Tile.TouchingChecker(startingRow, startingColumn, existingTile) == false && i < currentPlayer.placedTiles.Count() - 1)
                            {
                                Console.WriteLine($"{newTile}@{startingRow},{startingColumn} does not touch {existingTile.GridXref}, but there are more placed tiles to check against.");
                            }
                            i++;
                        }
                        Console.WriteLine("The new tile DOES touch a previously placed tile");

                        // in addition to touching each other, they must all be placed along the same axis;
                        if (currentPlayer.placedTiles.Count() > 1)
                        {
                            EnumAxis existingAxis = Tile.AxisChecker(currentPlayer.placedTiles[0], currentPlayer.placedTiles[1]);

                            /*
                             *  0 = no axis match (shouldn't be possible)
                             *  1 = horizontal axis match
                             *  2 = vertical axis match
                             */
                            if (existingAxis == EnumAxis.None)
                            {
                                Console.WriteLine("Somehow there are placed tiles which do not share an axis");
                                return(false);
                            }

                            foreach (Tile existingTile in currentPlayer.placedTiles)
                            {
                                if (Tile.AxisMatch(startingRow, startingColumn, existingTile, existingAxis) == false)
                                {
                                    return(false);
                                }
                            }
                            Console.WriteLine("The new tile DOES share an axis with a previously placed tile");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Skipping nearby tile checks, as this is the first tile placed this turn");
                    }



                    // Do I have a current matchType?
                    switch (matchType)
                    {
                    case 0:     //no current matchtype. can match either colour OR shape
                        if (Tile.ColourMatch(nearbyTile, newTile))
                        {
                            Console.WriteLine($"New Tile ({newTile}) Matches existing tile ({nearbyTile} on Colour.");
                            matchType = 1;
                            distance++;
                            continue;
                        }
                        else if (Tile.ShapeMatch(nearbyTile, newTile))
                        {
                            Console.WriteLine($"New Tile ({newTile}) Matches existing tile ({nearbyTile} on Shape.");
                            matchType = 2;
                            distance++;
                            continue;
                        }
                        else
                        {
                            Console.WriteLine($"New Tile ({newTile}) Matches existing tile ({nearbyTile} on Neither!.");
                            return(false);
                        }

                    case 1:                                                                                                 //should only match colour
                        if (Tile.ColourMatch(nearbyTile, newTile) == true && Tile.ShapeMatch(nearbyTile, newTile) == false) //only matches colour, doesn't match shape
                        {
                            Console.WriteLine($"New Tile ({newTile}) Matches existing tile ({nearbyTile} on Colour. (case2)");
                            distance++;     //proceeed to checking the next tile;
                            continue;
                        }
                        else     //if the above check failed, then the new tile is of an invalid type, so reject the move.
                        {
                            Console.WriteLine($"New Tile ({newTile}) Does not match existing tile ({nearbyTile} on Colour. (case2)");
                            invalidMove = true;
                            continue;
                        }

                    case 2:                                                                                                 //should only match shape
                        if (Tile.ColourMatch(nearbyTile, newTile) == false && Tile.ShapeMatch(nearbyTile, newTile) == true) //only matches shape, doesn't match colour
                        {
                            Console.WriteLine($"New Tile ({newTile}) Matches existing tile ({nearbyTile} on Shape. (case3)");
                            distance++;     //proceeed to checking the next tile;
                            continue;
                        }
                        else     //if the above check failed, then the new tile is of an invalid type, so reject the move.
                        {
                            Console.WriteLine($"New Tile ({newTile}) does not match existing tile ({nearbyTile} on Shape. (case3)");
                            invalidMove = true;
                            continue;
                        }
                    }
                    // Is the nearbyTile a Colour Match for newTile?
                    // Is the nearbyTile a Shape Match for newTile?
                }
                else
                {
                    Console.WriteLine($"No more tiles found {direction}");
                    switch (direction)
                    {
                    case EnumDirection.Right:
                        direction = EnumDirection.Up;
                        distance  = 1;    //reset the distance, because we're now starting with a new direction
                        matchType = 0;    //the next direction is up, we're therefore changing plane and so we need to reset the match type.
                        continue;

                    case EnumDirection.Down:     // If we've got here, we must've checked all directions without being told it's invalid.
                        if (hasNearbyTiles)
                        {
                            Console.WriteLine("That move is valid");
                            return(true);    //the new tile must be touching existing tiles, and not declared invalid, so it must be valid.
                        }
                        else
                        {
                            return(false);    //the new tile doesn't touch any existing tiles, but existing tiles exist on the board. new tiles MUST touch existing tiles.
                        }

                    default:
                        direction++;  //go to the next direction
                        distance = 1; //reset the distance
                        continue;     //start the loop again.
                    }
                }
            } while (invalidMove == false);

            return(false);
        }
Example #18
0
 public override AssetLocation GetHorizontallyFlippedBlockCode(EnumAxis axis)
 {
     return(base.GetHorizontallyFlippedBlockCode(axis));
 }
Example #19
0
    private void ProcessTouch()
    {
        // did not touch enough faces
        if (touchList.Count <= 1)
        {
            touchList.Clear();
            print("did not touch enough faces");
            return;
        }

        var axisTouched = touchList[0].name.Substring(4, 1);

        List <GameObject> facesOnSameAxis = touchList.Where(f => f.name.Contains(axisTouched)).ToList();

        // Did not touch enough faces on same axis
        if (facesOnSameAxis.Count == 1)
        {
            touchList.Clear();
            print("Did not touch enough faces on same axis");
            return;
        }

        var firstFace    = facesOnSameAxis.FirstOrDefault();
        var firstFaceRow = int.Parse(firstFace.name.Substring(5, 1));
        var firstFaceCol = int.Parse(firstFace.name.Substring(6, 1));

        var lastFace    = facesOnSameAxis.LastOrDefault();
        var lastFaceRow = int.Parse(lastFace.name.Substring(5, 1));
        var lastFaceCol = int.Parse(lastFace.name.Substring(6, 1));

        // Can't determine slice touched
        if (firstFaceCol != lastFaceCol && firstFaceRow != lastFaceRow)
        {
            touchList.Clear();
            print("Cannot determine slice touched");
            return;
        }

        EnumAxis      axis      = EnumAxis.z; // remove default;
        int           slice     = 0;
        EnumDirection direction = EnumDirection.positive;
        EnumAnimType  animType  = EnumAnimType.slice;

        switch (axisTouched)
        {
        case "X":
            if (firstFaceRow == lastFaceRow)
            {
                axis      = EnumAxis.y;
                slice     = firstFaceRow;
                direction = firstFaceCol > lastFaceCol ? EnumDirection.negative : EnumDirection.positive;
                animType  = firstFaceRow == 1 ? EnumAnimType.cube : EnumAnimType.slice;
            }
            else
            {
                axis      = EnumAxis.z;
                slice     = firstFaceCol;
                direction = firstFaceRow > lastFaceRow ? EnumDirection.negative : EnumDirection.positive;
                animType  = firstFaceCol == 1 ? EnumAnimType.cube : EnumAnimType.slice;
            }
            break;

        case "Y":
            if (firstFaceRow == lastFaceRow)
            {
                axis      = EnumAxis.x;
                slice     = firstFaceRow;
                direction = firstFaceCol > lastFaceCol ? EnumDirection.negative : EnumDirection.positive;
                animType  = firstFaceRow == 1 ? EnumAnimType.cube : EnumAnimType.slice;
            }
            else
            {
                axis      = EnumAxis.z;
                slice     = firstFaceCol;
                direction = firstFaceRow > lastFaceRow ? EnumDirection.positive : EnumDirection.negative;
                animType  = firstFaceCol == 1 ? EnumAnimType.cube : EnumAnimType.slice;
            }
            break;

        case "Z":
            if (firstFaceRow == lastFaceRow)
            {
                axis      = EnumAxis.y;
                slice     = firstFaceRow;
                direction = firstFaceCol > lastFaceCol ? EnumDirection.positive : EnumDirection.negative;
                animType  = firstFaceRow == 1 ? EnumAnimType.cube : EnumAnimType.slice;
            }
            else
            {
                axis      = EnumAxis.x;
                slice     = firstFaceCol;
                direction = firstFaceRow > lastFaceRow ? EnumDirection.positive : EnumDirection.negative;
                animType  = firstFaceCol == 1 ? EnumAnimType.cube : EnumAnimType.slice;
            }
            break;
        }

        touchList.Clear();
        print("rotating");
        CubeController.Instance.StartRotation(axis, animType, direction, slice);
    }
Example #20
0
 /// <summary>
 /// For any block that can be flipped vertically, this method should be implemented to return the correctly flipped block code. It is used by the world edit tool for allowing block data rotations
 /// </summary>
 /// <param name="axis"></param>
 /// <param name="handling"></param>
 /// <returns></returns>
 public virtual AssetLocation GetHorizontallyFlippedBlockCode(EnumAxis axis, ref EnumHandling handling)
 {
     handling = EnumHandling.PassThrough;
     return(null);
 }