Пример #1
0
        /// <summary>
        /// Writes an attribute to the StringBuilder if the attribute type exists in the sounds list.
        /// </summary>
        /// <param name="sounds">The list of sound attributes and their sounds for this package</param>
        /// <param name="classMap">A ruuning list of objects that will be later written to the buffer.</param>
        /// <param name="builder">The current string buffer</param>
        private static void WriteAttribute <TSound>(SoundInfo info,
                                                    Dictionary <SoundAttribute, List <TSound> > sounds,
                                                    Dictionary <string, Sound> classMap,
                                                    SiiFileBuilder builder) where TSound : Sound
        {
            // Only add the sound if it exists (obviously)
            List <TSound> soundList;

            if (sounds.TryGetValue(info.AttributeType, out soundList))
            {
                if (info.IsArray)
                {
                    int    i    = 0;
                    string name = info.AttributeName;
                    foreach (var snd in soundList)
                    {
                        // Write attribute line
                        string sname = info.StructName + i++;
                        builder.WriteLineIf(info.Indexed, $"{name}[{i - 1}]: {sname}", $"{name}[]: {sname}");

                        // Add to classmap
                        classMap.Add(sname, snd);
                    }
                }
                else
                {
                    // Write attribute line
                    builder.WriteAttribute(info.AttributeName, info.StructName, false);

                    // Add to classmap
                    classMap.Add(info.StructName, soundList[0]);
                }

                // Trailing line?
                builder.WriteLineIf(info.AppendLineAfter);
            }
        }
Пример #2
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);
                        }
                    }
                }
            }
        }
Пример #3
0
        private void InitializeForm()
        {
            // Set title
            this.Text = (Type == SoundLocation.Interior) ? "Interior Sound Editor" : "Exterior Sound Editor";

            // Get a list of existing sound attributes already in the sound package
            var existing = new List <SoundAttribute>();

            if (NewSound)
            {
                switch (Package.SoundType)
                {
                case SoundType.Engine:
                    var ep = (EngineSoundPackage)Package;
                    existing.AddRange(ep.EngineSounds.Where(x => x.Location == Type).Select(x => x.Attribute));
                    break;

                case SoundType.Truck:
                    var tp = (TruckSoundPackage)Package;
                    existing.AddRange(tp.TruckSounds.Where(x => x.Location == Type).Select(x => x.Attribute));
                    break;

                default:
                    throw new Exception("Invalid sound type");
                }
            }

            // Fill selection box
            foreach (var name in Enum.GetNames(typeof(SoundAttribute)))
            {
                // Fetch sound info for this attribute
                var       val = (SoundAttribute)Enum.Parse(typeof(SoundAttribute), name);
                SoundInfo si  = SoundInfo.Attributes[val];

                // Skip existing sounds for this package that are not array sounds
                if (si.SoundType != Package.SoundType || (existing.Contains(val) && !si.IsArray))
                {
                    continue;
                }

                // Add item
                attrType.Items.Add(val);
                if (Sound != null && val == Sound.Attribute)
                {
                    attrType.SelectedIndex = attrType.Items.Count - 1;
                }
            }

            // If not a new sound, fill form data
            if (!NewSound)
            {
                attrType.Enabled       = false;
                fileNameBox.Text       = Sound.FileName;
                volumeBox.Value        = (decimal)(Sound.Volume * 100);
                checkBox2D.Checked     = Sound.Is2D;
                checkBoxLooped.Checked = Sound.Looped;
                if (Package.SoundType == SoundType.Engine)
                {
                    var es = (EngineSound)Sound;
                    pitchBox.Value  = es.PitchReference;
                    maxRpmBox.Value = es.MaxRpm;
                    minRpmBox.Value = es.MinRpm;
                }
            }

            // Enable or Disable engine specific inputs
            bool enabled = Package.SoundType == SoundType.Engine;

            groupBox1.Enabled = enabled;
            pitchBox.Enabled  = enabled;
            maxRpmBox.Enabled = enabled;
            minRpmBox.Enabled = enabled;

            // Set default attribute index
            if (attrType.SelectedIndex == -1)
            {
                attrType.SelectedIndex = 0;
            }
        }