odrick / free-tex-packer

Free texture packer
http://free-tex-packer.com/
MIT License
927 stars 173 forks source link

[Feature Request] Export Solar2D information and data #68

Open Hexality opened 2 years ago

Hexality commented 2 years ago

Export sheet options information as a importable (local name = require("animation") lua file. image

Hexality commented 2 years ago

(these lua files and sheet got exported using trial version of texturepacker with sucks)

jcbk101 commented 2 years ago

Here, try the code block at the very bottom. Remember though, if 'trimmed' is not checked, remove these lines.

        sourceX = {{spriteSourceSize.x}},
        sourceY = {{spriteSourceSize.y}},
        sourceWidth = {{spriteSourceSize.w}},
        sourceHeight = {{spriteSourceSize.h}},

I cannot get...

 {{#trimmed}}
 "data in here" 
{{/trimmed}} 

...to act as "logic" though it is checked if true or false. :(

These lines are just here to produce the names. I cannot get any index numbers to print to save my life. I guess that data is not passed in the "rects" prop. :( But they can be adjusted after all data is printed.

SheetInfo.frameIndex =
{
    {{#rects}}
    ["{{name}}"] = 1,
    {{/rects}}
}

If trim is checked then leave as is. Also, don't forget the check the box "Remove file ext".

Actual code to use in the "custom" export format window.

local SheetInfo = {}

SheetInfo.sheet =
{
  frames =  {
    {{#rects}}
      {
        -- {{{name}}}
        sourceX = {{spriteSourceSize.x}},
        sourceY = {{spriteSourceSize.y}},
        sourceWidth = {{spriteSourceSize.w}},
        sourceHeight = {{spriteSourceSize.h}},

        x = {{frame.x}},
        y = {{frame.y}},
        width = {{frame.w}},
        height = {{frame.h}},
      },
    {{/rects}} 
  },

  sheetContentWidth = {{config.imageWidth}},
  sheetContentHeight = {{config.imageHeight}}
}

SheetInfo.frameIndex =
{
    {{#rects}}
    ["{{name}}"] = 1,
    {{/rects}}
}

function SheetInfo:getSheet()
    return self.sheet;
end

function SheetInfo:getFrameIndex(name)
    return self.frameIndex[name];
end

return SheetInfo