def GenerateSource(self, srcPath, hdrPath): f = filewriter.FileWriter() f.Open(srcPath) f.WriteLine("// NIDL #version:{}#".format(self.version)) head, tail = ntpath.split(hdrPath) hdrInclude = tail or ntpath.basename(head) head, tail = ntpath.split(srcPath) srcFileName = tail or ntpath.basename(head) IDLDocument.WriteSourceHeader(f, srcFileName) IDLDocument.AddInclude(f, hdrInclude) hasMessages = "messages" in self.document if hasMessages: IDLDocument.AddInclude(f, "scripting/bindings.h") if "attributes" in self.document: IDLDocument.BeginNamespaceOverride(f, self.document, "Attr") IDLAttribute.WriteAttributeSourceDefinitions(f, self.document) IDLDocument.EndNamespaceOverride(f, self.document, "Attr") f.WriteLine("") # Add additional dependencies to document. if "dependencies" in self.document: for dependency in self.document["dependencies"]: fstream = open(dependency, 'r') depDocument = sjson.loads(fstream.read()) deps = depDocument["attributes"] # Add all attributes to this document self.document["attributes"].update(deps) fstream.close() hasComponents = "components" in self.document if hasComponents or hasMessages: IDLDocument.BeginNamespace(f, self.document) if hasMessages: IDLProtocol.WriteMessageImplementation(f, self.document) if hasComponents: namespace = IDLDocument.GetNamespace(self.document) for componentName, component in self.document[ "components"].items(): f.WriteLine("") componentWriter = IDLComponent.ComponentClassWriter( f, self.document, component, componentName, namespace) componentWriter.WriteClassImplementation() f.WriteLine("") IDLDocument.EndNamespace(f, self.document) f.Close()
def GenerateSource(self, srcPath, hdrPath): f = filewriter.FileWriter() f.Open(srcPath) f.WriteLine("// NIDL #version:{}#".format(self.version)) head, tail = ntpath.split(hdrPath) hdrInclude = tail or ntpath.basename(head) head, tail = ntpath.split(srcPath) srcFileName = tail or ntpath.basename(head) IDLDocument.WriteSourceHeader(f, srcFileName) IDLDocument.AddInclude(f, hdrInclude) IDLDocument.AddInclude(f, "core/sysfunc.h") IDLDocument.AddInclude(f, "util/stringatom.h") IDLDocument.AddInclude(f, "memdb/typeregistry.h") IDLDocument.AddInclude(f, "game/propertyserialization.h") IDLDocument.AddInclude(f, "game/propertyinspection.h") hasMessages = "messages" in self.document if hasMessages: IDLDocument.AddInclude(f, "scripting/python/conversion.h") # Add additional dependencies to document. if "dependencies" in self.document: for dependency in self.document["dependencies"]: fstream = open(dependency, 'r') depDocument = sjson.loads(fstream.read()) deps = depDocument["properties"] # Add all properties to this document self.document["properties"].update(deps) fstream.close() hasStructs = IDLProperty.HasStructProperties() hasEnums = "enums" in self.document if hasEnums or hasStructs: IDLDocument.AddInclude(f, "pjson/pjson.h") IDLDocument.BeginNamespaceOverride(f, self.document, "IO") if hasEnums: IDLProperty.WriteEnumJsonSerializers(f, self.document) if hasStructs: IDLProperty.WriteStructJsonSerializers(f, self.document) IDLDocument.EndNamespaceOverride(f, self.document, "IO") hasProperties = "properties" in self.document if hasProperties or hasMessages: IDLDocument.BeginNamespace(f, self.document) if hasMessages: IDLProtocol.WriteMessageImplementation(f, self.document) if "properties" in self.document: IDLDocument.BeginNamespaceOverride(f, self.document, "Details") IDLProperty.WritePropertySourceDefinitions(f, self.document) IDLDocument.EndNamespaceOverride(f, self.document, "Details") f.WriteLine("") IDLDocument.EndNamespace(f, self.document) f.Close()