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 MethodInternalsRegionTemplate GenerateClassInternals(JToken classObject) { MethodInternalsRegionTemplate template = new MethodInternalsRegionTemplate(); string classInternals = classObject["Methods"].Aggregate("", (x, method) => x + "\n" + MethodToInternal(classObject["ClassName"].ToString(), new TorqueFunction((JObject)method)) .Indent() .Content); // We append the create function to the rest of the internals, so we can use it in the constructor JObject token = new JObject { ["Type"] = classObject["ClassName"] + "*", ["Name"] = $"{classObject["ClassName"]}_create", ["Comment"] = "/**/", ["Parameters"] = new JArray(), ["IsStringlyTyped"] = false }; classInternals += "\n" + FunctionGenerator.FunctionToInternal(new TorqueFunction(token)).Indent().Content; 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 }; classInternals += MethodToInternal(classObject["ClassName"].ToString(), 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 }; classInternals += MethodToInternal(classObject["ClassName"].ToString(), 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 }; classInternals += MethodToInternal(classObject["ClassName"].ToString(), 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 }; classInternals += MethodToInternal(classObject["ClassName"].ToString(), new TorqueFunction(assignIdFunction)) .Indent() .Content; JObject preloadFunction = new JObject { ["Type"] = "void", ["Name"] = "Preload", ["Comment"] = "/**/", ["Parameters"] = new JArray(), ["IsStringlyTyped"] = false }; classInternals += MethodToInternal(classObject["ClassName"].ToString(), new TorqueFunction(preloadFunction)) .Indent() .Content; } template.ReplaceField("classInternals", classInternals); return(template); }