Skip to content

Commit

Permalink
Renamed template files to .inja, added Pixijs
Browse files Browse the repository at this point in the history
  • Loading branch information
houmain committed May 23, 2023
1 parent 8be05da commit f413620
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 17 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. \
Expand All @@ -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 <br/> "OrcAttack/Frame04.png" |
| :--------------------------------------------------: | :---------------------------------: | :-------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| "Decorations (32x32).png" | "Old enemies 2.png" | "misc_scenery.png" | "OrcAttack/Frame01.png" to <br/> "OrcAttack/Frame04.png" |
| :--: | :--: | :--: | :--: |
| <kbd><img src="docs/Decorations (32x32).png"/></kbd> | <img src="docs/Old enemies 2.png"/> | <kbd><img src="docs/misc_scenery.png"/></kbd> | <kbd><img src="docs/Orc Attack/Frame01.png"/></kbd> <kbd><img src="docs/Orc Attack/Frame02.png"/></kbd> <kbd><img src="docs/Orc Attack/Frame03.png"/></kbd> <kbd><img src="docs/Orc Attack/Frame04.png"/></kbd> |

And your game engine supports efficiently packed sprite sheets like this:
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions templates/phaser.template → templates/phaser.inja
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"app": "https://github.com/houmain/spright"
},
"textures": [
{% for texture in textures %}
## for texture in textures
{
"image": "{{ texture.filename }}",
"format": "RGBA8888",
Expand All @@ -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 %},
Expand All @@ -39,9 +39,9 @@
"y": {{ sprite.pivot.y / sprite.rect.h }}
}
}{% if sprite != last(sprites) %},{% endif %}
{% endfor %}
## endfor
]
}
{% endfor %}
## endfor
]
}
6 changes: 3 additions & 3 deletions templates/phaser2.template → templates/phaser2.inja
Original file line number Diff line number Diff line change
Expand Up @@ -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 %},
Expand All @@ -29,6 +29,6 @@
"y": {{ sprite.pivot.y / sprite.rect.h }}
}
}{% if sprite != last(sprites) %},{% endif %}
{% endfor %}
## endfor
]
}
43 changes: 43 additions & 0 deletions templates/pixijs.inja
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit f413620

Please sign in to comment.