Exemple #1
0
    def importer(root, path, model):
        res = desper.get_resource_importer(
            location=DEFAULT_STATIC_MEDIA_LOCATION,
            accepted_exts=DEFAULT_MEDIA_EXTS)(root, path, model)

        if res is None:
            return res
        return (*res, False)
Exemple #2
0
def get_image_importer():
    """Get an importer function for `pyglet.image.AbstractImage`.

    Given the resource subfolder and accepted extensions, return a
    function in the form of :py:attr:`GameModel.LAMBDA_SIG` that will
    only accept files in the given resource subfolder(`location`) and
    returns the path to the given image if it's considered accepted
    (designed to be used with :class:`ImageHandle`).

    :return: A function usable as key in an `importer_dict`.
    """
    return desper.get_resource_importer(location=DEFAULT_SPRITES_LOCATION,
                                        accepted_exts=DEFAULT_IMAGE_EXTS)
Exemple #3
0
def get_world_importer():
    """Get an importer function for worlds(:class:`WorldHandle`).

    :return: A function usable as key in an `importer_dict`.
    """
    lambd = desper.get_resource_importer(DEFAULT_WORLDS_LOCATION,
                                         DEFAULT_WORLDS_EXTS)

    def decorated_lambda(root, rel_path, model):
        ret = lambd(root, rel_path, model)
        if ret is None:
            return None

        ret = list(ret)
        ret.append(model)

        return ret

    return decorated_lambda
Exemple #4
0
def get_media_importer():
    """Get an importer function for `pyglet.media.Source` resources.

    Given the resource subfolder and accepted extensions, return a
    function in the form of :py:attr:`GameModel.LAMBDA_SIG` that will
    only accept files in the given resource subfolder(`location`) and
    returns the path to the given media resource if it's considered
    accepted.
    (Designed to be used with :class:`MediaHandle`).

    Currently there is not metadata file, the resource is imported as it
    is (by default streamed from the disk, a custom importer function/handle
    might be necessary if pre-decoded resources are needed).

    :param location: The resource subfolder for the game where media
                     should be stored(other directories won't be
                     accepted).
    :param accepted_exts: An iterable of extensions recognized as valid
                          media metadata.
    """
    return desper.get_resource_importer(location=DEFAULT_MEDIA_LOCATION,
                                        accepted_exts=DEFAULT_MEDIA_EXTS)
Exemple #5
0
def get_animation_importer():
    """Get an importer function for `pyglet.image.animation.Animation`.

    Given the resource subfolder and accepted extensions, return a
    function in the form of :py:attr:`GameModel.LAMBDA_SIG` that will
    only accept files in the given resource subfolder(`location`) and
    returns the path to the given image if it's considered accepted
    (designed to be used with :class:`AnimationHandle`).

    For more information about the metadata file format see
    :class:`AnimationHandle`.

    :param location: The resource subfolder for the game where sprites
                     should be stored(other directories won't be
                     accepted).
    :param accepted_exts: An iterable of extensions recognized as valid
                          animation metadata.
    :param accepted_sheet_exts: An iterable of extensions recognized as
                                valid animation files(sprite sheets).
    :return: A function usable as key in an `importer_dict`.
    """
    return desper.get_resource_importer(location=DEFAULT_SPRITES_LOCATION,
                                        accepted_exts=DEFAULT_ANIMATION_EXTS)