コード例 #1
0
 def load_defaults(self): 
     for default in self.default_attributes:
         if default in self.store().values():
             continue
         attr = EntityRegister.get_attribute(self.ctype, default)
         if attr.has_defaults():
             self.add_attribute(attr(self))
コード例 #2
0
def _create_component(name, component_type, command):

    component_class = EntityRegister.get_component(component_type)
    component = component_class(name, command)

    component.load_defaults()

    for attr_name in component.store().values().keys():        
        if attr_name in non_attributes:
            continue
        attr = EntityRegister.get_attribute(component_type, attr_name)
        if not attr:
            raise NotFound("Invalid attribute `{}` for component "
                           "{}. Maybe Missspelled?"
                           .format(attr_name, component.entity()))
        component.add_attribute(attr(component))

    # check if component is correctly initialized
    component.validate()
    return component