@theatrejs/loader-aseprite 1.2.0 → 1.4.0

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.2.0"
60
+ "version": "1.4.0"
61
61
  }
@@ -12,24 +12,24 @@ const pngjs = require('pngjs').PNG.sync;
12
12
  module.exports = function loader() {
13
13
 
14
14
  /**
15
- * @typedef {Object} typecolorswap A swap of two colors.
16
- * @property {Array<number>} typecolorswap.source The source color to swap from (in rgba).
17
- * @property {Array<number>} typecolorswap.target The target color to swap to (in rgba).
15
+ * @typedef {Object} TypeColorswap A swap of two colors.
16
+ * @property {Array<number>} TypeColorswap.source The source color to swap from (in rgba).
17
+ * @property {Array<number>} TypeColorswap.target The target color to swap to (in rgba).
18
18
  * @private
19
19
  */
20
20
 
21
21
  /**
22
- * @typedef {Object} typeoptions The options for the loader.
23
- * @property {string} typeoptions.aseprite The path to the Aseprite executable.
24
- * @property {Object} [typeoptions.prepare] The options for the Aseprite CLI.
25
- * @property {('colums' | 'horizontal' | 'packed' | 'rows' | 'vertical')} [typeoptions.prepare.sheet] The output sheet type ('rows' by default).
26
- * @property {boolean} [typeoptions.prepare.trim] The 'trim cels' option (false by default).
27
- * @property {Object} [typeoptions.processing] The options for processing the output files.
28
- * @property {Array<typecolorswap>} [typeoptions.processing.colorswap] The swaps of colors.
22
+ * @typedef {Object} TypeOptions The options for the loader.
23
+ * @property {string} TypeOptions.aseprite The path to the Aseprite executable.
24
+ * @property {Object} [TypeOptions.prepare] The options for the Aseprite CLI.
25
+ * @property {('colums' | 'horizontal' | 'packed' | 'rows' | 'vertical')} [TypeOptions.prepare.sheet] The output sheet type ('rows' by default).
26
+ * @property {boolean} [TypeOptions.prepare.trim] The 'trim cels' option (false by default).
27
+ * @property {Object} [TypeOptions.processing] The options for processing the output files.
28
+ * @property {Array<TypeColorswap>} [TypeOptions.processing.colorswap] The swaps of colors.
29
29
  * @private
30
30
  */
31
31
 
32
- const context = /** @type {webpack.LoaderContext<typeoptions>} */(this);
32
+ const context = /** @type {webpack.LoaderContext<TypeOptions>} */(this);
33
33
 
34
34
  const file = context.resourcePath;
35
35
  const options = context.getOptions();
@@ -42,9 +42,9 @@ module.exports = function loader() {
42
42
  require.resolve('@theatrejs/plugin-aseprite');
43
43
  }
44
44
 
45
- catch (error) {
45
+ catch ($error) {
46
46
 
47
- throw error;
47
+ throw $error;
48
48
  }
49
49
 
50
50
  if (typeof aseprite === 'undefined') {
@@ -67,65 +67,71 @@ module.exports = function loader() {
67
67
 
68
68
  try {
69
69
 
70
- subprocess.execSync(
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) {
71
74
 
72
- 'cd "' + location + '"' +
75
+ subprocess.execSync(
73
76
 
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
- );
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 (
@@ -139,9 +145,9 @@ module.exports = function loader() {
139
145
  );
140
146
  }
141
147
 
142
- catch (error) {
148
+ catch ($error) {
143
149
 
144
- throw error;
150
+ throw $error;
145
151
  }
146
152
  };
147
153