private static string GetReturn(TorqueType type, string stmt)
        {
            string prefix = "";

            if (!type.IsVoid)
            {
                prefix = "return ";
            }
            return(prefix + type.GetReturnString(stmt));
        }
Exemple #2
0
 public Vehicles()
 {
     this.maximumTorqueField       = new TorqueType();
     this.maximumSpeedField        = new SpeedDimension();
     this.maximumRangeField        = new RangeDimension();
     this.maximumHorsepowerField   = new HorsepowerDimension();
     this.fuelEconomyHighwayField  = new FuelEconomyDimension();
     this.fuelEconomyCombinedField = new FuelEconomyDimension();
     this.fuelEconomyCityField     = new FuelEconomyDimension();
     this.co2EmissionField         = new EmissionsDimension();
 }
 public PowerTransmission()
 {
     this.springRateField = new TorqueType();
     this.minimumSpringCompressionLoadField = new TorqueType();
     this.maximumTorqueField                = new TorqueType();
     this.maximumTensionLoadField           = new TorqueType();
     this.maximumSpringCompressionLoadField = new TorqueType();
     this.maximumRotationalSpeedField       = new SpeedDimension();
     this.maximumAngularMisalignmentField   = new DegreeDimension();
     this.deflectionAngleField              = new DegreeDimension();
 }
Exemple #4
0
        static void Main(string[] args)
        {
            string outputDir;

            if (args.Length < 1)
            {
                FolderBrowserDialog fbd       = new FolderBrowserDialog();
                DialogResult        fbdResult = fbd.ShowDialog();
                if (fbdResult == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
                {
                    outputDir = fbd.SelectedPath;
                }
                else
                {
                    return;
                }
            }
            else
            {
                outputDir = args[0];
            }

            JObject result;

            using (StreamReader SR = new StreamReader("EngineMetaData.json"))
                using (JsonReader reader = new JsonTextReader(SR))
                    result = JObject.Load(reader);

            JArray functions = JArray.FromObject(result["functions"]);
            JArray classes   = JArray.FromObject(result["classes"]);

            // First we register all the classes into our type system
            TorqueType.RegisterClasses(classes);

            // Then we generate all the classes
            IEnumerable <KeyValuePair <string, Template> > classTemplates = new ClassGenerator().GenerateFor(classes);

            // Lastly we generate all the functions
            IEnumerable <KeyValuePair <string, Template> > functionTemplates = new FunctionGenerator().GenerateFor(functions);

            // Output everything to corresponding files
            foreach (KeyValuePair <string, Template> nameTemplatePair in classTemplates.Concat(functionTemplates))
            {
                string fileName = outputDir + $"/{nameTemplatePair.Key}.cs";
                Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                using (StreamWriter SW = new StreamWriter(fileName))
                {
                    SW.Write(nameTemplatePair.Value.Content);
                }
            }
        }
Exemple #5
0
        private Template FieldToProperty(JToken field)
        {
            Template template = new PropertyDeclarationTemplate();

            try
            {
                TorqueType propType = new TorqueType(field["Type"].ToString());

                string fieldName = field["Name"].ToString().First().ToString().ToUpper() +
                                   field["Name"].ToString().Substring(1);
                int    elementCount       = field["ElementCount"].ToObject <int>();
                string fieldArrayIndexArg = elementCount > 1 ? $", {elementCount}" : "";

                string value = $"getFieldValue(\"{fieldName}\"{fieldArrayIndexArg})";

                string returnString = propType.FromString(value);

                if (elementCount > 1)
                {
                    template = new DynamicFieldVectorPropertyDeclarationTemplate();
                }
                else
                {
                    template = new PropertyDeclarationTemplate();
                }
                template.ReplaceField("FieldType", propType.ManagedType);
                template.ReplaceField("Return", returnString);
                template.ReplaceField("FieldName", fieldName);
                template.ReplaceField("FieldCount", elementCount.ToString());
                template.ReplaceField("Getter", propType.FromString("val"));
                template.ReplaceField("Setter", propType.ToString("obj"));
                template.ReplaceField("Set", propType.ToString("value"));
                template.ReplaceField("FieldArrayIndexArg", elementCount > 1 ? $", {elementCount}" : "");
            }
            catch (FieldDeprecatedException)
            {
                return(new EmptyTemplate());
            }
            return(template);
        }