コード例 #1
0
        internal ZDictionary(Story story, ZText ztext)
        {
            this.story = story;
            this.ztext = ztext;

            this.address = Header.ReadDictionaryAddress(story.Memory);

            var reader = new MemoryReader(story.Memory, address);

            int wordSepCount = reader.NextByte();

            this.wordSeparators = reader.NextBytes(wordSepCount).ConvertAll(b => (char)b).AsReadOnly();

            int entryLength = reader.NextByte();
            int entryCount  = reader.NextWord();

            int zwordsSize = story.Version <= 3 ? 2 : 3;
            int dataSize   = entryLength - (zwordsSize * 2);

            this.entries = new List <ZDictionaryEntry>(entryCount);
            for (int i = 0; i < entryCount; i++)
            {
                var entryAddress = reader.Address;
                var entryZWords  = reader.NextWords(zwordsSize);
                var entryData    = reader.NextBytes(dataSize);
                var entryZText   = ztext.ZWordsAsString(entryZWords, ZTextFlags.All);
                entries.Add(new ZDictionaryEntry(entryAddress, i, entryZWords, entryZText, entryData));
            }
        }
コード例 #2
0
        public void NextBytesWorksAsExpectedFromDifferentIndex()
        {
            byte[] bytes  = { 0xff, 0x00, 0x0f, 0xf0, 0xff, 0x00, 0x0f, 0xf0 };
            var    reader = new MemoryReader(bytes, 4);

            byte[][] expected =
            {
                new byte[] { 0xff, 0x00 },
                new byte[] { 0x0f, 0xf0 },
                new byte[] { 0xff, 0x00 },
                new byte[] { 0x0f, 0xf0 }
            };

            for (int i = 2; i < expected.Length; i++)
            {
                var b = reader.NextBytes(2);
                Assert.That(b, Is.EqualTo(expected[i]));
            }

            Assert.That(reader.Address, Is.EqualTo(reader.Size));

            Assert.That(() =>
                        reader.NextBytes(2),
                        Throws.InstanceOf <InvalidOperationException>());
        }