-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (48 loc) · 2.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var fs = require('fs');
var path = require('path');
var gkaUtils = require('gka-utils');
var html = require("./lib/html");
module.exports = class CreatejsTemplatePlugin {
constructor() {
}
apply(compiler) {
compiler.hooks.on('templateOptions', (context, next) => {
context.options.sprites = true;
context.options.split = false;
context.options.diff = false;
next(context);
})
compiler.hooks.on('template', (context, next) => {
const {
options,
data,
} = context;
const dir = options.imgOutput;
function run(data, opts, key) {
var name = (key? key + '-' : '') + 'gka',
dataName = name + '-data.js',
htmlName = name + '.html';
var prefix = opts.prefix,
frameduration = opts.frameduration;
var frames = data.frames,
frame = frames[0];
var _data = {};
_data.file = frame.file;
_data.w = frame.w;
_data.h = frame.h;
_data.sourceW = frame.sourceW;
_data.sourceH = frame.sourceH;
_data.frames = frames.map(function(frame){
return JSON.stringify([frame.x, frame.y, frame.width, frame.height, 0, (0-frame.offX), (0-frame.offY)])
});
context.assets[dataName] = `var data = ${gkaUtils.data.fixArrayString(JSON.stringify(_data, null, ' '))}`;
context.assets[htmlName] = html(data, opts, dataName);
context.assets['easeljs-NEXT.combined.js'] = fs.readFileSync(path.join(__dirname, 'lib/easeljs-NEXT.combined.js'), 'utf8');
}
run(data[0], options);
// 对每个子目录都进行处理
gkaUtils._.effectSubFolderSync(run, data[0], options);
next(context);
})
}
}