Esempio n. 1
0
        public void Write_ScanLineByteWidth()
        {
            ArtFile artFile = GetTestArtFile();

            // Check no throw if scanLine next 4 byte aligned
            using (MemoryStream stream = new MemoryStream())
            {
                artFile.Write(stream);
            }

            // Check throw if scanLine > width && < 4 byte aligned
            using (MemoryStream stream = new MemoryStream())
            {
                artFile.imageMetas[0].scanLineByteWidth = 11;
                Assert.ThrowsException <Exception>(() => artFile.Write(stream));
            }

            // Check throw if scanLine > first 4 byte align
            using (MemoryStream stream = new MemoryStream())
            {
                artFile.imageMetas[0].scanLineByteWidth = 16;
                Assert.ThrowsException <Exception>(() => artFile.Write(stream));
            }

            // Check throw if scanLine < width but still 4 byte aligned
            using (MemoryStream stream = new MemoryStream())
            {
                artFile.imageMetas[0].scanLineByteWidth = 8;
                Assert.ThrowsException <Exception>(() => artFile.Write(stream));
            }
        }
Esempio n. 2
0
        public void ReadMissingFile()
        {
            Assert.ThrowsException <FileNotFoundException>(() => ArtFile.Read("MissingFile.prt"));

            // Check if filename is an empty string
            Assert.ThrowsException <ArgumentException>(() => ArtFile.Read(""));
        }
Esempio n. 3
0
        public void ReadStream()
        {
            // We want a simple valid source to load from, so we will create one by first writing it
            using (MemoryStream stream = new MemoryStream())
            {
                new ArtFile().Write(stream);

                // Read from stream
                stream.Seek(0, SeekOrigin.Begin);
                ArtFile artFile = ArtFile.Read(stream);
            }
        }
Esempio n. 4
0
        private ArtFile GetTestArtFile()
        {
            ArtFile artFile = new ArtFile();

            artFile.palettes.Add(new Palette());

            ImageMeta imageMeta = new ImageMeta();

            imageMeta.width             = 10;
            imageMeta.scanLineByteWidth = 12;
            imageMeta.paletteIndex      = 0;
            artFile.imageMetas.Add(imageMeta);

            return(artFile);
        }
Esempio n. 5
0
        public void ReadBinary()
        {
            // We want a simple valid source to load from, so we will create one by first writing it
            using (MemoryStream stream = new MemoryStream())
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    new ArtFile().Write(writer);

                    // Read from stream as BinaryReader
                    writer.BaseStream.Seek(0, SeekOrigin.Begin);
                    using (BinaryReader reader = new BinaryReader(writer.BaseStream))
                    {
                        ArtFile artFile = ArtFile.Read(reader);
                    }
                }
        }
Esempio n. 6
0
        public void Write_PaletteIndexRange()
        {
            ArtFile artFile = GetTestArtFile();

            // Check for no throw when ImageMeta.paletteIndex is within palette container's range
            using (MemoryStream stream = new MemoryStream())
            {
                artFile.Write(stream);
            }

            artFile.palettes.Clear();

            // Check for throw due to ImageMeta.paletteIndex outside of palette container's range
            using (MemoryStream stream = new MemoryStream())
            {
                Assert.ThrowsException <Exception>(() => artFile.Write(stream));
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Loads required assets for the game.
        /// </summary>
        public static void Initialize(MonoBehaviour coroutineOwner, string[] modBundlePaths, OnInitializeCallback onInitCB)
        {
            // Load art file
            try
            {
                // Prepare Legacy manager
                _LegacyAssets = new ResourceManager(".");

                // Get art file
                Stream artPartStream = _LegacyAssets.GetResourceStream("op2_art.prt");
                _ArtFile = ArtFile.Read(artPartStream);
            }
            catch (System.Exception ex)
            {
                Debug.LogException(ex);

                // Inform caller of failure
                onInitCB?.Invoke(false);
                return;
            }

            // Load asset bundle
            coroutineOwner.StartCoroutine(LoadAssetsRoutine(modBundlePaths, onInitCB));
        }
Esempio n. 8
0
        public void Write_PaletteColors()
        {
            ArtFile artFile = GetTestArtFile();

            byte red  = 255;
            byte blue = 0;

            artFile.palettes[0].colors[0] = new Color(red, 0, blue, 0);

            using (MemoryStream stream = new MemoryStream())
            {
                artFile.Write(stream);

                // Check ArtFile palette remains unchanged after write
                Assert.AreEqual(red, artFile.palettes[0].colors[0].red);
                Assert.AreEqual(blue, artFile.palettes[0].colors[0].blue);

                // Check ArtFile palette written to disk properly
                stream.Seek(0, SeekOrigin.Begin);
                artFile = ArtFile.Read(stream);
                Assert.AreEqual(red, artFile.palettes[0].colors[0].red);
                Assert.AreEqual(blue, artFile.palettes[0].colors[0].blue);
            }
        }
Esempio n. 9
0
 public void ReadEmptyFile()
 {
     Assert.ThrowsException <EndOfStreamException>(() => ArtFile.Read("src/Sprite/data/Empty.prt"));
 }
Esempio n. 10
0
        public void PropertyGet_Id_ReturnsExpected()
        {
            var pg = new ArtFile("82128 acc128 pg48.PDF");

            pg.Id.Should().Be(82128);
        }