コード例 #1
0
ファイル: track.py プロジェクト: yoyonel/beatsaber
    def _load(self):
        data = resources.data.load(DataDescription(self.filename, kind='json'))

        for event in data['_events']:
            try:
                event_type = EventType(event['_type'])
            except ValueError:
                raise ValueError("Event type {} not supported".format(event['_type']))

            channel = self.channels.get(event_type.value)
            if not channel:
                # print("Event {} not supported".format(event_type.value))
                continue

            # Transform events if needed for easy access
            value = event['_value']
            # If value is greater or equal to 255 we are dealing with a color value
            # FIXME: We discard these events for now
            if value >= 255 and event_type.value < 5:
                continue

            channel.add_event(BSEvent(
                event_type,
                int(event['_time'] * 1000 / (self.bpm / 60)),
                value,
            ))
コード例 #2
0
ファイル: text_2d.py プロジェクト: sthagen/moderngl-window
    def __init__(self):
        super().__init__()

        meta = FontMeta(
            resources.data.load(
                DataDescription(path="bitmapped/text/meta.json")))
        self._texture = resources.textures.load(
            TextureDescription(
                path="bitmapped/textures/VeraMono.png",
                kind="array",
                mipmap=True,
                layers=meta.characters,
            ))
        self._program = resources.programs.load(
            ProgramDescription(path="bitmapped/programs/text_2d.glsl"))

        self._init(meta)

        self._string_buffer = self.ctx.buffer(reserve=1024 * 4)
        self._string_buffer.clear(chunk=b'\32')
        pos = self.ctx.buffer(data=bytes([0] * 4 * 3))

        self._vao = VAO("textwriter", mode=moderngl.POINTS)
        self._vao.buffer(pos, '3f', 'in_position')
        self._vao.buffer(self._string_buffer, '1u/i', 'in_char_id')

        self._text: str = None
コード例 #3
0
 def test_binary_abspath(self):
     """Strip search directories and use absolute path"""
     path = (Path(__file__).parent /
             "fixtures/resources/data/data.json").resolve()
     with resources.temporary_dirs([]):
         json = resources.data.load(DataDescription(path=path, kind="json"))
         self.assertEqual(json, {"test": "Hello"})
コード例 #4
0
 def test_data(self):
     """Create a DataDescription"""
     instance = DataDescription(
         path=self.path,
         kind=self.kind,
         label=self.label,
     )
     self.inspect_base_properties(instance)
コード例 #5
0
def find_path(path, throw=True):

    assert _regd, "No resource path has been registered yet. Did you remember to create an App() instance?"

    dd = DataDescription(path=path, kind='binary')
    mglw.resources.data.resolve_loader(dd)
    pp = dd.loader_cls(dd).find_data(dd.path)

    if pp is None and throw:
        raise IOError("Path %r not found." % path)

    if pp is not None:
        p0 = pathlib.Path(path)
        p1 = str(pp)[:-len(str(p0))]
        _dirs.add(p1)

    return pp
コード例 #6
0
    def load_binary(self, path: str, **kwargs) -> bytes:
        """Load a file in binary mode.

        Args:
            path (str): Path to the file relative to search directories
            **kwargs: Additional parameters to DataDescription
        Returns:
            bytes: The byte data of the file
        """
        if not kwargs:
            kwargs = {}

        if 'kind' not in kwargs:
            kwargs['kind'] = 'binary'

        return resources.data.load(DataDescription(path=path, kind="binary"))
コード例 #7
0
    def load_json(self, path: str, **kwargs) -> dict:
        """Load a json file

        Args:
            path (str): Path to the file relative to search directories
            **kwargs: Additional parameters to DataDescription
        Returns:
            dict: Contents of the json file
        """
        if not kwargs:
            kwargs = {}

        if 'kind' not in kwargs:
            kwargs['kind'] = 'json'

        return resources.data.load(DataDescription(path=path, **kwargs))
