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

[[TOC]]

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)
        self.log('loaded: %s' % path)
    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.log

This attribute is a function allowing the loader to output informational messages. The base implementation does not output messages messages anywhere, and this method should be overridden by the instantiator.

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