@theatrejs/loader-aseprite 1.3.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -30,8 +30,8 @@
30
30
  "html",
31
31
  "html5",
32
32
  "javascript",
33
- "pixel-art",
34
33
  "loader",
34
+ "pixel-art",
35
35
  "theatrejs",
36
36
  "theatrejs-loader",
37
37
  "webgl",
@@ -57,5 +57,5 @@
57
57
  "postversion": "node ./tools/custom/postversion.cjs"
58
58
  },
59
59
  "type": "commonjs",
60
- "version": "1.3.0"
60
+ "version": "1.4.1"
61
61
  }
@@ -67,65 +67,71 @@ module.exports = function loader() {
67
67
 
68
68
  try {
69
69
 
70
- subprocess.execSync(
71
-
72
- 'cd "' + location + '"' +
73
-
74
- ' && "' + aseprite + '"' +
75
- ' --batch "' + file + '"' +
76
- trim +
77
- ' --sheet "' + sourceTexture + '"' +
78
- ' --sheet-type ' + sheetType +
79
- ' --split-tags' +
80
- ' --data "' + sourceData + '"' +
81
- ' --list-tags' +
82
- ' --format json-array' +
83
- ' --filename-format {tag}#{tagframe001}@{title}.{extension}'
84
- );
70
+ if (fs.existsSync(path.resolve(location, sourceTexture)) === false
71
+ || fs.existsSync(path.resolve(location, sourceData)) === false
72
+ || fs.statSync(path.resolve(location, sourceTexture)).mtime < fs.statSync(file).mtime
73
+ || fs.statSync(path.resolve(location, sourceData)).mtime < fs.statSync(file).mtime) {
74
+
75
+ subprocess.execSync(
76
+
77
+ 'cd "' + location + '"' +
78
+
79
+ ' && "' + aseprite + '"' +
80
+ ' --batch "' + file + '"' +
81
+ trim +
82
+ ' --sheet "' + sourceTexture + '"' +
83
+ ' --sheet-type ' + sheetType +
84
+ ' --split-tags' +
85
+ ' --data "' + sourceData + '"' +
86
+ ' --list-tags' +
87
+ ' --format json-array' +
88
+ ' --filename-format {tag}#{tagframe001}@{title}.{extension}'
89
+ );
85
90
 
86
- if (typeof processing !== 'undefined'
87
- && Array.isArray(processing.colorswap)
88
- && processing.colorswap.length > 0) {
91
+ if (typeof processing !== 'undefined'
92
+ && Array.isArray(processing.colorswap)
93
+ && processing.colorswap.length > 0) {
89
94
 
90
- const bufferSource = fs.readFileSync(path.resolve(location, sourceTexture));
91
- const image = pngjs.read(bufferSource);
95
+ const bufferSource = fs.readFileSync(path.resolve(location, sourceTexture));
96
+ const image = pngjs.read(bufferSource);
92
97
 
93
- const pixels = image.data;
94
- const height = image.height;
95
- const width = image.width;
98
+ const pixels = image.data;
99
+ const height = image.height;
100
+ const width = image.width;
96
101
 
97
- processing.colorswap.forEach(({source, target}) => {
102
+ processing.colorswap.forEach(({source, target}) => {
98
103
 
99
- const [redSource, greenSource, blueSource, alphaSource] = source;
100
- const [redTarget, greenTarget, blueTarget, alphaTarget] = target;
104
+ const [redSource, greenSource, blueSource, alphaSource] = source;
105
+ const [redTarget, greenTarget, blueTarget, alphaTarget] = target;
101
106
 
102
- for (let y = 0; y < height; y += 1) {
107
+ for (let y = 0; y < height; y += 1) {
103
108
 
104
- for (let x = 0; x < width; x += 1) {
109
+ for (let x = 0; x < width; x += 1) {
105
110
 
106
- const index = (width * y + x) * 4;
111
+ const index = (width * y + x) * 4;
107
112
 
108
- const indexRed = index;
109
- const indexGreen = index + 1;
110
- const indexBlue = index + 2;
111
- const indexAlpha = index + 3;
113
+ const indexRed = index;
114
+ const indexGreen = index + 1;
115
+ const indexBlue = index + 2;
116
+ const indexAlpha = index + 3;
112
117
 
113
- if (pixels[indexRed] === redSource
114
- && pixels[indexGreen] === greenSource
115
- && pixels[indexBlue] === blueSource
116
- && pixels[indexAlpha] === alphaSource) {
118
+ if (pixels[indexRed] === redSource
119
+ && pixels[indexGreen] === greenSource
120
+ && pixels[indexBlue] === blueSource
121
+ && pixels[indexAlpha] === alphaSource) {
117
122
 
118
- pixels[indexRed] = redTarget;
119
- pixels[indexGreen] = greenTarget;
120
- pixels[indexBlue] = blueTarget;
121
- pixels[indexAlpha] = alphaTarget;
123
+ pixels[indexRed] = redTarget;
124
+ pixels[indexGreen] = greenTarget;
125
+ pixels[indexBlue] = blueTarget;
126
+ pixels[indexAlpha] = alphaTarget;
127
+ }
122
128
  }
123
129
  }
124
- }
125
- });
130
+ });
126
131
 
127
- const bufferTarget = pngjs.write(image);
128
- fs.writeFileSync(path.resolve(location, sourceTexture), bufferTarget);
132
+ const bufferTarget = pngjs.write(image);
133
+ fs.writeFileSync(path.resolve(location, sourceTexture), bufferTarget);
134
+ }
129
135
  }
130
136
 
131
137
  return (