コード例 #8
0
    def load_text(self, path: str, **kwargs) -> str:
        """Load a text file.

        Args:
            path (str): Path to the file relative to search directories
            **kwargs: Additional parameters to DataDescription
        Returns:
            str: Contents of the text file
        """
        if not kwargs:
            kwargs = {}

        if "kind" not in kwargs:
            kwargs["kind"] = "text"

        return resources.data.load(DataDescription(path=path, **kwargs))
コード例 #9
0
ファイル: window.py プロジェクト: sthagen/moderngl-window
    def load_binary(self, path: str, **kwargs) -> bytes:
        """Load a file in binary mode.

        If the path is relative the resource system is used expecting one or more
        resource directories to be registered first. Absolute paths will attempt
        to load the file directly.

        Args:
            path (str): Path to the file relative to search directories
            **kwargs: Additional parameters to DataDescription
        Returns:
            bytes: The byte data of the file
        """
        if not kwargs:
            kwargs = {}

        if "kind" not in kwargs:
            kwargs["kind"] = "binary"

        return resources.data.load(DataDescription(path=path, kind="binary"))
コード例 #10
0
ファイル: window.py プロジェクト: sthagen/moderngl-window
    def load_json(self, path: str, **kwargs) -> dict:
        """Load a json file

        If the path is relative the resource system is used expecting one or more
        resource directories to be registered first. Absolute paths will attempt
        to load the file directly.

        Args:
            path (str): Path to the file relative to search directories
            **kwargs: Additional parameters to DataDescription
        Returns:
            dict: Contents of the json file
        """
        if not kwargs:
            kwargs = {}

        if "kind" not in kwargs:
            kwargs["kind"] = "json"

        return resources.data.load(DataDescription(path=path, **kwargs))
コード例 #11
0
def load_image(
    o,
    autocrop=False,
    flip=False,
):

    if type(o) is str:
        d0 = mglw.resources.data.load(DataDescription(path=o, kind='binary'))
        im = PIL.Image.open(io.BytesIO(d0))
        im.load()

    if isinstance(o, np.ndarray):
        im = PIL.Image.fromarray(o.astype('uint8'))

    if isinstance(o, PIL.Image.Image):
        im = o

    if autocrop:
        im = pil_autocrop(im)

    if flip:
        im = im.transpose(PIL.Image.FLIP_TOP_BOTTOM)

    return im
コード例 #12
0
def load_font(path, size):

    ff = mglw.resources.data.load(DataDescription(path=path, kind='binary'))
    return PIL.ImageFont.truetype(io.BytesIO(ff), size)
コード例 #13
0
 def load_source(path):
     return path, resources.data.load(DataDescription(path,
                                                      kind='text'))
コード例 #14
0
 def test_txt(self):
     """Ensure correct loader is selected by looking at file extension (txt)"""
     text = resources.data.load(DataDescription(path='data/data.txt'))
     self.assertEqual(text, "Hello")
コード例 #15
0
 def test_binary_not_found(self):
     """Ensure ImproperlyConfigured is raised if file is not found"""
     with self.assertRaises(ImproperlyConfigured):
         resources.data.load(DataDescription(path='data/notfound.bin', kind="binary"))
コード例 #16
0
 def test_json_kind(self):
     """Load a json file"""
     json = resources.data.load(DataDescription(path='data/data.json', kind="json"))
     self.assertEqual(json, {"test": "Hello"})
コード例 #17
0
 def test_text_kind(self):
     """Load a e textfile"""
     text = resources.data.load(DataDescription(path='data/data.txt', kind="text"))
     self.assertEqual(text, "Hello")
コード例 #18
0
 def test_binary_kind(self):
     """Loading a binary file"""
     data = resources.data.load(DataDescription(path='data/data.bin', kind="binary"))
     self.assertEqual(data, b'Hello')
コード例 #19
0
 def test_json(self):
     """Ensure correct loader is selected by looking at file extension (json)"""
     json = resources.data.load(DataDescription(path='data/data.json'))
     self.assertEqual(json, {"test": "Hello"})