예제 #1
0
        /// <summary>
        /// Recursively deserializes a Token and its children from a stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        /// <returns>Returns the Token that was deserialized.</returns>
        public static Token LoadFromFile(BinaryReader stream)
        {
            var newToken = new Token();

            newToken.Name = stream.ReadString();
            var flags = stream.Read7BitEncodedInt();
            //Format: child count, reserved, has text, value is integral, has value.
            var numTokens = flags >> 4;

            if ((flags & 1) == 1)
            {
                var isInt = ((flags & 2) == 2);
                if (isInt)
                {
                    newToken.Value = stream.Read7BitEncodedInt();
                }
                else
                {
                    newToken.Value = stream.ReadSingle();
                }
            }
            if ((flags & 4) == 4)
            {
                newToken.Text = stream.ReadString();
            }
            for (var i = 0; i < numTokens; i++)
            {
                newToken.Tokens.Add(Token.LoadFromFile(stream));
            }
            return(newToken);
        }
예제 #2
0
        public static new DroppedItem LoadFromFile(BinaryReader stream)
        {
            Toolkit.ExpectFromFile(stream, "DROP", "dropped item entity");
            var e = Entity.LoadFromFile(stream);

            //Handle broken references (warhammer > war_hammer)
            var id     = stream.ReadString();
            var exists = NoxicoGame.KnownItems.Any(ki => ki.ID == id);

            if (!exists)
            {
                var attempt = NoxicoGame.KnownItems.FirstOrDefault(ki => ki.ID.Replace("_", string.Empty) == id);
                if (attempt != null)
                {
                    id = attempt.ID;
                }
                else
                {
                    id = NoxicoGame.KnownItems[0].ID;                     //Fallback.
                }
            }

            var newItem = new DroppedItem(id)
            {
                ID              = e.ID,
                Glyph           = e.Glyph,
                ForegroundColor = e.ForegroundColor,
                BackgroundColor = e.BackgroundColor,
                XPosition       = e.XPosition,
                YPosition       = e.YPosition,
            };

            newItem.Token = Token.LoadFromFile(stream);
            return(newItem);
        }
예제 #3
0
        public static new Container LoadFromFile(BinaryReader stream)
        {
            Toolkit.ExpectFromFile(stream, "CONT", "container entity");
            var e            = Entity.LoadFromFile(stream);
            var newContainer = new Container(string.Empty, null)
            {
                ID              = e.ID,
                Glyph           = e.Glyph,
                ForegroundColor = e.ForegroundColor,
                BackgroundColor = e.BackgroundColor,
                XPosition       = e.XPosition,
                YPosition       = e.YPosition,
            };

            newContainer.Token = Token.LoadFromFile(stream);
            Clutter.ResetToKnown(newContainer);
            return(newContainer);
        }