def __new__(cls, *args, **kwargs): if isinstance(new_class, str): from mudsling.utils.modules import class_from_path new_cls = class_from_path(new_class) else: new_cls = new_class return new_cls.__new__(new_cls, *args, **kwargs)
def __init__(self, data): """ Pattern data format: { "id": "unique_id", "name": "Instance Name", "class": "module.path.to.Class", "attributes": { "foo": <value>, ..., "attrN": <value> } ... arbitrary metadata key/vals ... } @param data: dict of pattern data. @type data: dict """ self.validate_data(data) self.data = data self.id = data['id'] self.name = data['name'] self.attributes = data['attributes'] if 'attributes' in data else {} if isinstance(data['class'], basestring): self.cls = class_from_path(data['class']) else: # Must be a child of type. self.cls = data['class']
def _isa(accessed_obj, accessing_obj, cls_name): cls = registry.classes.get_class(cls_name) if cls is None: # noinspection PyBroadException try: cls = mod_utils.class_from_path(cls_name) except: cls = None if not issubclass(cls, BaseObject): cls = None if cls is not None: return accessing_obj.isa(cls) return False
def run(self, this, actor, args): cls = registry.classes.get_class(args['class']) if cls is None: # noinspection PyBroadException try: cls = mod_utils.class_from_path(args['class']) except: cls = None if cls is None or not issubclass(cls, BaseObject): actor.msg("Unknown class: %s" % args['class']) return clsName = registry.classes.get_class_name(cls) if not actor.superuser and not (issubclass(cls, LockableObject) and cls.createLock.eval(cls, actor)): msg = "{yYou do not have permission to create {c%s{y objects." actor.msg(msg % clsName) return if 'names' in args and args['names']: try: names = misc.parse_names(args['names']) except Exception as e: actor.msg('{r' + e.message) return else: names = None obj = cls.create(names=names, owner=actor) actor.msg("{gCreated new %s: {c%s" % (clsName, obj.nn)) if obj.isa(LocatedObject): if actor.isa(BasePlayer): if (actor.possessing is not None and actor.possessing.isa(LocatedObject)): where = actor.possessing else: where = None elif actor.isa(LocatedObject): where = actor else: where = None if where is not None: obj.move_to(where) actor.msg("{c%s {yplaced in: {m%s" % (obj.nn, where.nn)) else: actor.msg("{c%s {yis {rnowhere{y.")
def import_area_object(data, sandbox, top=None): """ Import an area data structure. Main entry point. :param data: The area data to import. :type data: dict :param sandbox: The workspace for the import process. :type sandbox: dict :param top: Optionally specify the object to use instead of creating one. :type top: AreaExportable """ if 'id' in data: external_id = data['id'] if 'objmap' not in sandbox: sandbox['objmap'] = {} objmap = sandbox['objmap'] if external_id in objmap: return objmap[external_id] if top is None: try: cls = mod_utils.class_from_path(data['class']) except errors.Error as e: raise AreaImportFailed(e.message) except KeyError: raise AreaImportFailed('Invalid area file: missing class') # noinspection PyUnresolvedReferences obj = cls.create() else: obj = top sandbox['top'] = obj obj.area_import(data, sandbox) obj = obj.ref() if isinstance(obj, AreaExportableBaseObject) else obj if 'id' in data: sandbox['objmap'][data['id']] = obj return obj