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

Added support for one-way collision shapes #51

Open
wants to merge 2 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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ To setup a collision shape for a tile, first edit the tileset in Tiled:

- Select the tile in the tileset file
- You should see a side panel "Tile Collision Editor", use the menu above it to create a new shape. Use rectangle or polygon only.
- For a one-way collision, with the Object shape selected set the `Type` or `Class` field to `one-way`.

For navigation, do the same thing, but with the Object shape selected, set the `Type` field to `navigation`.
For navigation, do the same thing, but with the Object shape selected, set the `Type` or `Class` field to `navigation`.

## Why use it?

Expand All @@ -164,7 +165,7 @@ More about my struggles can be read in Tiled Forum or Godot reddit. Check the Co
- [x] Export collision shapes<sup>*</sup>
- [ ] Export occluder shapes<sup>*</sup>
- [x] Export navigation shapes<sup>*</sup>
- [ ] Support for one-way collision shapes
- [x] Support for one-way collision shapes
- [ ] Support for image layers
- [x] Support for tile objects, which are exported to Godot as Sprite nodes. (Other types of objects are not yet included.)
- [ ] Full support for object layers, which are exported as StaticBody2D, Area2D or LightOccluder2D for shapes (depending on the type property) and as Sprite for tiles
Expand Down
9 changes: 5 additions & 4 deletions export_to_godot_tileset.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@ class GodotTilesetExporter {
* @param {point} autotileCoordinates autotile coordinates for the tile
*/
exportCollisions(object, tile, autotileCoordinates) {
var isOneWay = object.type === "one-way";
// noinspection JSUnresolvedVariable
if (object.polygon.length > 0) {
this.shapesResources += this.getCollisionShapePolygon(tile.id, object);
this.exportShapes(tile, autotileCoordinates);
this.exportShapes(tile, autotileCoordinates, isOneWay);
} else if (object.width > 0 && object.height > 0) {
this.shapesResources += this.getCollisionShapeRectangle(tile.id, object);
this.exportShapes(tile, autotileCoordinates);
this.exportShapes(tile, autotileCoordinates, isOneWay);
}
}

Expand All @@ -132,13 +133,13 @@ class GodotTilesetExporter {
* @param {Tile} tile the target tile
* @param {point} autotileCoordinates autotile coordinates for the tile
*/
exportShapes(tile, autotileCoordinates) {
exportShapes(tile, autotileCoordinates, isOneWay) {
if (this.firstShapeID === "") {
this.firstShapeID = 'SubResource( ' + tile.id + ' )';
}
this.shapes += this.getShapesTemplate(
autotileCoordinates,
false,
isOneWay,
tile.id
);
}
Expand Down