def __init__(self): Component.__init__(self, depth=float, color=color.RGBA) self.fields['color'].default = lambda: color.RGBA(1,1,1,1)
__version__ = '$Id$' import operator from grease.geometry import Vec2d, Vec2dArray, Rect from grease import color # Allowed field types -> default values types = { int: lambda: 0, float: lambda: 0.0, bool: lambda: False, str: lambda: "", object: lambda: None, Vec2d: lambda: Vec2d(0, 0), Vec2dArray: lambda: Vec2dArray(), color.RGBA: lambda: color.RGBA(0.0, 0.0, 0.0, 0.0), Rect: lambda: Rect(0.0, 0.0, 0.0, 0.0) } class Schema(dict): """Field schema definition for custom components""" def __init__(self, **fields): for ftype in fields.values(): assert ftype in types, fname + " has an illegal field type" self.update(fields) class FieldAccessor(object): """Facade for manipulating a field for a set of entities"""