-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixiAdvExporter.qs
81 lines (75 loc) · 2.7 KB
/
pixiAdvExporter.qs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var exportSprites = function(sprites, locationPrefix) {
var result = {};
for (var i = 0; i < sprites.length; i++) {
var s = sprites[i];
var frame = {
x: s.frameRect.x,
y: s.frameRect.y,
w: s.rotated ? s.frameRect.height : s.frameRect.width,
h: s.rotated ? s.frameRect.width : s.frameRect.height
};
var spriteName = locationPrefix + s.trimmedName;
result[spriteName] = {
frame: frame,
rotated: s.rotated,
trimmed: s.trimmed,
spriteSourceSize: {
x: s.trimmed ? s.sourceRect.x : 0,
y: s.trimmed ? s.sourceRect.y : 0,
w: s.trimmed ? s.sourceRect.width : frame.w,
h: s.trimmed ? s.sourceRect.height : frame.h
},
sourceSize: {
w: s.untrimmedSize.width,
h: s.untrimmedSize.height
}
};
}
return result;
};
var generateRelatedMultiPacks = function(root, currentTextureName)
{
var relatedPacks = [];
var textures = root.allResults[root.variantIndex].textures;
for (var i = 0; i < textures.length; i++)
{
var textureName = textures[i].fullName;
if (textureName !== currentTextureName)
{
textureName = textureName.split(".").slice(0, -1).join(".");
relatedPacks.push(textureName + ".json");
}
}
return relatedPacks;
};
var exportData = function(root)
{
var settings = root.settings;
var variantParams = root.variantParams;
var locationPrefix = root.exporterProperties.location_prefix || '';
var includeScale = root.exporterProperties.include_scale;
var currentTexture = root.allResults[root.variantIndex].textures[root.multiPackIndex];
var currentTextureName = currentTexture.fullName;
var doc = {
frames: exportSprites(currentTexture.allSprites, locationPrefix),
meta: {
app: "https://www.codeandweb.com/texturepacker",
version: "1.0",
image: currentTextureName,
format: settings.outputFormat,
size: {
w: currentTexture.size.width,
h: currentTexture.size.height
},
//scale: variantParams.scale.toString(),
related_multi_packs: generateRelatedMultiPacks(root, currentTextureName),
smartupdate: root.smartUpdateKey
}
};
if(includeScale) {
doc.meta.scale = variantParams.scale.toString();
}
return JSON.stringify(doc, null, "\t");
};
exportData.filterName = "exportData";
Library.addFilter("exportData");