diff --git a/texture.js b/texture.js
index 70bed2d..21083e8 100644
--- a/texture.js
+++ b/texture.js
@@ -1,9 +1,13 @@
+// Regexps for parsing contents of deutex-format texture definition files.
EMPTY_RE = /^\s*$/;
COMMENT_RE = /^\s*;/;
TEXTURE_RE = /^\s*([A-Za-z0-9_-]+)\s*(-?[0-9]+)\s*(-?[0-9]+)/;
PATCH_RE = /^\s*\*\s*([A-Za-z0-9_-]+)\s*(-?[0-9]+)\s*(-?[0-9]+)/;
+// PatchesStore implements a class that will load patches on demand from a
+// specified URL, creating them as tags in a hidden
so that they
+// can be composited into a full texture.
class PatchesStore {
constructor(rootPath, extension) {
this.patches = {};
@@ -17,6 +21,8 @@ class PatchesStore {
document.body.appendChild(this.container);
}
+ // loadPatch loads the given patch by name, creating an
tag
+ // for it if necessary.
loadPatch(name) {
name = name.toLowerCase();
if (name in this.patches) {
@@ -35,6 +41,8 @@ class PatchesStore {
this.patches[name] = img;
}
+ // getPatch returns an
tag for the given patch. The patch must
+ // have already have been loaded using loadPatch().
getPatch(name) {
name = name.toLowerCase();
if (name in this.patches) {
@@ -50,6 +58,9 @@ class PatchesStore {
}
}
+ // loadAllPatches invokes loadPatch() for every patch referenced
+ // in the given list of Texture objects, invoking the specified
+ // callback when they have all been loaded.
loadAllPatches(textures, callback) {
var ps = this;
ps.onload = function() {
@@ -66,6 +77,7 @@ class PatchesStore {
}
}
+// Patch represents a single patch inside a texture entry.
class Patch {
constructor(name, x, y) {
this.name = name;
@@ -78,6 +90,7 @@ class Patch {
}
}
+// Texture represents a texture inside the TEXTUREx lump.
class Texture {
constructor(name, width, height) {
this.name = name;
@@ -95,6 +108,9 @@ class Texture {
return hdr + "\n" + this.patches.join("\n");
}
+ // drawTexture renders the texture into a full