Skip to content

Commit

Permalink
Fixed issue #67
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiamo2 committed Jan 1, 2025
1 parent b79792b commit 939be90
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ 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/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.1.7] - 2025-01-01

### Fixed
- Fixed issue #67

## [2.1.6] - 2024-12-23

### Fixed
Expand Down
7 changes: 6 additions & 1 deletion CSharp/addons/YATI/TilemapCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ private void HandleObject(Dictionary obj, Node layerNode, TileSet tileset, Vecto
objSprite.RotationDegrees = objRot;
objSprite.Visible = objVisible;
TileData td;
if (GetNumTilesForSourceId(sourceId) > 1)
if (IsPartitionedTileset(sourceId))
{
// Object is tile from partitioned tileset
var atlasWidth = gidSource.GetAtlasGridSize().X;
Expand Down Expand Up @@ -1912,6 +1912,11 @@ private string GetTilesetAlignment(int gid)
return (string)_atlasSources[idx]["objectAlignment"];
}

private bool IsPartitionedTileset(int sourceId)
{
return _atlasSources.Where(src => (int)src["sourceId"] == sourceId).Select(src => (int)src["assignedId"] < 0).FirstOrDefault();
}

private int GetNumTilesForSourceId(int sourceId)
{
foreach (var src in _atlasSources.Where(src => (int)src["sourceId"] == sourceId))
Expand Down
2 changes: 1 addition & 1 deletion CSharp/addons/YATI/TilesetCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private void CreateOrAppend(Dictionary tileSet)

_currentAtlasSource.Texture = texture;
_columns = _currentAtlasSource.Texture.GetWidth() / _tileSize.X;
_tileCount = _columns * _currentAtlasSource.Texture.GetHeight() / _tileSize.X;
_tileCount = _columns * _currentAtlasSource.Texture.GetHeight() / _tileSize.Y;

RegisterAtlasSource(addedSourceId, _tileCount, -1, _tileOffset);
var atlasGridSize = _currentAtlasSource.GetAtlasGridSize();
Expand Down
2 changes: 1 addition & 1 deletion CSharp/addons/YATI/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="YATI"
description=""
author="Roland Helmerichs"
version="2.1.6"
version="2.1.7"
script="TiledImport.cs"
7 changes: 6 additions & 1 deletion CSharp/runtime/TilemapCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ private void HandleObject(Dictionary obj, Node layerNode, TileSet tileset, Vecto
objSprite.RotationDegrees = objRot;
objSprite.Visible = objVisible;
TileData td;
if (GetNumTilesForSourceId(sourceId) > 1)
if (IsPartitionedTileset(sourceId))
{
// Object is tile from partitioned tileset
var atlasWidth = gidSource.GetAtlasGridSize().X;
Expand Down Expand Up @@ -1910,6 +1910,11 @@ private string GetTilesetAlignment(int gid)
return (string)_atlasSources[idx]["objectAlignment"];
}

private bool IsPartitionedTileset(int sourceId)
{
return _atlasSources.Where(src => (int)src["sourceId"] == sourceId).Select(src => (int)src["assignedId"] < 0).FirstOrDefault();
}

private int GetNumTilesForSourceId(int sourceId)
{
foreach (var src in _atlasSources.Where(src => (int)src["sourceId"] == sourceId))
Expand Down
2 changes: 1 addition & 1 deletion CSharp/runtime/TilesetCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private void CreateOrAppend(Dictionary tileSet)

_currentAtlasSource.Texture = texture;
_columns = _currentAtlasSource.Texture.GetWidth() / _tileSize.X;
_tileCount = _columns * _currentAtlasSource.Texture.GetHeight() / _tileSize.X;
_tileCount = _columns * _currentAtlasSource.Texture.GetHeight() / _tileSize.Y;

RegisterAtlasSource(addedSourceId, _tileCount, -1, _tileOffset);
var atlasGridSize = _currentAtlasSource.GetAtlasGridSize();
Expand Down
11 changes: 9 additions & 2 deletions GDScript/addons/YATI/TilemapCreator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ func handle_object(obj: Dictionary, layer_node: Node, tileset: TileSet, offset:
obj_sprite.rotation_degrees = obj_rot
obj_sprite.visible = obj_visible
var td
if get_num_tiles_for_source_id(source_id) > 1:
if is_partitioned_tileset(source_id):
# Object is tile from partitioned tileset
var atlas_width: int = gid_source.get_atlas_grid_size().x

Expand Down Expand Up @@ -1543,6 +1543,13 @@ func get_tileset_alignment(gid: int):
return _atlas_sources[idx]["objectAlignment"]


func is_partitioned_tileset(source_id: int) -> bool:
for src in _atlas_sources:
if src["sourceId"] == source_id:
return (src["assignedId"] < 0)
return false


func get_num_tiles_for_source_id(source_id: int):
for src in _atlas_sources:
if src["sourceId"] == source_id:
Expand Down Expand Up @@ -1583,7 +1590,7 @@ func handle_properties(target_node: Node, properties: Array):
target_node.add_to_group(group.strip_edges(), true)

# v1.6.6: script resource and godot_script property
if name.to_lower() == GODOT_SCRIPT_PROPERTY and type == "file":
elif name.to_lower() == GODOT_SCRIPT_PROPERTY and type == "file":
target_node.set_script(load(val))

# CanvasItem properties
Expand Down
2 changes: 1 addition & 1 deletion GDScript/addons/YATI/TilesetCreator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func create_or_append(tile_set: Dictionary):

_current_atlas_source.texture = texture
_columns = _current_atlas_source.texture.get_width() / _tile_size.x
_tile_count = _columns * _current_atlas_source.texture.get_height() / _tile_size.x
_tile_count = _columns * _current_atlas_source.texture.get_height() / _tile_size.y

register_atlas_source(added_source_id, _tile_count, -1, _tile_offset)
var atlas_grid_size = _current_atlas_source.get_atlas_grid_size()
Expand Down
2 changes: 1 addition & 1 deletion GDScript/addons/YATI/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="YATI"
description=""
author="Roland Helmerichs"
version="2.1.6"
version="2.1.7"
script="TiledImport.gd"
9 changes: 8 additions & 1 deletion GDScript/runtime/TilemapCreator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ func handle_object(obj: Dictionary, layer_node: Node, tileset: TileSet, offset:
obj_sprite.rotation_degrees = obj_rot
obj_sprite.visible = obj_visible
var td
if get_num_tiles_for_source_id(source_id) > 1:
if is_partitioned_tileset(source_id):
# Object is tile from partitioned tileset
var atlas_width: int = gid_source.get_atlas_grid_size().x

Expand Down Expand Up @@ -1542,6 +1542,13 @@ func get_tileset_alignment(gid: int):
return _atlas_sources[idx]["objectAlignment"]


func is_partitioned_tileset(source_id: int) -> bool:
for src in _atlas_sources:
if src["sourceId"] == source_id:
return (src["assignedId"] < 0)
return false


func get_num_tiles_for_source_id(source_id: int):
for src in _atlas_sources:
if src["sourceId"] == source_id:
Expand Down
2 changes: 1 addition & 1 deletion GDScript/runtime/TilesetCreator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func create_or_append(tile_set: Dictionary):

_current_atlas_source.texture = texture
_columns = _current_atlas_source.texture.get_width() / _tile_size.x
_tile_count = _columns * _current_atlas_source.texture.get_height() / _tile_size.x
_tile_count = _columns * _current_atlas_source.texture.get_height() / _tile_size.y

register_atlas_source(added_source_id, _tile_count, -1, _tile_offset)
var atlas_grid_size = _current_atlas_source.get_atlas_grid_size()
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ created by the [Tiled Map Editor](http://www.mapeditor.org).

Tested on Windows 10 with Godot 4.3/4.2.2 and Tiled 1.11.0 (Tiled maps from older Tiled versions may work too)

Latest version: 2.1.6 (needs Godot 4.3.0 or higher)
Downloads: [GDScript version](../../releases/download/v2.1.6/v2.1.6-gdscript.zip) / [CSharp version](../../releases/download/v2.1.6/v2.1.6-csharp.zip)
Latest version: 2.1.7 (needs Godot 4.3.0 or higher)
Downloads: [GDScript version](../../releases/download/v2.1.7/v2.1.7-gdscript.zip) / [CSharp version](../../releases/download/v2.1.7/v2.1.7-csharp.zip)

Latest version for Godot 4.2.x: 1.7.1
Version 1.7.1 downloads: [GDScript version](../../releases/download/v1.7.1/v1.7.1-gdscript.zip) / [CSharp version](../../releases/download/v1.7.1/v1.7.1-csharp.zip)
Expand All @@ -20,7 +20,7 @@ For installation and usage please refer to the [runtime document](Runtime.md)

The addon is available in GDScript as well as in C# for the Mono version of Godot 4.

- Download either the [GDScript version](../../releases/download/v2.1.6/v2.1.6-gdscript.zip) or the [CSharp version](../../releases/download/v2.1.6/v2.1.6-csharp.zip)
- Download either the [GDScript version](../../releases/download/v2.1.7/v2.1.7-gdscript.zip) or the [CSharp version](../../releases/download/v2.1.7/v2.1.7-csharp.zip)
- Move the unzipped addon folder with its entire content to your Godot project folder
- After starting your project in Godot the plugin should appear at Project>>Project Settings...>>Plugins

Expand Down
2 changes: 1 addition & 1 deletion Runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The YATI runtime package allows for importing Tiled maps during (game) runtime.
To offer such a package was proposed by Jeff Brooks (see issue #16) as being of value for several users.

Like for the editor plugin there's a [GDScript version](../../releases/download/v2.1.6/runtime-v2.1.6-gdscript.zip) and a [CSharp version](../../releases/download/v2.1.6/runtime-v2.1.6-csharp.zip) available.
Like for the editor plugin there's a [GDScript version](../../releases/download/v2.1.7/runtime-v2.1.7-gdscript.zip) and a [CSharp version](../../releases/download/v2.1.7/runtime-v2.1.7-csharp.zip) available.

(Runtime downloads for Godot 4.2.x: [GDScript version](../../releases/download/v1.7.1/runtime-v1.7.1-gdscript.zip) and a [CSharp version](../../releases/download/v1.7.1/runtime-v1.7.1-csharp.zip))

Expand Down

0 comments on commit 939be90

Please sign in to comment.