Skip to content
James Lott edited this page Mar 10, 2018 · 3 revisions

Synopsis

from mkproject.loader import BaseLoader
from mkproject.loader import LoaderError

class MyLoader(BaseLoader):
  def load(self, pack):
    try:
      for path, data, meta in self._fetch_external(self.location):
        pack.register_path(path, data, **meta)
    except EnvironmentError as e:
      raise LoaderError(e)
  def _fetch_external(self, location):
    # Some logic to fetch asset data from an external source
    return (
      ('/dev/null', '', {}),
    )

BaseLoader.location

This property is the value which the loader can use to locate the external resource to load assets from. It is populated by __init__().

Baseloader.load

Spec

instance.load(pack)

Description

This method must be implemented by each loader class. Its job is to fetch assets from an external location and populate the AssetPack passed in the pack parameter with the fetched assets. This population should be performed using the AssetPack.register_path method. If the loader fails to fetch any asset for any reason, it is expected to raise a LoaderError.

Clone this wiki locally