Esempio n. 1
0
        public BufferFileMeta GetMetadataFromAttachment(LiteDB.BsonDocument doc)
        {
            var meta = new BufferFileMeta();

            foreach (var property in typeof(BufferFileMeta).GetProperties())
            {
                if (property.CanWrite && doc.ContainsKey(property.Name))
                {
                    var converter = TypeDescriptor.GetConverter(property.PropertyType);
                    property.SetValue(meta, converter.ConvertFromString(doc[property.Name]));
                }
            }

            meta.SetId(int.Parse(doc[nameof(BufferFileMeta.Id)].AsString));
            return(meta);
        }
Esempio n. 2
0
        public void ApplyPhysicsData(BsonDocument doc)
        {
            if (doc.ContainsKey("ph_pos"))
            {
                SetPosition(Location.FromDoubleBytes(doc["ph_pos"].AsBinary, 0));
            }
            if (doc.ContainsKey("ph_vel"))
            {
                SetVelocity(Location.FromDoubleBytes(doc["ph_vel"].AsBinary, 0));
            }
            if (doc.ContainsKey("ph_avel"))
            {
                SetAngularVelocity(Location.FromDoubleBytes(doc["ph_avel"].AsBinary, 0));
            }
            if (doc.ContainsKey("ph_ang_x") && doc.ContainsKey("ph_ang_y") && doc.ContainsKey("ph_ang_z") && doc.ContainsKey("ph_ang_w"))
            {
                double ax = (double)doc["ph_ang_x"].AsDouble;
                double ay = (double)doc["ph_ang_y"].AsDouble;
                double az = (double)doc["ph_ang_z"].AsDouble;
                double aw = (double)doc["ph_ang_w"].AsDouble;
                SetOrientation(new Quaternion(ax, ay, az, aw));
            }
            if (doc.ContainsKey("ph_grav"))
            {
                SetGravity(Location.FromDoubleBytes(doc["ph_grav"].AsBinary, 0));
            }
            if (doc.ContainsKey("ph_bounce"))
            {
                SetBounciness((double)doc["ph_bounce"].AsDouble);
            }
            if (doc.ContainsKey("ph_frict"))
            {
                SetFriction((double)doc["ph_frict"].AsDouble);
            }
            if (doc.ContainsKey("ph_mass"))
            {
                SetMass((double)doc["ph_mass"].AsDouble);
            }
            if (doc.ContainsKey("ph_cg"))
            {
                int cg = doc["ph_cg"].AsInt32;
                if (cg == 0)
                {
                    CGroup = CollisionUtil.NonSolid;
                }
                else if (cg == 1)
                {
                    CGroup = CollisionUtil.Solid;
                }
                else if (cg == 2)
                {
                    CGroup = CollisionUtil.Player;
                }
                else if (cg == 3)
                {
                    CGroup = CollisionUtil.Item;
                }
                else // cg == 4
                {
                    CGroup = CollisionUtil.Water;
                }
            }
            if (doc.ContainsKey("ph_flag"))
            {
                int flags = doc["ph_flag"].AsInt32;
                Visible = (flags & 1) == 1;
                GenBlockShadow = (flags & 2) == 2;
                TransmitMe = (flags & 128) == 128;

            }
        }