Exemplo n.º 1
0
        /// <summary>
        /// Creates a deep copy of this class
        /// </summary>
        /// <returns>Returns a deep copy of this class</returns>
        public SPieceInfo MakeCopy()
        {
            SPieceInfo Temp = new SPieceInfo(_ID);

            foreach (SJointInfo item in _Joints)
            {
                Temp.AddJoint(item);
            }

            return(Temp);
        }
        /// <summary>
        /// Loads puzzle data from file stream of .pm file
        /// </summary>
        /// <param name="stream">Stream to load data from</param>
        /// <returns>Returns true if data loading is successfull false otherwise</returns>
        private bool LoadStreamData(System.IO.Stream stream)
        {
            System.IO.BinaryReader bReader = null;

            try
            {
                using (bReader = new System.IO.BinaryReader(stream))
                {
                    //Get secret number to check file intigrity
                    int secretNumber = bReader.ReadInt32();
                    if (secretNumber != _secretVersionNo)
                    {
                        bReader.Close();
                        Debug.LogError("Error reading file. Make sure this file is created with puzzle maker`s current version");
                        return false;
                    }

                    //Get basic variables data
                    _noOfPiecesInRow = bReader.ReadInt32();
                    _noOfPiecesInCol = bReader.ReadInt32();

                    _pieceWidthWithoutJoint = bReader.ReadInt32();
                    _pieceHeightWithoutJoint = bReader.ReadInt32();


                    //Origional puzzle image
                    int lengthImageEncoded = bReader.ReadInt32();
                    byte[] imageEncoded = bReader.ReadBytes(lengthImageEncoded);
                    _origionalImage = new Texture2D(100, 100);
                    _origionalImage.LoadImage(imageEncoded);


                    //Puzzle image with joints
                    lengthImageEncoded = bReader.ReadInt32();
                    imageEncoded = bReader.ReadBytes(lengthImageEncoded);
                    _image = new Texture2D(100, 100);
                    _image.LoadImage(imageEncoded);

                    //Created background image
                    lengthImageEncoded = bReader.ReadInt32();
                    imageEncoded = bReader.ReadBytes(lengthImageEncoded);
                    _createdBackgroundImage = new Texture2D(100, 100);
                    _createdBackgroundImage.LoadImage(imageEncoded);
                    
                    //Top joint mask image
                    lengthImageEncoded = bReader.ReadInt32();
                    imageEncoded = bReader.ReadBytes(lengthImageEncoded);
                    _topJointsMaskImage = new Texture2D(100, 100);
                    _topJointsMaskImage.LoadImage(imageEncoded);

                    //Bottom joint mask image
                    lengthImageEncoded = bReader.ReadInt32();
                    imageEncoded = bReader.ReadBytes(lengthImageEncoded);
                    _botJointsMaskImage = new Texture2D(100, 100);
                    _botJointsMaskImage.LoadImage(imageEncoded);

                    //Left joint mask image
                    lengthImageEncoded = bReader.ReadInt32();
                    imageEncoded = bReader.ReadBytes(lengthImageEncoded);
                    _leftJointsMaskImage = new Texture2D(100, 100);
                    _leftJointsMaskImage.LoadImage(imageEncoded);

                    //Right joint mask iamge
                    lengthImageEncoded = bReader.ReadInt32();
                    imageEncoded = bReader.ReadBytes(lengthImageEncoded);
                    _rightJointsMaskImage = new Texture2D(100, 100);
                    _rightJointsMaskImage.LoadImage(imageEncoded);


                    //Load joint mask array
                    int lengthJointMaskArr = bReader.ReadInt32();
                    _jointMask = new Texture2D[lengthJointMaskArr];
                    for (int i = 0; i < lengthJointMaskArr; i++)
                    {
                        int TempLength = bReader.ReadInt32();

                        _jointMask[i] = new Texture2D(100, 100);
                        imageEncoded = bReader.ReadBytes(TempLength);
                        _jointMask[i].LoadImage(imageEncoded);
                    }


#region "Retreive Pieces Metadata"

                    _CreatedPiecesData = new SPieceInfo[_noOfPiecesInCol, _noOfPiecesInRow];

                    for (int RowTrav = 0; RowTrav < _noOfPiecesInCol; RowTrav++)
                    {
                        for (int ColTrav = 0; ColTrav < _noOfPiecesInRow; ColTrav++)
                        {
                            int pieceID = bReader.ReadInt32();

                            //Get joints info
                            int JointInfoLength = bReader.ReadInt32();
                            SPieceInfo TempSPieceInfo = new SPieceInfo(pieceID);

                            for (int i = 0; i < JointInfoLength; i++)
                            {
                                int jointType = bReader.ReadInt32();
                                int jointWidth = bReader.ReadInt32();
                                int jointHeight = bReader.ReadInt32();
                                int jointPosition = bReader.ReadInt32();


                                TempSPieceInfo.AddJoint(new SJointInfo((EJointType)jointType, (EJointPosition)jointPosition,
                                                        jointWidth, jointHeight));
                            }
                            

                            //Insert this piece data in list
                            _CreatedPiecesData[RowTrav, ColTrav] = TempSPieceInfo;

                        }
                    }

#endregion

                    bReader.Close();

                }
            }
            catch (System.Exception ex)
            {
                throw new System.Exception("Exception in load data 2: " + ex.Message);
            }
            
            return true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load data from stream of file for puzzle maker.
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        private bool LoadStreamData(System.IO.Stream stream)
        {
            System.IO.BinaryReader bReader = null;

            try
            {
                using (bReader = new System.IO.BinaryReader(stream))
                {
                    //Get secret number to check file intigrity
                    int secretNumber = bReader.ReadInt32();
                    if (secretNumber != 6640330)
                    {
                        bReader.Close();
                        Debug.LogError("Error reading file. Make sure this file is created with puzzle maker`s current version");
                        return false;
                    }

                    //Get basic variables data
                    _NoOfPiecesInRow = bReader.ReadInt32();
                    _NoOfPiecesInCol = bReader.ReadInt32();

                    _PieceWidthWithoutJoint = bReader.ReadInt32();
                    _PieceHeightWithoutJoint = bReader.ReadInt32();

                    ColorPieces = bReader.ReadBoolean();


#region "Retrieve basic images"


                    int lengthImageEncoded = bReader.ReadInt32();
                    byte[] imageEncoded = bReader.ReadBytes(lengthImageEncoded);
                    _Image = new Texture2D(100, 100);
                    _Image.LoadImage(imageEncoded);


                    int lengthBackgroundImageEncoded = bReader.ReadInt32();
                    byte[] createdBackgroundImageEncoded = bReader.ReadBytes(lengthBackgroundImageEncoded);
                    _CreatedBackgroundImage = new Texture2D(100, 100);
                    _CreatedBackgroundImage.LoadImage(createdBackgroundImageEncoded);

#endregion


#region "Retrieve joint mask array"

                    int lengthJointMaskArr = bReader.ReadInt32();
                    _JointMask = new Texture2D[lengthJointMaskArr];
                    for (int i = 0; i < lengthJointMaskArr; i++)
                    {
                        int TempLength = bReader.ReadInt32();

                        _JointMask[i] = new Texture2D(100, 100);
                        byte[] TempMaskArr = bReader.ReadBytes(TempLength);
                        _JointMask[i].LoadImage(TempMaskArr);
                    }

#endregion


#region "Retreive Pieces Metadata"

                    _CreatedImagePiecesData = new SPieceMetaData[_NoOfPiecesInCol, _NoOfPiecesInRow];

                    for (int RowTrav = 0; RowTrav < _NoOfPiecesInCol; RowTrav++)
                    {
                        for (int ColTrav = 0; ColTrav < _NoOfPiecesInRow; ColTrav++)
                        {
                            int pieceID = bReader.ReadInt32();

                            //Get joints info
                            int JointInfoLength = bReader.ReadInt32();
                            SPieceInfo TempSPieceInfo = new SPieceInfo(pieceID);

                            for (int i = 0; i < JointInfoLength; i++)
                            {
                                int jointType = bReader.ReadInt32();
                                int jointWidth = bReader.ReadInt32();
                                int jointHeight = bReader.ReadInt32();
                                int jointPosition = bReader.ReadInt32();


                                TempSPieceInfo.AddJoint(new SJointInfo((EJointType)jointType, (EJointPosition)jointPosition,
                                                        jointWidth, jointHeight));
                            }

                            //Get this piece image
                            int pieceImgArrLength = bReader.ReadInt32();
                            byte[] pieceTempArr = bReader.ReadBytes(pieceImgArrLength);
                            Texture2D pieceTempImage = new Texture2D(100, 100);
                            pieceTempImage.LoadImage(pieceTempArr);
                            pieceTempImage.wrapMode = TextureWrapMode.Clamp;

                            //Insert this piece data in list
                            _CreatedImagePiecesData[RowTrav, ColTrav] = new SPieceMetaData(TempSPieceInfo, pieceTempImage);

                        }
                    }

#endregion

                    bReader.Close();

                }
            }
            catch (System.Exception ex)
            {
                throw new System.Exception("Exception in load data 2: " + ex.Message);
                //Debug.LogError("Puzzle Maker LoadData Method: " + ex.Message);
            }

            return true;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a deep copy of this class
        /// </summary>
        /// <returns>Returns a deep copy of this class</returns>
        public SPieceInfo MakeCopy()
        {
            SPieceInfo Temp = new SPieceInfo(_ID);
            foreach (SJointInfo item in _Joints)
                Temp.AddJoint(item);

            return Temp;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Loads puzzle data from file stream of .pm file
        /// </summary>
        /// <param name="stream">Stream to load data from</param>
        /// <returns>Returns true if data loading is successfull false otherwise</returns>
        private bool LoadStreamData(System.IO.Stream stream)
        {
            System.IO.BinaryReader bReader = null;

            try
            {
                using (bReader = new System.IO.BinaryReader(stream))
                {
                    //Get secret number to check file intigrity
                    int secretNumber = bReader.ReadInt32();
                    if (secretNumber != _secretVersionNo)
                    {
                        bReader.Close();
                        Debug.LogError("Error reading file. Make sure this file is created with puzzle maker`s current version");
                        return(false);
                    }

                    //Get basic variables data
                    _noOfPiecesInRow = bReader.ReadInt32();
                    _noOfPiecesInCol = bReader.ReadInt32();

                    _pieceWidthWithoutJoint  = bReader.ReadInt32();
                    _pieceHeightWithoutJoint = bReader.ReadInt32();


                    //Origional puzzle image
                    int    lengthImageEncoded = bReader.ReadInt32();
                    byte[] imageEncoded       = bReader.ReadBytes(lengthImageEncoded);
                    _origionalImage = new Texture2D(100, 100);
                    _origionalImage.LoadImage(imageEncoded);


                    //Puzzle image with joints
                    lengthImageEncoded = bReader.ReadInt32();
                    imageEncoded       = bReader.ReadBytes(lengthImageEncoded);
                    _image             = new Texture2D(100, 100);
                    _image.LoadImage(imageEncoded);

                    //Created background image
                    lengthImageEncoded      = bReader.ReadInt32();
                    imageEncoded            = bReader.ReadBytes(lengthImageEncoded);
                    _createdBackgroundImage = new Texture2D(100, 100);
                    _createdBackgroundImage.LoadImage(imageEncoded);

                    //Top joint mask image
                    lengthImageEncoded  = bReader.ReadInt32();
                    imageEncoded        = bReader.ReadBytes(lengthImageEncoded);
                    _topJointsMaskImage = new Texture2D(100, 100);
                    _topJointsMaskImage.LoadImage(imageEncoded);

                    //Bottom joint mask image
                    lengthImageEncoded  = bReader.ReadInt32();
                    imageEncoded        = bReader.ReadBytes(lengthImageEncoded);
                    _botJointsMaskImage = new Texture2D(100, 100);
                    _botJointsMaskImage.LoadImage(imageEncoded);

                    //Left joint mask image
                    lengthImageEncoded   = bReader.ReadInt32();
                    imageEncoded         = bReader.ReadBytes(lengthImageEncoded);
                    _leftJointsMaskImage = new Texture2D(100, 100);
                    _leftJointsMaskImage.LoadImage(imageEncoded);

                    //Right joint mask iamge
                    lengthImageEncoded    = bReader.ReadInt32();
                    imageEncoded          = bReader.ReadBytes(lengthImageEncoded);
                    _rightJointsMaskImage = new Texture2D(100, 100);
                    _rightJointsMaskImage.LoadImage(imageEncoded);


                    //Load joint mask array
                    int lengthJointMaskArr = bReader.ReadInt32();
                    _jointMask = new Texture2D[lengthJointMaskArr];
                    for (int i = 0; i < lengthJointMaskArr; i++)
                    {
                        int TempLength = bReader.ReadInt32();

                        _jointMask[i] = new Texture2D(100, 100);
                        imageEncoded  = bReader.ReadBytes(TempLength);
                        _jointMask[i].LoadImage(imageEncoded);
                    }


                    #region "Retreive Pieces Metadata"

                    _CreatedPiecesData = new SPieceInfo[_noOfPiecesInCol, _noOfPiecesInRow];

                    for (int RowTrav = 0; RowTrav < _noOfPiecesInCol; RowTrav++)
                    {
                        for (int ColTrav = 0; ColTrav < _noOfPiecesInRow; ColTrav++)
                        {
                            int pieceID = bReader.ReadInt32();

                            //Get joints info
                            int        JointInfoLength = bReader.ReadInt32();
                            SPieceInfo TempSPieceInfo  = new SPieceInfo(pieceID);

                            for (int i = 0; i < JointInfoLength; i++)
                            {
                                int jointType     = bReader.ReadInt32();
                                int jointWidth    = bReader.ReadInt32();
                                int jointHeight   = bReader.ReadInt32();
                                int jointPosition = bReader.ReadInt32();


                                TempSPieceInfo.AddJoint(new SJointInfo((EJointType)jointType, (EJointPosition)jointPosition,
                                                                       jointWidth, jointHeight));
                            }


                            //Insert this piece data in list
                            _CreatedPiecesData[RowTrav, ColTrav] = TempSPieceInfo;
                        }
                    }

                    #endregion

                    bReader.Close();
                }
            }
            catch (System.Exception ex)
            {
                throw new System.Exception("Exception in load data 2: " + ex.Message);
            }

            return(true);
        }