Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusted Godot Atlas exporter to take margins into account #85

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
.idea/*
.vscode/*

node_modules/*

package-lock.json

.DS_Store
/index.js
/index.js.map
/dist/app
/electron/www
.idea/*
.vscode/*

node_modules/*

dist/*

package-lock.json

yarn.lock

.DS_Store
/index.js
/index.js.map
/dist/app
/electron/www
8 changes: 8 additions & 0 deletions src/client/exporters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ function prepareData(data, options) {
let frame = {x: item.frame.x, y: item.frame.y, w: item.frame.w, h: item.frame.h, hw: item.frame.w/2, hh: item.frame.h/2};
let spriteSourceSize = {x: item.spriteSourceSize.x, y: item.spriteSourceSize.y, w: item.spriteSourceSize.w, h: item.spriteSourceSize.h};
let sourceSize = {w: item.sourceSize.w, h: item.sourceSize.h};

//Used when importing to Godot Atlas to retain the original sprite size
let margin = {x: (sourceSize.w - spriteSourceSize.w)/2, y: (sourceSize.h - spriteSourceSize.h)/2, h: sourceSize.h - spriteSourceSize.h, w: sourceSize.w - spriteSourceSize.w}
Copy link

@Gerfalerf Gerfalerf Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think rather than splitting the difference of spriteSourceSize and sourceSize, margin.x and margin.y here should simply be set to spriteSourceSize.x and spriteSourceSize.y. Weird that spriteSourceSize is called a "size" when it has an offset like a rect, but those x/y values appear to be the actual offset of the sprite's subregion that was copied into the atlas.

Otherwise, change looks great. Just ran into this issue myself.


let trimmed = item.trimmed;

Expand All @@ -102,6 +105,10 @@ function prepareData(data, options) {
frame.h *= opt.scale;
frame.hw *= opt.scale;
frame.hh *= opt.scale;
margin.x *= opt.scale;
margin.y *= opt.scale;
margin.w *= opt.scale;
margin.h *= opt.scale;

spriteSourceSize.x *= opt.scale;
spriteSourceSize.y *= opt.scale;
Expand All @@ -117,6 +124,7 @@ function prepareData(data, options) {
frame: frame,
spriteSourceSize: spriteSourceSize,
sourceSize: sourceSize,
margin: margin,
rotated: item.rotated,
trimmed: trimmed
});
Expand Down
6 changes: 3 additions & 3 deletions src/client/exporters/list.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@
"type": "Godot (atlas)",
"description": "Godot Atlas format",
"allowTrim": true,
"allowRotation": true,
"allowRotation": false,
"template": "GodotAtlas.mst",
"fileExt": "tpsheet"
},
{
"type": "Godot (tileset)",
"description": "Godot Tileset format",
"description": "Godot Tileset format (3.x only)",
"allowTrim": true,
"allowRotation": true,
"allowRotation": false,
"template": "GodotTileset.mst",
"fileExt": "tpset"
},
Expand Down
8 changes: 4 additions & 4 deletions src/client/resources/static/exporters/GodotAtlas.mst
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"h": {{frame.h}}
},
"margin": {
"x": 0,
"y": 0,
"w": 0,
"h": 0
"x": {{margin.x}},
"y": {{margin.y}},
"w": {{margin.w}},
"h": {{margin.h}}
}
}{{^last}},{{/last}}
{{/rects}}
Expand Down