Пример #1
0
        private BitBuffer SerializeStructure()
        {
            BitBuffer buffer = new MutableBitBuffer((RealPlacedBlock.SerializedBitsSize
                                                     * _structure.RealBlockCount + 7) / 8);

            _structure.Serialize(buffer);
            return(buffer);
        }
Пример #2
0
        private static CompleteStructure CreateStructure(byte playerId)
        {
            MutableBitBuffer buffer = new MutableBitBuffer();

            buffer.SetContents(PlayerStructures[playerId]);
            CompleteStructure structure = CompleteStructure.Create(buffer, playerId);

            Assert.IsNotNull(structure, "The example structure creation must be successful.");
            structure.transform.position = new Vector3(0, 10, 0);
            return(structure);
        }
Пример #3
0
        public void ResetStructure()
        {
            string    file = GetFilePath();
            BitBuffer data;

            if (File.Exists(file))
            {
                MutableBitBuffer temp = new MutableBitBuffer();
                temp.SetContents(File.ReadAllBytes(file));
                data = temp;
            }
            else
            {
                data = DefaultStructure;
            }

            Assert.IsTrue(_structure.Deserialize(data), "Failed to load the structure.");
        }
Пример #4
0
        public void SerializeDeserialize()
        {
            BitBuffer buffer = new MutableBitBuffer((6 * 4 * Rotation.SerializedBitsSize + 7) / 8);

            for (int facingBit = 0; facingBit < 6; facingBit++)
            {
                for (byte variant = 0; variant < 4; variant++)
                {
                    byte rotation = Rotation.GetByte((BlockSides)(1 << facingBit), variant);

                    Rotation.Serialize(buffer, rotation);
                    Assert.AreEqual(
                        rotation,
                        Rotation.Deserialize(buffer)
                        );
                }
            }
        }
Пример #5
0
        private void Update()
        {
            if (Input.GetButtonDown("Fire1"))
            {
                Place();
            }
            else if (Input.GetButtonDown("Fire2"))
            {
                Delete();
            }

            Rotate(Input.GetAxisRaw("MouseScroll"));
            if (Input.GetButtonDown("Fire3"))
            {
                Switch();
            }

            // ReSharper disable once UnusedVariable
            if (GetSelectedBlock(out GameObject block, out BlockPosition position, out byte rotation))
            {
                if (!position.Equals(_previousPreviewPosition))
                {
                    ShowPreview(position, rotation);
                }
            }
            else
            {
                Destroy(_previewObject);
                _previousPreviewPosition = null;
            }

            if (Input.GetButtonDown("Ability"))
            {
                new Action(() => {
                    EditableStructure.Errors errors = _structure.GetStructureErrors();
                    if (errors != EditableStructure.Errors.None)
                    {
                        Debug.Log("Structure error: " + errors);
                        return;
                    }

                    IDictionary <BlockPosition, IPlacedBlock> notConnected = _structure.GetNotConnectedBlocks();
                    Assert.IsNotNull(notConnected, "The lack of the presence of the Mainframe was not shown among the errors.");
                    if (notConnected.Count != 0)
                    {
                        Debug.Log("Structure error: not connected blocks");
                        return;
                    }

                    BitBuffer someBuffer = new MutableBitBuffer((RealPlacedBlock.SerializedBitsSize
                                                                 * _structure.RealBlockCount + 7) / 8);
                    _structure.Serialize(someBuffer);
                    Debug.Log("Structure: " + string.Join(", ", someBuffer.Array));
                    CompleteStructure complete = CompleteStructure.Create(someBuffer, 1);
                    Assert.IsNotNull(complete, "Own CompleteStructure creation mustn't fail.");

                    complete.transform.position = new Vector3(0, 10, 0);
                    complete.gameObject.AddComponent <LocalBotController>();
                    _camera.gameObject.AddComponent <PlayingCameraController>().Initialize(complete);

                    Destroy(_camera.gameObject.GetComponent <BuildingCameraController>());
                    Destroy(gameObject);

                    CompleteStructure otherStructure = CompleteStructure.Create(ExampleStructure, 2);
                    Assert.IsNotNull(otherStructure, "Other CompleteStructure creation mustn't fail.");
                    otherStructure.transform.position = new Vector3(150, 5, 150);
                }).Invoke();
            }
        }