def __init__(self, propertyName, prop): self.propertyName = propertyName self.variables = list() self.isFlag = False self.isStruct = False self.isResource = False if isinstance(prop, dict): if not "_type_" in prop: for varName, var in prop.items(): self.variables.append(GetVariableFromEntry(varName, var)) self.isStruct = True else: var = GetVariableFromEntry(propertyName, prop) if var.type is None: self.isFlag = True self.variables.append(var) else: var = GetVariableFromEntry(propertyName, prop) if var.type is None: self.isFlag = True self.variables.append(GetVariableFromEntry(propertyName, prop)) # Check to see if any of the types within the struct are resource. for var in self.variables: if var.type == IDLTypes.GetTypeString("resource"): if self.isStruct: util.fmtError( "Structs containing resources not supported!") self.isResource = True
def GetVariableFromEntry(name, var): if isinstance(var, dict): if not "_type_" in var: util.fmtError('{} : {}'.format(name, var.__repr__())) default = None if var["_type_"] == "_flag_": return VariableDefinition(None, name, None) if "_default_" in var: default = IDLTypes.GetTypeString( var["_type_"]) + "(" + IDLTypes.DefaultToString( var["_default_"]) + ")" else: default = IDLTypes.DefaultValue(var["_type_"]) return VariableDefinition(IDLTypes.GetTypeString(var["_type_"]), name, default) else: return VariableDefinition(IDLTypes.GetTypeString(var), name, IDLTypes.DefaultValue(var))
def WriteAttributeHeaderDeclarations(f, document): for attributeName, attribute in document["attributes"].items(): typeString = IDLTypes.GetTypeString(attribute["type"]) if not "fourcc" in attribute: util.fmtError( 'Attribute FourCC is required. Attribute "{}" does not have a fourcc!' .format(attributeName)) fourcc = attribute["fourcc"] accessMode = "rw" if "access" in attribute: accessMode = IDLTypes.AccessModeToClassString(attribute["access"]) defVal = IDLTypes.DefaultValue(attribute["type"]) if "default" in attribute: default = IDLTypes.DefaultToString(attribute["default"]) defVal = "{}({})".format(IDLTypes.GetTypeString(attribute["type"]), default) f.WriteLine('__DeclareAttribute({}, {}, \'{}\', {}, {});'.format( Capitalize(attributeName), typeString, fourcc, accessMode, defVal))
def WriteAttributeAccessDeclarations(self): if self.hasAttributes: self.f.WriteLine("/// Attribute access methods") for attributeName in self.component["attributes"]: if not attributeName in self.document["attributes"]: util.fmtError(AttributeNotFoundError.format(attributeName)) returnType = IDLTypes.GetTypeString( self.document["attributes"][attributeName]["type"]) attributeName = Capitalize(attributeName) self.f.WriteLine( "{retval}& {attributeName}(Game::InstanceId instance);". format(retval=returnType, attributeName=attributeName))
def WriteAttributeAccessImplementation(self): if self.hasAttributes: for i, attributeName in enumerate(self.component["attributes"]): if not attributeName in self.document["attributes"]: util.fmtError(AttributeNotFoundError.format(attributeName)) returnType = IDLTypes.GetTypeString( self.document["attributes"][attributeName]["type"]) attributeName = Capitalize(attributeName) self.f.InsertNebulaDivider() self.f.WriteLine( "{retval}& {className}::{attributeName}(Game::InstanceId instance)" .format(retval=returnType, className=self.className, attributeName=attributeName)) self.f.WriteLine("{") self.f.IncreaseIndent() self.f.WriteLine( "return this->data.Get<{}>(instance);".format(i + 1)) self.f.DecreaseIndent() self.f.WriteLine("}")
def ContainsEntityTypes(): for prop in properties: for var in prop.variables: if var.type == IDLTypes.GetTypeString("entity"): return True return False