Exemple #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);
            }
        }
Exemple #2
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());
        }