Beispiel #1
0
        public SoundEditor(SoundPackage package, SoundLocation type)
        {
            // Create controls and style the header
            InitializeComponent();
            headerPanel.BackColor = Color.FromArgb(51, 53, 53);

            // Set internals
            NewSound = true;
            Package  = package;
            Type     = type;

            // Create new sound
            switch (package.SoundType)
            {
            case SoundType.Engine:
                Sound = new EngineSound();
                break;

            case SoundType.Truck:
                Sound = new TruckSound();
                break;

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

            InitializeForm();
        }
Beispiel #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;
        }
Beispiel #3
0
        private DialogResult AskUserAboutSwitch(SoundLocation type)
        {
            string prefix = (Type == SoundLocation.Exterior) ? "interior" : "exterior";
            string suffix = (Type == SoundLocation.Exterior) ? "exterior" : "interior";

            return(MessageBox.Show(
                       $"The selected sound file is an {prefix} sound file. Would you like to create a copy in the {suffix} folder?",
                       "Verification",
                       MessageBoxButtons.YesNo,
                       MessageBoxIcon.Question
                       ));
        }
Beispiel #4
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;
        }
Beispiel #5
0
        /// <summary>
        /// Fetches the specified sound accessory
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public AccessorySoundData GetSoundFile(SoundLocation type)
        {
            // Check cache
            switch (type)
            {
            case SoundLocation.Interior: if (Interior != null)
                {
                    return(Interior);
                }
                break;

            case SoundLocation.Exterior: if (Exterior != null)
                {
                    return(Exterior);
                }
                break;
            }

            // Load the file entry from the archive
            var entry = Archive.GetEntry(type == SoundLocation.Interior ? "interior.sii" : "exterior.sii");

            if (entry == null)
            {
                return(null);
            }

            // Parse the sii file
            var document = new SiiDocument(typeof(AccessorySoundData), typeof(SoundData), typeof(SoundEngineData));

            using (StreamReader reader = new StreamReader(entry.Open()))
                document.Load(reader.ReadToEnd().Trim());

            // return the main object
            var key  = new List <string>(document.Definitions.Keys).First();
            var item = document.GetDefinition <AccessorySoundData>(key);

            // Cache the sound data
            if (type == SoundLocation.Interior)
            {
                Interior = item;
            }
            else
            {
                Exterior = item;
            }

            // return
            return(item);
        }
Beispiel #6
0
        /// <summary>
        /// Sound File compiler
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        private static string CompileSoundFile(
            SoundLocation location,
            Truck truck,
            SoundPackageWrapper <EngineSoundPackage, EngineSound> enginePackage,
            SoundPackageWrapper <TruckSoundPackage, TruckSound> truckPackage,
            string unitName = null)
        {
            // Local variables
            var builder      = new SiiFileBuilder();
            var objectMap    = new Dictionary <string, Sound>();
            var engineSounds = enginePackage.GetSoundsByLocation(location);
            var truckSounds  = truckPackage.GetSoundsByLocation(location);

            // Figure out the accessory name
            var name = new StringBuilder(unitName ?? enginePackage.Package.UnitName);

            name.Append($".{truck.UnitName}.");
            name.AppendLineIf(location == SoundLocation.Exterior, "esound", "isound");

            // Write file intro
            builder.IndentStructs = false;
            builder.WriteStartDocument();

            // Write the accessory type
            builder.WriteStructStart("accessory_sound_data", name.ToString().TrimEnd());

            // Mark exterior or interior attribute
            builder.WriteAttribute("exterior_sound", location == SoundLocation.Exterior);
            builder.WriteLine();

            // ===
            // === Write Engine Attributes
            // ===
            foreach (var info in SoundInfo.Attributes.Values)
            {
                // Only engine sounds
                if (info.SoundType != SoundType.Engine)
                {
                    continue;
                }

                WriteAttribute(info, engineSounds, objectMap, builder);
            }

            // ===
            // === Write Truck Attributes
            // ===
            foreach (var info in SoundInfo.Attributes.Values)
            {
                // Only truck sounds
                if (info.SoundType != SoundType.Truck)
                {
                    continue;
                }

                WriteAttribute(info, truckSounds, objectMap, builder);
            }

            // Include directive.. Directives have no tabs at all!
            if (location == SoundLocation.Interior)
            {
                builder.WriteInclude("/def/vehicle/truck/common_sound_int.sui");
            }
            else
            {
                builder.WriteInclude("/def/vehicle/truck/common_sound_ext.sui");
            }

            // Close Accessory
            builder.WriteStructEnd();
            builder.WriteLine();

            // ===
            // === Append class objects
            // ===
            foreach (var item in objectMap)
            {
                // Get sound package
                SoundPackage package = (item.Value.SoundType == SoundType.Engine)
                    ? enginePackage.Package as SoundPackage
                    : truckPackage.Package as SoundPackage;

                // Add sound object
                item.Value.AppendTo(builder, item.Key, package);
            }

            // Write the include directive
            if (location == SoundLocation.Interior)
            {
                builder.WriteInclude("/def/vehicle/truck/common_sound_int_data.sui");
            }
            else
            {
                builder.WriteInclude("/def/vehicle/truck/common_sound_ext_data.sui");
            }

            // Close SiiNUnit
            builder.WriteEndDocument();
            return(builder.ToString());
        }
Beispiel #7
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);
                        }
                    }
                }
            }
        }
Beispiel #8
0
 /// <summary>
 /// Gets a dictionary of sounds contained in this package based on location
 /// </summary>
 /// <param name="location"></param>
 /// <returns></returns>
 public Dictionary <SoundAttribute, List <TSound> > GetSoundsByLocation(SoundLocation location)
 {
     return(Sounds[location]);
 }