private KeyValuePair <string, Template> OutputClass(JToken classObject) { MethodInternalsRegionTemplate classInternals = GenerateClassInternals(classObject); MethodDeclarationRegionTemplate classDecls = GenerateClassDeclarations(classObject); PropertiesDeclarationRegionTemplate classProps = GenerateClassProperties(classObject); Template classTemplate = new SimClassTemplate(); if (classObject["ClassName"].ToString() == "SimObject") { classTemplate = new SimObjectClassTemplate(); } else if (classObject["ClassName"].ToString() == "SimDataBlock") { classTemplate = new SimDatablockClassTemplate(); } else if (classObject["IsDatablock"].ToObject <bool>()) { classTemplate = new SimDatablockObjectClassTemplate(); } string parentString = ""; if (!string.IsNullOrEmpty(classObject["ParentClassName"].ToString())) { parentString = ": " + classObject["ParentClassName"]; } classTemplate.ReplaceField("ClassName", classObject["ClassName"].ToString()); classTemplate.ReplaceField("ParentString", parentString); classTemplate.ReplaceField("Internals", classInternals.Indent(2).Content); classTemplate.ReplaceField("Declarations", classDecls.Indent(2).Content); classTemplate.ReplaceField("Properties", classProps.Indent(2).Content); return(new KeyValuePair <string, Template>(classObject["ClassName"].ToString(), classTemplate)); }
private MethodDeclarationRegionTemplate GenerateClassDeclarations(JToken classObject) { IEnumerable <string> classDeclarations = classObject["Methods"].Select( method => new MethodDeclarationTemplate(new TorqueFunction((JObject)method)).Indent().Content); string classDecls = classDeclarations.Aggregate("", (x, y) => x + "\n" + y); if (classObject["ClassName"].ToString() == "SimObject") { // registerObject is a special method, which is not exposed to TorqueScript, so we have to add it manually here JObject registerObjectFunction = new JObject { ["Type"] = "bool", ["Name"] = "registerObject", ["Comment"] = "/**/", ["Parameters"] = new JArray(), ["IsStringlyTyped"] = false }; classDecls += "\n" + new MethodDeclarationTemplate(new TorqueFunction(registerObjectFunction)).Indent().Content; JObject copyFromFunction = new JObject { ["Type"] = "void", ["Name"] = "CopyFrom", ["Comment"] = "/**/", ["Parameters"] = new JArray(new JObject { ["Type"] = "SimObject", ["Name"] = "parent", ["DefaultValue"] = null, ["VarArgs"] = false }), ["IsStringlyTyped"] = false }; classDecls += "\n" + new MethodDeclarationTemplate(new TorqueFunction(copyFromFunction)).Indent().Content; JObject setModsFunction = new JObject { ["Type"] = "void", ["Name"] = "SetMods", ["Comment"] = "/**/", ["Parameters"] = new JArray(new JObject { ["Type"] = "bool", ["Name"] = "modStaticFields", ["DefaultValue"] = null, ["VarArgs"] = false }, new JObject { ["Type"] = "bool", ["Name"] = "modDynamicFields", ["DefaultValue"] = null, ["VarArgs"] = false }), ["IsStringlyTyped"] = false }; classDecls += "\n" + new MethodDeclarationTemplate(new TorqueFunction(setModsFunction)).Indent().Content; } if (classObject["ClassName"].ToString() == "SimDataBlock") { // registerObject is a special method, which is not exposed to TorqueScript, so we have to add it manually here JObject assignIdFunction = new JObject { ["Type"] = "void", ["Name"] = "AssignId", ["Comment"] = "/**/", ["Parameters"] = new JArray(), ["IsStringlyTyped"] = false }; classDecls += "\n" + new MethodDeclarationTemplate(new TorqueFunction(assignIdFunction)).Indent().Content; JObject preloadFunction = new JObject { ["Type"] = "void", ["Name"] = "Preload", ["Comment"] = "/**/", ["Parameters"] = new JArray(), ["IsStringlyTyped"] = false }; classDecls += "\n" + new MethodDeclarationTemplate(new TorqueFunction(preloadFunction)).Indent().Content; } MethodDeclarationRegionTemplate regionTemplate = new MethodDeclarationRegionTemplate(); regionTemplate.ReplaceField("classDecls", classDecls); return(regionTemplate); }