public IReadOnlyList <MapIndex> Deserialize()
        {
            IBufferReadable buffer        = GenerateMapIndexBuffer();
            int             mapIndexCount = buffer.buffer.Length / (sizeof(short) * 3 + sizeof(byte));

            MapIndex[] indexArray = new MapIndex[mapIndexCount];

            for (int index = 0; index < mapIndexCount; index++)
            {
                //ID is basically the unique value represneing bitwise combined X,Y region id.
                int  id      = buffer.getUnsignedLEShort();
                int  terrain = buffer.getUnsignedLEShort();
                int  objects = buffer.getUnsignedLEShort();
                bool members = buffer.getUnsignedByte() == 1;

                indexArray[index] = new MapIndex(members, objects, id, terrain);
            }

            return(indexArray);
        }
Пример #2
0
        public static String readFromStream(int length, IBufferReadable stream)
        {
            int pointer = 0;
            int l       = -1;

            for (int c = 0; c < length; c++)
            {
                int encodedLetter = stream.getUnsignedByte();
                int letter        = encodedLetter >> 4 & 0xf;
                if (l == -1)
                {
                    if (letter < 13)
                    {
                        characterList[pointer++] = validChars[letter];
                    }
                    else
                    {
                        l = letter;
                    }
                }
                else
                {
                    characterList[pointer++] = validChars[((l << 4) + letter) - 195];
                    l = -1;
                }

                letter = encodedLetter & 0xf;
                if (l == -1)
                {
                    if (letter < 13)
                    {
                        characterList[pointer++] = validChars[letter];
                    }
                    else
                    {
                        l = letter;
                    }
                }
                else
                {
                    characterList[pointer++] = validChars[((l << 4) + letter) - 195];
                    l = -1;
                }
            }

            bool endOfSentence = true;

            for (int c = 0; c < pointer; c++)
            {
                char character = characterList[c];
                if (endOfSentence && character >= 'a' && character <= 'z')
                {
                    characterList[c] += '\uFFE0';
                    endOfSentence     = false;
                }

                if (character == '.' || character == '!' || character == '?')
                {
                    endOfSentence = true;
                }
            }

            return(new String(characterList, 0, pointer));
        }