Exemplo n.º 1
0
        public override void Read(GameAssetStore store, IDeserializer context)
        {
            base.Read(store, context);
            this.Crew           = context.Read <int>("crew");
            this.Passengers     = context.Read <int>("passengers");
            this.Acceleration   = context.Read <float>("acceleration");
            this.TurnSpeed      = context.Read <float>("turn_speed");
            this.MaxHealth      = context.Read <float>("health");
            this.Mass           = context.Read <float>("mass");
            this.RadarRadius    = context.Read <float>("radar");
            this.EnginePosition = context.Read <Vector2>("engine", CommonSerialize.Read);
            var spriteName = context.Read <string>("sprite");

            this.SpriteTemplate = store.Sprites[spriteName];
            var weapons = context.ReadList("weapons", (ctx) =>
            {
                var name = ctx.Read <string>("weapon");
                var pos  = ctx.Read <Vector2>("pos", CommonSerialize.Read);
                return(new WeaponPlacement
                {
                    Weapon = store.Objects.Get <WeaponTemplate>(name),
                    LocalPosition = pos,
                });
            });

            this.AddWeapons(weapons);
        }
Exemplo n.º 2
0
 public static void Read(IDeserializer context, out TileStencil stencil)
 {
     stencil = new TileStencil();
     foreach (var entry in context.ReadList <KeyValuePair <Point, ITile> >("tiles", Read))
     {
         stencil[entry.Key] = entry.Value;
     }
 }
Exemplo n.º 3
0
        public static void Read(Store store, IDeserializer context, out BlockStore blockStore)
        {
            var tileSize = context.Read <int>("tilesize");

            blockStore = new BlockStore(tileSize);
            var materials = context.ReadList <KeyValuePair <MaterialType, IList <int> > >("materials", Read);

            foreach (var kvp in materials)
            {
                blockStore.Materials[kvp.Key].AddRange(kvp.Value);
            }
            var tiles = context.ReadList <ISpriteTemplate, Store>("tiles", store, Read);

            blockStore.Tiles.AddRange(tiles);
            var flags = context.ReadList <KeyValuePair <int, TileFlags> >("flags", Read);

            foreach (var flag in flags)
            {
                blockStore[flag.Key] = flag.Value;
            }
        }
Exemplo n.º 4
0
        private static void Read(IDeserializer context, out KeyValuePair <MaterialType, IList <int> > blocks)
        {
            MaterialType material;

            if (!Enum.TryParse(context.Read <string>("material"), out material))
            {
                throw new InvalidOperationException("Unknown material type");
            }
            var tiles = context.ReadList <int>("tiles");

            blocks = new KeyValuePair <MaterialType, IList <int> >(material, tiles);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Reads an arbitrary object from the input stream.
        /// </summary>
        /// <param name="expectedType">the expected class if the protocol doesn't supply it.</param>
        /// <returns>Read object</returns>
        /// <exception cref="CHessianException"/>
        /// <exception cref="CHessianException"/>
        public override object ReadObject(Type expectedType)
        {
            object objResult = null;

            if (expectedType == null || expectedType.Equals(typeof(object)))
            {
                objResult = ReadObject();
            }
            else
            {
                int intTag = Read();
                if (intTag != CHessianProtocolConstants.PROT_NULL)
                {
                    switch (intTag)
                    {
                    case CHessianProtocolConstants.PROT_MAP_TYPE:
                    {
                        string strType = ReadType();

                        AbstractDeserializer deserializer = GetObjectDeserializer(strType);

                        if (expectedType == deserializer.GetOwnType() || expectedType.IsAssignableFrom(deserializer.GetOwnType()))
                        {
                            return(deserializer.ReadMap(this));
                        }

                        deserializer = GetDeserializer(expectedType);


                        return(deserializer.ReadMap(this));
                    }

                    case CHessianProtocolConstants.PROT_REF_TYPE:
                    {
                        int intRefNumber = ParseInt();
                        return(m_arrRefs[intRefNumber]);
                    }

                    case 'r':
                    {
                        throw new CHessianException("remote type is not implemented");
                    }

                    case CHessianProtocolConstants.PROT_LIST_TYPE:
                    {
                        string        strType      = this.ReadType();
                        int           intLength    = this.ReadLength();
                        IDeserializer deserializer = this.m_serializerFactory.GetObjectDeserializer(strType);
                        if ((expectedType == deserializer.GetOwnType() || expectedType.IsAssignableFrom(deserializer.GetOwnType())))
                        {
                            //if (expectedType != deserializer.GetOwnType() && expectedType.IsAssignableFrom(deserializer.GetOwnType()))
                            return(deserializer.ReadList(this, intLength));
                        }
                        deserializer = m_serializerFactory.GetDeserializer(expectedType);
                        return(deserializer.ReadList(this, intLength));
                    }
                    }

                    m_intPeek = intTag;

                    objResult = m_serializerFactory.GetDeserializer(expectedType).ReadObject(this);
                }
            }
            return(objResult);
        }