示例#1
0
 /// <summary>
 /// A private constructor
 /// </summary>
 private SoundInfo(SoundAttribute attr, SoundType type, string attrName, string structName, bool array = false, bool space = false)
 {
     this.AttributeType   = attr;
     this.AttributeName   = attrName;
     this.SoundType       = type;
     this.StructName      = structName;
     this.IsArray         = array;
     this.AppendLineAfter = space;
 }
示例#2
0
        /// <summary>
        /// Creates a new instance of <see cref="TruckSound"/>
        /// </summary>
        public TruckSound(SoundData data, SoundAttribute attr, SoundLocation location)
        {
            this.Location  = location;
            this.Attribute = attr;

            this.FileName = data.Name;
            this.Is2D     = data.Is2D;
            this.Looped   = data.Looped;
            this.Volume   = data.Volume;
        }
示例#3
0
        /// <summary>
        /// Creates a new instance of <see cref="EngineSound"/>
        /// </summary>
        public EngineSound(SoundEngineData data, SoundAttribute attr, SoundLocation location)
        {
            this.Location  = location;
            this.Attribute = attr;

            this.FileName       = data.Name;
            this.Is2D           = data.Is2D;
            this.Looped         = data.Looped;
            this.MinRpm         = (int)data.MinRPM;
            this.MaxRpm         = (int)data.MaxRPM;
            this.Volume         = data.Volume;
            this.PitchReference = (int)data.Pitch;
        }
示例#4
0
        /// <summary>
        /// Imports the sound accessory objects into the AppDatabase
        /// </summary>
        /// <param name="db">An open AppData.db connection</param>
        /// <param name="package">The <see cref="SoundPackage"/> that will own these accessory objects</param>
        /// <param name="data">The accessory data object</param>
        /// <param name="location">The sound type</param>
        protected void ImportSounds(
            AppDatabase db,
            SoundPackage package,
            AccessorySoundData data,
            SoundLocation location,
            List <PropertyInfo> properties,
            List <string> files)
        {
            // Using reflection, we will now loop through each property
            // with the SoundAttribute attribute, and create an EngineSound
            // entity using that data.
            foreach (var prop in properties)
            {
                // Define local vars
                SoundAttribute attr = prop.GetCustomAttribute <SoundAttributeAttribute>().Attribute;
                SoundInfo      info = SoundInfo.Attributes[attr];

                // Skip if wrong sound type
                if (info.SoundType != Type)
                {
                    continue;
                }

                if (Type == SoundType.Engine)
                {
                    if (info.IsArray)
                    {
                        if (info.IsEngineSoundData)
                        {
                            var values = ((SoundEngineData[])prop.GetValue(data) ?? new SoundEngineData[] { });
                            foreach (var sound in values)
                            {
                                db.EngineSounds.Add(new EngineSound(sound, attr, location)
                                {
                                    PackageId = package.Id
                                });
                                files.Add(sound.Name);
                            }
                        }
                        else
                        {
                            var values = ((SoundData[])prop.GetValue(data) ?? new SoundData[] { });
                            foreach (var sound in values)
                            {
                                db.EngineSounds.Add(new EngineSound(sound, attr, location)
                                {
                                    PackageId = package.Id
                                });
                                files.Add(sound.Name);
                            }
                        }
                    }
                    else
                    {
                        if (info.IsEngineSoundData)
                        {
                            var sound = (SoundEngineData)prop.GetValue(data);
                            if (sound != null)
                            {
                                db.EngineSounds.Add(new EngineSound(sound, attr, location)
                                {
                                    PackageId = package.Id
                                });
                                files.Add(sound.Name);
                            }
                        }
                        else
                        {
                            var sound = (SoundData)prop.GetValue(data);
                            if (sound != null)
                            {
                                db.EngineSounds.Add(new EngineSound(sound, attr, location)
                                {
                                    PackageId = package.Id
                                });
                                files.Add(sound.Name);
                            }
                        }
                    }
                }
                else if (Type == SoundType.Truck)
                {
                    if (info.IsArray)
                    {
                        var values = ((SoundData[])prop.GetValue(data) ?? new SoundData[] { });
                        foreach (var sound in values)
                        {
                            db.TruckSounds.Add(new TruckSound(sound, attr, location)
                            {
                                PackageId = package.Id
                            });
                            files.Add(sound.Name);
                        }
                    }
                    else
                    {
                        var sound = (SoundData)prop.GetValue(data);
                        if (sound != null)
                        {
                            db.TruckSounds.Add(new TruckSound(sound, attr, location)
                            {
                                PackageId = package.Id
                            });
                            files.Add(sound.Name);
                        }
                    }
                }
            }
        }
 public SoundAttributeAttribute(SoundAttribute attribute)
 {
     this.Attribute = attribute;
 }