Module packs

Overview

To make it easier to load many assets at once, this module exports a proc loadPack which can take the filename of a so-called Packfile, JSON formatted files that look like this:

{
  "includes": [
    "other_pack.json",
    "subdir/second_pack.json"
  ],
  "assets": {
    "some_asset": {
      "name": "Some Asset",
      "description": "Some asset used for example",
      "filename": "assets/some_asset.ext",
    },
    "other_asset": {
      "name": "Some Other Asset",
      "description": "Some other asset",
      "filename": "assets/other_asset.ext",
    }
  }
}

"includes" optional

The "includes" field specifies an array of relative paths to other packfiles whose contents should be included in this one.

"assets" required

The "assets" field is specified as an object. Each field of the object names a different asset. Each asset is returned as is, that is as a JsonNode. Assets declared under the "assets" field will override assets in any included packfiles.

Once loaded with loadPack, a single ResourcePack value will be returned containing a single Table mapping resource names to raw JsonNode assets. In the above example the assets are simple strings but they could be an integer, an array or even nested objects. It is up to consumers of ResourcePacks to deal with the resulting JsonNodes.

Types

ResourcePack = Table[string, JsonNode]

Procs

proc loadPack(filename: string): ResourcePack {.
    raises: [ValueError, IOError, Exception, JsonParsingError],
    tags: [ReadIOEffect, RootEffect].}

Loads the resource-pack at the provided filename (and recursively, any included resource-packs) and returns a flat table mapping resource names to JsonNodes.

It is up to consumers of resource-packs to deal with the handling of various resources as they appear in the JSON.