Module namedatlases

Overview

A NamedAtlas, like an Atlas and Texture, represents raw image data in GPU memory. Like an Atlas, it too provides an even partitioning of the underlying Texture. The NamedAtlas, however, also provides a string-based name for each indexed sub-region allowing for a more semantic interface.

Types

NamedAtlasInfo = object
  name*: string                ## name of the Atlas in an AtlasManager
  description*: string         ## description of the NamedAtlas
  authors*: seq[string]        ## authors of the NamedAtlas
  filename*: string            ## filename used to load the NamedAtlas
  width*: int                  ## the width of the NamedAtlas partitions
  height*: int                 ## the height of the NamedAtlas partitions
  names*: seq[string]          ## names of the NamedAtlas partitions
  
Meta-data describing a NamedAtlas
NamedAtlas = ref object
  info*: NamedAtlasInfo        ## meta-data describing the NamedAtlas
  atlas*: Atlas                ## Atlas underlying the NamedAtlas
  
Used for rendering sub-regions of a Texture by name
NamedAtlasManager = ref object
  atlases: AtlasManager        ## Atlases backing managed NamedAtlases
  registry: Table[string, NamedAtlas] ## loaded NamedAtlases by name
  
Used for loading and managing NamedAtlases

Procs

proc newNamedAtlasManager(window: WindowPtr; display: RendererPtr): NamedAtlasManager {.
    raises: [], tags: [].}
proc load(tmm: NamedAtlasManager; name, filename: string; width, height: int;
         names: seq[string]; description: string = nil; authors: seq[string] = nil): NamedAtlas {.
    raises: [KeyError, NoSuchResourceError, ValueError, InvalidResourceError],
    tags: [ReadDirEffect].}
Load an image resource from disk, partitioned into sub-regions of t_width and t_height. Once loaded sub-regions my be rendered by index or by name. Names are assigned to sub-regions by the order in which they appear in the names sequence.
proc loadPack(tsm: NamedAtlasManager; filename: string) {.raises: [ValueError, IOError,
    Exception, JsonParsingError, IndexError, KeyError, NoSuchResourceError,
    InvalidResourceError], tags: [ReadIOEffect, RootEffect, ReadDirEffect].}

Load a resource-pack of NamedAtlases. NamedAtlases inside of a NamedAtlas resource-pack should be unmarshalable by the NamedAtlasAsset type.

Example NamedAtlasInfo JSON

"example_atlas_asset": {
  "filename": "atlases/example_atlas.png",
  "width": 32, "height": 32,
  "names": ["dirt", "grass", "stone", "water", "ice"]
}
proc get(tmm: NamedAtlasManager; name: string): NamedAtlas {.
    raises: [NoSuchResourceError, KeyError], tags: [].}
Get a loaded NamedAtlas by name
proc getNameIndex(atlas: NamedAtlas; name: string): int {.raises: [], tags: [].}
proc render(display: RendererPtr; atlas: NamedAtlas; name: string; dx, dy: int) {.
    raises: [DivByZeroError], tags: [].}
Render a region from the NamedAtlas to dx, dy