@theatrejs/loader-aseprite 1.0.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/LICENSE +21 -0
- package/README.md +81 -0
- package/package.json +44 -0
- package/sources/aseprite.loader.js +83 -0
- package/sources/index.js +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Alexandre Blondeau (deformhead) deformhead@gmail.com
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
[](https://github.com/deformhead) [](https://github.com/theatrejs/loader-aseprite/blob/master/LICENSE) [](https://www.npmjs.com/package/@theatrejs/loader-aseprite/v/latest) [](https://www.npmjs.com/package/@theatrejs/loader-aseprite/v/latest)
|
|
2
|
+
|
|
3
|
+
# Aseprite Webpack Loader
|
|
4
|
+
|
|
5
|
+
> *⚙️ A Webpack Loader for Aseprite files.*
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
#### `dependencies`
|
|
10
|
+
|
|
11
|
+
```shell
|
|
12
|
+
npm install @theatrejs/plugin-aseprite --save
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```shell
|
|
16
|
+
npm install @theatrejs/loader-aseprite --save-dev
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
#### `webpack configuration`
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
{
|
|
23
|
+
'module': {
|
|
24
|
+
'rules': [
|
|
25
|
+
...
|
|
26
|
+
{
|
|
27
|
+
'test': /\.aseprite$/,
|
|
28
|
+
'use': [
|
|
29
|
+
{
|
|
30
|
+
'loader': '@theatrejs/loader-aseprite',
|
|
31
|
+
'options': {
|
|
32
|
+
'aseprite': <path-to-aseprite-executable>
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
...
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Quick Start
|
|
44
|
+
|
|
45
|
+
> *⚠️ This example does not include the preloading of assets.*
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
import {Actor} from '@theatrejs/theatrejs';
|
|
49
|
+
|
|
50
|
+
import spritesheetHero from './hero-16x16.aseprite';
|
|
51
|
+
|
|
52
|
+
class Hero extends Actor {
|
|
53
|
+
onCreate() {
|
|
54
|
+
this.$timeline = spritesheetHero.createTimeline({$actor: this, $framerate: 8, $loop: true, $tag: 'idle'});
|
|
55
|
+
}
|
|
56
|
+
onTick($timetick) {
|
|
57
|
+
this.$timeline.tick($timetick);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## With Preloading
|
|
63
|
+
|
|
64
|
+
```javascript
|
|
65
|
+
import {FACTORIES} from '@theatrejs/theatrejs';
|
|
66
|
+
|
|
67
|
+
import * as PLUGINASEPRITE from '@theatrejs/plugin-aseprite';
|
|
68
|
+
|
|
69
|
+
import spritesheetHero from './hero-16x16.aseprite';
|
|
70
|
+
|
|
71
|
+
class Hero extends FACTORIES.ActorWithPreloadables([PLUGINASEPRITE.FACTORIES.PreloadableAseprite(spritesheetHero)]) {
|
|
72
|
+
onCreate() {
|
|
73
|
+
this.$timeline = spritesheetHero.createTimeline({$actor: this, $framerate: 8, $loop: true, $tag: 'idle'});
|
|
74
|
+
}
|
|
75
|
+
onTick($timetick) {
|
|
76
|
+
this.$timeline.tick($timetick);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## [API](https://theatrejs.github.io/loader-aseprite/index.html)
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "Alexandre Blondeau",
|
|
3
|
+
"description": "⚙️ A Webpack Loader for Aseprite files.",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": "16.13.0",
|
|
6
|
+
"npm": "8.1.0"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"sources/"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/theatrejs/loader-aseprite",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"2d",
|
|
14
|
+
"aseprite",
|
|
15
|
+
"canvas",
|
|
16
|
+
"engine",
|
|
17
|
+
"game",
|
|
18
|
+
"game-engine",
|
|
19
|
+
"html",
|
|
20
|
+
"html5",
|
|
21
|
+
"javascript",
|
|
22
|
+
"pixel-art",
|
|
23
|
+
"loader",
|
|
24
|
+
"theatrejs",
|
|
25
|
+
"theatrejs-loader",
|
|
26
|
+
"webgl",
|
|
27
|
+
"webgl2",
|
|
28
|
+
"webpack",
|
|
29
|
+
"webpack-loader"
|
|
30
|
+
],
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"main": "./sources/index.js",
|
|
33
|
+
"name": "@theatrejs/loader-aseprite",
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@theatrejs/plugin-aseprite": ">= 1.0.0",
|
|
36
|
+
"webpack": ">= 5.94.0"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/theatrejs/loader-aseprite.git"
|
|
41
|
+
},
|
|
42
|
+
"type": "commonjs",
|
|
43
|
+
"version": "1.0.0"
|
|
44
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const subprocess = require('child_process');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const webpack = require('webpack');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @type {webpack.RawLoaderDefinition}
|
|
9
|
+
*/
|
|
10
|
+
module.exports = function loader() {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {Object} typeoptions Options for the loader.
|
|
14
|
+
* @property {(string | undefined)} typeoptions.aseprite The path of the Aseprite executable.
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const context = /** @type {webpack.LoaderContext<typeoptions>} */(this);
|
|
19
|
+
|
|
20
|
+
const file = context.resourcePath;
|
|
21
|
+
const options = context.getOptions();
|
|
22
|
+
const aseprite = options.aseprite;
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
|
|
26
|
+
require.resolve('@theatrejs/plugin-aseprite');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
catch (error) {
|
|
30
|
+
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (typeof aseprite === 'undefined') {
|
|
35
|
+
|
|
36
|
+
throw new Error('Aseprite executable path is missing in the loader options.');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (fs.existsSync(aseprite) === false) {
|
|
40
|
+
|
|
41
|
+
throw new Error('Aseprite executable not found reading path: ' + (typeof aseprite !== 'undefined' || aseprite !== '' ? '\'' + aseprite + '\'' : '<empty>') + '.');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const location = path.dirname(file);
|
|
45
|
+
const filename = path.basename(file, '.aseprite');
|
|
46
|
+
const png = filename + '.png';
|
|
47
|
+
const json = filename + '.json';
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
|
|
51
|
+
subprocess.execSync(
|
|
52
|
+
|
|
53
|
+
'cd "' + location + '"' +
|
|
54
|
+
|
|
55
|
+
' && "' + aseprite + '"' +
|
|
56
|
+
' --batch "' + file + '"' +
|
|
57
|
+
' --sheet "' + png + '"' +
|
|
58
|
+
' --sheet-type rows' +
|
|
59
|
+
' --split-tags' +
|
|
60
|
+
' --data "' + json + '"' +
|
|
61
|
+
' --list-tags' +
|
|
62
|
+
' --format json-array' +
|
|
63
|
+
' --filename-format {tag}#{tagframe001}@{title}.{extension}'
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
|
|
68
|
+
'import {Aseprite} from \'@theatrejs/plugin-aseprite\';' +
|
|
69
|
+
|
|
70
|
+
'import texture from \'./' + png + '\';' +
|
|
71
|
+
'import data from \'./' + json + '\';' +
|
|
72
|
+
|
|
73
|
+
'export default new Aseprite(texture, data);'
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
catch (error) {
|
|
78
|
+
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
module.exports.raw = true;
|
package/sources/index.js
ADDED