diff --git a/CHANGELOG.md b/CHANGELOG.md index 9667095..8aa7442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [Version 3.2.0] - 2023-05-23 + +### Added + +- Added PixiJS template. +- Replacing variables in tag values. + +### Changed + +- Renamed template files to .inja. + +### Fixed + +- Fixed output path for descriptions. +- Fixed redundancy check when outputting multiple descriptions. + ## [Version 3.1.0] - 2023-05-20 ### Added @@ -192,6 +208,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fixed -- commandline arguments. - Fixed sample cpp.template. +[version 3.2.0]: https://github.com/houmain/spright/compare/3.1.0...3.2.0 [version 3.1.0]: https://github.com/houmain/spright/compare/3.0.0...3.1.0 [version 3.0.0]: https://github.com/houmain/spright/compare/2.3.0...3.0.0 [version 2.3.0]: https://github.com/houmain/spright/compare/2.2.0...2.3.0 diff --git a/README.md b/README.md index 893a2a7..1a3f5fe 100644 --- a/README.md +++ b/README.md @@ -53,10 +53,10 @@ glob "characters/**/*.png" glob "scenery/**/*.png" ``` -Unless specified on the [command line](#command-line-arguments) spright reads the input definition from `spright.conf` in the current directory. To pack the sheets and generate an output description consumable by e.g. [Phaser](https://github.com/photonstorm/phaser) using the [phaser.template](templates/phaser.template), call: +Unless specified on the [command line](#command-line-arguments) spright reads the input definition from `spright.conf` in the current directory. To pack the sheets and generate an output description consumable by e.g. [Phaser](https://github.com/photonstorm/phaser) using the [phaser.inja](templates/phaser.inja), call: ``` -spright -t phaser.template +spright -t phaser.inja ``` See the [input definition](#input-definition-reference) section for a description of the available options. \ @@ -66,8 +66,8 @@ See the [output template engine](#output-template-engine) section on how to gene Say you got some [nice](https://itch.io/game-assets/tag-sprites) [sprites](https://opengameart.org/art-search-advanced?field_art_type_tid[]=9&sort_by=count) you would like to use in your next game: -| "Decorations (32x32).png" | "Old enemies 2.png" | "misc_scenery.png" | "OrcAttack/Frame01.png" to
"OrcAttack/Frame04.png" | -| :--------------------------------------------------: | :---------------------------------: | :-------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | +| "Decorations (32x32).png" | "Old enemies 2.png" | "misc_scenery.png" | "OrcAttack/Frame01.png" to
"OrcAttack/Frame04.png" | +| :--: | :--: | :--: | :--: | | | | | | And your game engine supports efficiently packed sprite sheets like this: @@ -352,7 +352,7 @@ With the power of the [inja](https://github.com/pantor/inja/) template engine it A template is selected with the **-t** or **--template** and the output filename with the **-o** or **--output** parameter: ``` -spright -t cpp.template -o spright.h +spright -t cpp.inja -o spright.h ``` This is what a simple template, that transforms the IDs of the output description's sprites into a JavaScript array initialization, looks like: @@ -369,11 +369,12 @@ For information about the functionality of the template engine, please see the [ | Target | Template | | ------------------------------------------------- | ---------------------------------------------- | -| C++ | [cpp.template](templates/cpp.template) | -| [Phaser 3](https://github.com/photonstorm/phaser) | [phaser.template](templates/phaser.template) | -| [Phaser 2](https://github.com/photonstorm/phaser) | [phaser2.template](templates/phaser2.template) | +| C++ | [cpp.inja](templates/cpp.inja) | +| [Phaser 3](https://github.com/photonstorm/phaser) | [phaser.inja](templates/phaser.inja) | +| [Phaser 2](https://github.com/photonstorm/phaser) | [phaser2.inja](templates/phaser2.inja) | +| [PixiJS](https://pixijs.com/) | [pixijs.inja](templates/pixijs.inja) | -The C++ template is just an example for how the sprite description can be directly embedded in code. This [spright.h](docs/spright.h) was generated from the [sample](#advanced-usage-example), using the [cpp.template](templates/cpp.template) template. +The C++ template is just an example for how the sprite description can be directly embedded in code. This [spright.h](docs/spright.h) was generated from the [sample](#advanced-usage-example), using the [cpp.inja](templates/cpp.inja) template. ## Command line arguments diff --git a/templates/cpp.template b/templates/cpp.inja similarity index 100% rename from templates/cpp.template rename to templates/cpp.inja diff --git a/templates/phaser.template b/templates/phaser.inja similarity index 89% rename from templates/phaser.template rename to templates/phaser.inja index fc2f270..3563d75 100644 --- a/templates/phaser.template +++ b/templates/phaser.inja @@ -3,7 +3,7 @@ "app": "https://github.com/houmain/spright" }, "textures": [ -{% for texture in textures %} +## for texture in textures { "image": "{{ texture.filename }}", "format": "RGBA8888", @@ -13,8 +13,8 @@ }, "scale": 1, "frames": [ -{% for index in texture.spriteIndices %}{% set sprite=at(sprites, index) %} - { +## for index in texture.spriteIndices + { {% set sprite=at(sprites, index) %} "filename": "{{ sprite.id }}", "rotated": {{ sprite.rotated }}, "trimmed": {% if sprite.rect.w == sprite.trimmedRect.w and sprite.rect.h == sprite.trimmedRect.h %}false{% else %}true{% endif %}, @@ -39,9 +39,9 @@ "y": {{ sprite.pivot.y / sprite.rect.h }} } }{% if sprite != last(sprites) %},{% endif %} -{% endfor %} +## endfor ] } -{% endfor %} +## endfor ] } diff --git a/templates/phaser2.template b/templates/phaser2.inja similarity index 95% rename from templates/phaser2.template rename to templates/phaser2.inja index bd9330d..015b024 100644 --- a/templates/phaser2.template +++ b/templates/phaser2.inja @@ -3,8 +3,8 @@ "app": "https://github.com/houmain/spright" }, "frames": [ -{% for sprite in sprites %} - { +## for sprite in sprites + { "filename": "{{ sprite.id }}", "rotated": {{ sprite.rotated }}, "trimmed": {% if sprite.rect.w == sprite.trimmedRect.w and sprite.rect.h == sprite.trimmedRect.h %}false{% else %}true{% endif %}, @@ -29,6 +29,6 @@ "y": {{ sprite.pivot.y / sprite.rect.h }} } }{% if sprite != last(sprites) %},{% endif %} -{% endfor %} +## endfor ] } diff --git a/templates/pixijs.inja b/templates/pixijs.inja new file mode 100644 index 0000000..fcd5d52 --- /dev/null +++ b/templates/pixijs.inja @@ -0,0 +1,43 @@ +{"frames": { +## for sprite in sprites +"{{ sprite.id }}": +{ + "rotated": {{ sprite.rotated }}, + "trimmed": {% if sprite.rect.w == sprite.trimmedRect.w and sprite.rect.h == sprite.trimmedRect.h %}false{% else %}true{% endif %}, + "sourceSize": { + "w": {{ sprite.sourceRect.w }}, + "h": {{ sprite.sourceRect.h }} + }, + "spriteSourceSize": { + "x": {{ sprite.trimmedSourceRect.x }}, + "y": {{ sprite.trimmedSourceRect.y }}, + "w": {{ sprite.trimmedSourceRect.w }}, + "h": {{ sprite.trimmedSourceRect.h }} + }, + "frame": { + "x": {{ sprite.trimmedRect.x }}, + "y": {{ sprite.trimmedRect.y }}, + "w": {{ sprite.trimmedRect.w }}, + "h": {{ sprite.trimmedRect.h }} + }, + "anchor": { + "x": {{ sprite.pivot.x / sprite.rect.w }}, + "y": {{ sprite.pivot.y / sprite.rect.h }} + } +}{% if sprite != last(sprites) %},{% endif %} +## endfor +}, +"animations": { +## for value, indices in tags.anim + "{{ value }}": [{% for index in indices %}"{{ at(sprites, index).id }}"{% if index != last(indices) %}, {% endif %}{% endfor %}]{% if loop.index1 < length(tags.anim) %},{% endif %} +## endfor +}, +"meta": { + "app": "https://github.com/houmain/spright", + "format": "RGBA8888", +## for texture in textures + "image": "{{ texture.filename }}", + "size": { "w": {{ texture.width }}, "h": {{ texture.height }} } +## endfor +} +}