Beispiel #1
0
def load_prefab(target, file):
    if isinstance(file, str):
        with open(parse_path(file)) as fl:
            return load_prefab(target, fl)
    data = json.load(file)

    def load(current_target, instances):
        for instance_data in instances:
            module_name, class_name = instance_data["class"].rsplit(".", 1)
            arguments = instance_data.get("arguments", {})
            attributes = instance_data.get("attributes", {})
            children = instance_data.get("children", [])
            meta = instance_data.get("meta", [])

            module = import_module(module_name)
            cls = getattr(module, class_name)

            parsed_arguments = {
                name: parse_argument(cls, arg, name, file)
                for name, arg in arguments.items()
            }

            if meta:
                parent = [current_target] + meta
            else:
                parent = current_target

            instance = cls(parent, **parsed_arguments)

            for name, value in attributes.items():
                setattr(instance, name, parse_argument(cls, value, name, file))

            load(instance, children)

    load(target, data)
Beispiel #2
0
def load_prefab(target, file):
    if isinstance(file, str):
        with open(parse_path(file)) as fl:
            return load_prefab(target, fl)
    data = json.load(file)

    def load(current_target, instances):
        for instance_data in instances:
            module_name, class_name = instance_data["class"].rsplit(".", 1)
            arguments = instance_data.get("arguments", {})
            attributes = instance_data.get("attributes", {})
            children = instance_data.get("children", [])
            meta = instance_data.get("meta", [])

            module = import_module(module_name)
            cls = getattr(module, class_name)

            parsed_arguments = {
                name: parse_argument(cls, arg, name, file)
                for name, arg in arguments.items()
            }

            if meta:
                parent = [current_target] + meta
            else:
                parent = current_target

            instance = cls(parent, **parsed_arguments)

            for name, value in attributes.items():
                setattr(instance, name, parse_argument(cls, value, name, file))

            load(instance, children)

    load(target, data)
Beispiel #3
0
 def on_create(self, path):
     self.image = engine.Image(parse_path(path))
     w = self.image.width / 2
     h = self.image.height / 2
     VertexList(
         self,
         points=quad(0, 0, w, h),
         uvs=quad(0.5, 0.5, 0.5, 0.5),
         texture=self.image
     )
Beispiel #4
0
 def on_create(self, path, border_size):
     self.image = engine.Image(parse_path(path))
     self._width = self.image.width
     self._height = self.image.height
     self._border_size = border_size
     w = self.width / 2
     h = self.height / 2
     b = self._border_size / 2
     self.vertex_list = VertexList(
         self,
         points=self._get_pts(0, 0, w, h, b, b),
         uvs=self._get_pts(0.5, 0.5, 0.5, 0.5, b / w, b / h),
         texture=self.image
     )
Beispiel #5
0
 def on_create(self, path, border_size):
     self.image = engine.Image(parse_path(path))
     self._width = self.image.width
     self._height = self.image.height
     self._border_size = border_size
     w = self.width / 2
     h = self.height / 2
     b = self._border_size / 2
     self.vertex_list = VertexList(
         self,
         points=self._get_pts(0, 0, w, h, b, b),
         uvs=self._get_pts(0.5, 0.5, 0.5, 0.5, b / w, b / h),
         texture=self.image,
     )
Beispiel #6
0
 def on_create(self, path):
     self.image = engine.Image(parse_path(path))
     w = self.image.width / 2
     h = self.image.height / 2
     VertexList(self, points=quad(0, 0, w, h), uvs=quad(0.5, 0.5, 0.5, 0.5), texture=self.image)