@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 +2 -2
- package/sources/aseprite.loader.js +64 -58
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.
|
|
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}
|
|
16
|
-
* @property {Array<number>}
|
|
17
|
-
* @property {Array<number>}
|
|
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}
|
|
23
|
-
* @property {string}
|
|
24
|
-
* @property {Object} [
|
|
25
|
-
* @property {('colums' | 'horizontal' | 'packed' | 'rows' | 'vertical')} [
|
|
26
|
-
* @property {boolean} [
|
|
27
|
-
* @property {Object} [
|
|
28
|
-
* @property {Array<
|
|
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<
|
|
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
|
-
|
|
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
|
-
|
|
75
|
+
subprocess.execSync(
|
|
73
76
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
if (typeof processing !== 'undefined'
|
|
92
|
+
&& Array.isArray(processing.colorswap)
|
|
93
|
+
&& processing.colorswap.length > 0) {
|
|
89
94
|
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
const bufferSource = fs.readFileSync(path.resolve(location, sourceTexture));
|
|
96
|
+
const image = pngjs.read(bufferSource);
|
|
92
97
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
const pixels = image.data;
|
|
99
|
+
const height = image.height;
|
|
100
|
+
const width = image.width;
|
|
96
101
|
|
|
97
|
-
|
|
102
|
+
processing.colorswap.forEach(({source, target}) => {
|
|
98
103
|
|
|
99
|
-
|
|
100
|
-
|
|
104
|
+
const [redSource, greenSource, blueSource, alphaSource] = source;
|
|
105
|
+
const [redTarget, greenTarget, blueTarget, alphaTarget] = target;
|
|
101
106
|
|
|
102
|
-
|
|
107
|
+
for (let y = 0; y < height; y += 1) {
|
|
103
108
|
|
|
104
|
-
|
|
109
|
+
for (let x = 0; x < width; x += 1) {
|
|
105
110
|
|
|
106
|
-
|
|
111
|
+
const index = (width * y + x) * 4;
|
|
107
112
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
const indexRed = index;
|
|
114
|
+
const indexGreen = index + 1;
|
|
115
|
+
const indexBlue = index + 2;
|
|
116
|
+
const indexAlpha = index + 3;
|
|
112
117
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
if (pixels[indexRed] === redSource
|
|
119
|
+
&& pixels[indexGreen] === greenSource
|
|
120
|
+
&& pixels[indexBlue] === blueSource
|
|
121
|
+
&& pixels[indexAlpha] === alphaSource) {
|
|
117
122
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
128
|
-
|
|
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
|
|