コード例 #1
0
        /// <summary>
        /// Serializes this transmission into SII format, and returns the result
        /// </summary>
        /// <returns></returns>
        public string ToSiiFormat(string truckName)
        {
            // Create local variables
            var series   = this.Series;
            var builder  = new SiiFileBuilder();
            var name     = $"{this.UnitName}.{truckName}.transmission";
            var hasNames = Gears.Any(x => !String.IsNullOrWhiteSpace(x.Name));

            // Make sure we have a file comment
            if (Comment == null || Comment.Length == 0)
            {
                Comment = new string[] { "Generated with the ATS Engine Generator Tool by Wilson212" }
            }
            ;

            // Write file intro
            builder.WriteStartDocument();

            // Write file comment
            builder.WriteCommentBlock(Comment);

            // Begin the engine accessory
            builder.WriteStructStart("accessory_transmission_data", name);

            // Generic Info
            builder.WriteAttribute("name", this.Name);
            builder.WriteAttribute("price", this.Price, "Transmission price", 1);
            builder.WriteAttribute("unlock", this.Unlock, "Unlocks @ Level", 2);
            builder.WriteAttribute("icon", series.Icon);
            builder.WriteLine();

            // Add names if we have them
            if (hasNames)
            {
                builder.WriteLine("# Transmission gear names");
                builder.WriteAttribute("transmission_names", ".names", false);
                builder.WriteLine();
            }

            // Diff Ratio
            builder.WriteLine("# Differential Ratio: 2.64, 2.85, 2.93, 3.08, 3.25, 3.36, 3.40?, 3.42, 3.55, 3.58(single) 3.70, 3.73?, 3.78, 3.91, 4.10");
            builder.WriteAttribute("differential_ratio", this.DifferentialRatio);
            builder.WriteLine();

            // Add Retarder
            if (Retarder > 0)
            {
                builder.WriteLine("# Retarder");
                builder.WriteAttribute("retarder", Retarder);
                builder.WriteLine();
            }

            if (StallTorqueRatio > 0.0m)
            {
                builder.WriteLine("# Torque Converter: 2.42, 2.34, 1.9, 1.79, 1.58");
                builder.WriteAttribute("stall_torque_ratio", StallTorqueRatio);
                builder.WriteLine();
            }

            // Create gear lists
            var reverseGears = new List <TransmissionGear>(this.Gears.Where(x => x.IsReverse));
            var forwardGears = new List <TransmissionGear>(this.Gears.Where(x => !x.IsReverse));

            // Reverse Gears
            int i = 0;

            builder.WriteLine($"# reverse gears");
            foreach (var gear in reverseGears)
            {
                builder.WriteAttribute($"ratios_reverse[{i++}]", gear.Ratio);
            }
            builder.WriteLine();

            // Forward Gears
            i = 0;
            builder.WriteLine($"# forward gears");
            foreach (var gear in forwardGears)
            {
                builder.WriteAttribute($"ratios_forward[{i++}]", gear.Ratio);
            }

            // Write the default[]...
            if (Defaults != null && Defaults.Length > 0)
            {
                builder.WriteLine();
                builder.WriteLine("# Attachments");
                foreach (string line in Defaults)
                {
                    builder.WriteAttribute("defaults[]", line);
                }
            }

            // Define is we output suitible_for and conflict_with for engines
            bool writeSuitables = Program.Config.CompileOption == CompileOption.TransmissionOnly ||
                                  Program.Config.CompileOption == CompileOption.Both;
            var conflicts = this.EngineConflicts.ToList();
            var suitables = this.SuitableEngines.ToList();

            // Write the conflict_with[]...
            if (conflicts.Count > 0 || (Conflicts != null && Conflicts.Length > 0))
            {
                builder.WriteLine();
                builder.WriteLine("# Conflicts");

                // Engines
                foreach (string eng in conflicts.Select(x => x.Engine.UnitName))
                {
                    builder.WriteAttribute("conflict_with[]", $"{eng}.{truckName}.engine");
                }

                // Other Conflicts
                if (Conflicts != null)
                {
                    foreach (string line in Conflicts)
                    {
                        builder.WriteAttribute("conflict_with[]", line);
                    }
                }
            }

            // Write the conflict_with[]...
            if ((writeSuitables && suitables.Count > 0) || (SuitableFor != null && SuitableFor.Length > 0))
            {
                builder.WriteLine();
                builder.WriteLine("# Suitables");

                // Engines?
                if (writeSuitables)
                {
                    foreach (string eng in suitables.Select(x => x.Engine.UnitName))
                    {
                        builder.WriteAttribute("suitable_for[]", $"{eng}.{truckName}.engine");
                    }
                }

                // Other Suitables
                if (SuitableFor != null)
                {
                    foreach (string line in SuitableFor)
                    {
                        builder.WriteAttribute("suitable_for[]", line);
                    }
                }
            }

            // Close brackets
            builder.WriteStructEnd();

            // Do we have gear names?
            if (hasNames)
            {
                builder.WriteLine();
                builder.WriteStructStart("transmission_names", ".names");

                // Neutral always first
                builder.WriteAttribute("neutral", "N");

                // Forward Gears
                i = 0; // Reset
                builder.WriteLine();
                builder.WriteLine("# Forward Gear Names");
                foreach (var gear in forwardGears)
                {
                    name = GetGearNameAtIndex(i, gear, forwardGears);
                    builder.WriteAttribute($"forward[{i++}]", name);
                }

                // Reverse Gears
                i = 0; // Reset
                builder.WriteLine();
                builder.WriteLine("# Reverse Gear Names");
                foreach (var gear in reverseGears)
                {
                    name = GetGearNameAtIndex(i, gear, reverseGears);
                    builder.WriteAttribute($"reverse[{i++}]", name);
                }

                builder.WriteStructEnd();
            }

            // End brace
            builder.WriteEndDocument();

            // Define file paths
            return(builder.ToString().Replace("{{{NAME}}}", truckName).TrimEnd());
        }