Skip to content

Commit

Permalink
Version 1.7.1 for Godot 4.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiamo2 committed Nov 13, 2024
1 parent 1f0cb8a commit 3cc9f94
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 23 deletions.
19 changes: 14 additions & 5 deletions CSharp/addons/YATI/TilemapCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -826,13 +826,18 @@ private static void SetSpriteOffset(Sprite2D objSprite, float width, float heigh
};
}

private static void ConvertMetaDataToObjProperties(TileData td, Dictionary obj)
private void ConvertMetaDataToObjProperties(TileData td, Dictionary obj)
{
var metaList = td.GetMetaList();
foreach (var metaName in metaList)
{
if (((string)metaName)?.ToLower() is ClassInternal or GodotNodeTypeProperty)
switch (((string)metaName)?.ToLower())
{
case GodotNodeTypeProperty:
case ClassInternal when !_addClassAsMetadata:
continue;
}

var metaVal = td.GetMeta(metaName);
var metaType = metaVal.VariantType;
var propDict = new Dictionary();
Expand Down Expand Up @@ -1111,7 +1116,7 @@ private void HandleObject(Dictionary obj, Node layerNode, TileSet tileset, Vecto
td = gidSource.GetTileData(Vector2I.Zero, 0);
}

// Tile objects could also be classified as instance...
// Tile objects may already have been classified as instance in the tileset
var objIsInstance = godotType == GodotType.Instance && !obj.ContainsKey("template") && !obj.ContainsKey("text");
var tileClass = "";
if (td.HasMeta(ClassInternal))
Expand Down Expand Up @@ -1163,6 +1168,12 @@ private void HandleObject(Dictionary obj, Node layerNode, TileSet tileset, Vecto

return;
}

// Tile objects may already have been classified as ...body in the tileset
if (tileClass != "" && godotType == GodotType.Empty)
godotType = GetGodotType(tileClass);

ConvertMetaDataToObjProperties(td, obj);

var idx = (int)td.GetCustomData(CustomDataInternal);
if (idx > 0)
Expand Down Expand Up @@ -1194,8 +1205,6 @@ private void HandleObject(Dictionary obj, Node layerNode, TileSet tileset, Vecto
}
}

ConvertMetaDataToObjProperties(td, obj);

objSprite.FlipH = flippedH;
objSprite.FlipV = flippedV;

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="1.7.0"
version="1.7.1"
script="TiledImport.cs"
19 changes: 14 additions & 5 deletions CSharp/runtime/TilemapCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -824,13 +824,18 @@ private static void SetSpriteOffset(Sprite2D objSprite, float width, float heigh
};
}

private static void ConvertMetaDataToObjProperties(TileData td, Dictionary obj)
private void ConvertMetaDataToObjProperties(TileData td, Dictionary obj)
{
var metaList = td.GetMetaList();
foreach (var metaName in metaList)
{
if (((string)metaName)?.ToLower() is ClassInternal or GodotNodeTypeProperty)
switch (((string)metaName)?.ToLower())
{
case GodotNodeTypeProperty:
case ClassInternal when !_addClassAsMetadata:
continue;
}

var metaVal = td.GetMeta(metaName);
var metaType = metaVal.VariantType;
var propDict = new Dictionary();
Expand Down Expand Up @@ -1109,7 +1114,7 @@ private void HandleObject(Dictionary obj, Node layerNode, TileSet tileset, Vecto
td = gidSource.GetTileData(Vector2I.Zero, 0);
}

// Tile objects could also be classified as instance...
// Tile objects may already have been classified as instance in the tileset
var objIsInstance = godotType == GodotType.Instance && !obj.ContainsKey("template") && !obj.ContainsKey("text");
var tileClass = "";
if (td.HasMeta(ClassInternal))
Expand Down Expand Up @@ -1161,6 +1166,12 @@ private void HandleObject(Dictionary obj, Node layerNode, TileSet tileset, Vecto

return;
}

// Tile objects may already have been classified as ...body in the tileset
if (tileClass != "" && godotType == GodotType.Empty)
godotType = GetGodotType(tileClass);

ConvertMetaDataToObjProperties(td, obj);

var idx = (int)td.GetCustomData(CustomDataInternal);
if (idx > 0)
Expand Down Expand Up @@ -1192,8 +1203,6 @@ private void HandleObject(Dictionary obj, Node layerNode, TileSet tileset, Vecto
}
}

ConvertMetaDataToObjProperties(td, obj);

objSprite.FlipH = flippedH;
objSprite.FlipV = flippedV;

Expand Down
1 change: 0 additions & 1 deletion CSharp/runtime/XmlParserCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class XmlParserCtrl
private readonly XmlParser _parser = new();
private string _parsedFileName;


public Error Open(string sourceFile)
{
_parsedFileName = sourceFile;
Expand Down
14 changes: 10 additions & 4 deletions GDScript/addons/YATI/TilemapCreator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,9 @@ func set_sprite_offset(obj_sprite: Sprite2D, width: float, height: float, alignm
func convert_metadata_to_obj_properties(td: TileData, obj: Dictionary) -> void:
var meta_list = td.get_meta_list()
for meta_name in meta_list:
if meta_name.to_lower() in [CLASS_INTERNAL, GODOT_NODE_TYPE_PROPERTY]:
if meta_name.to_lower() == GODOT_NODE_TYPE_PROPERTY:
continue
if meta_name.to_lower() == CLASS_INTERNAL and not _add_class_as_metadata:
continue
var meta_val = td.get_meta(meta_name)
var meta_type = typeof(meta_val)
Expand Down Expand Up @@ -913,7 +915,7 @@ func handle_object(obj: Dictionary, layer_node: Node, tileset: TileSet, offset:
obj_sprite.scale = Vector2(scale_x, scale_y)
td = gid_source.get_tile_data(Vector2i.ZERO, 0)

# Tile objects could also be classified as instance...
# Tile objects may already have been classified as instance in the tileset
var obj_is_instance = godot_type == _godot_type.INSTANCE and not obj.has("template") and not obj.has("text")
var tile_class = ""
if td.has_meta(CLASS_INTERNAL):
Expand Down Expand Up @@ -955,6 +957,12 @@ func handle_object(obj: Dictionary, layer_node: Node, tileset: TileSet, offset:
handle_properties(instance, obj["properties"])
return

# Tile objects may already have been classified as ...body in the tileset
if tile_class != "" and godot_type == _godot_type.EMPTY:
godot_type = get_godot_type(tile_class)

convert_metadata_to_obj_properties(td, obj)

var idx = td.get_custom_data(CUSTOM_DATA_INTERNAL)
if idx > 0:
var parent = {
Expand All @@ -979,8 +987,6 @@ func handle_object(obj: Dictionary, layer_node: Node, tileset: TileSet, offset:
if obj.has("properties"):
handle_properties(parent, obj["properties"])

convert_metadata_to_obj_properties(td, obj)

obj_sprite.flip_h = flippedH
obj_sprite.flip_v = flippedV

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 @@ -196,7 +196,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_width() / _tile_size.x
_tile_count = _columns * _current_atlas_source.texture.get_height() / _tile_size.x

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="1.7.0"
version="1.7.1"
script="TiledImport.gd"
14 changes: 10 additions & 4 deletions GDScript/runtime/TilemapCreator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,9 @@ func set_sprite_offset(obj_sprite: Sprite2D, width: float, height: float, alignm
func convert_metadata_to_obj_properties(td: TileData, obj: Dictionary) -> void:
var meta_list = td.get_meta_list()
for meta_name in meta_list:
if meta_name.to_lower() in [CLASS_INTERNAL, GODOT_NODE_TYPE_PROPERTY]:
if meta_name.to_lower() == GODOT_NODE_TYPE_PROPERTY:
continue
if meta_name.to_lower() == CLASS_INTERNAL and not _add_class_as_metadata:
continue
var meta_val = td.get_meta(meta_name)
var meta_type = typeof(meta_val)
Expand Down Expand Up @@ -912,7 +914,7 @@ func handle_object(obj: Dictionary, layer_node: Node, tileset: TileSet, offset:
obj_sprite.scale = Vector2(scale_x, scale_y)
td = gid_source.get_tile_data(Vector2i.ZERO, 0)

# Tile objects could also be classified as instance...
# Tile objects may already have been classified as instance in the tileset
var obj_is_instance = godot_type == _godot_type.INSTANCE and not obj.has("template") and not obj.has("text")
var tile_class = ""
if td.has_meta(CLASS_INTERNAL):
Expand Down Expand Up @@ -954,6 +956,12 @@ func handle_object(obj: Dictionary, layer_node: Node, tileset: TileSet, offset:
handle_properties(instance, obj["properties"])
return

# Tile objects may already have been classified as ...body in the tileset
if tile_class != "" and godot_type == _godot_type.EMPTY:
godot_type = get_godot_type(tile_class)

convert_metadata_to_obj_properties(td, obj)

var idx = td.get_custom_data(CUSTOM_DATA_INTERNAL)
if idx > 0:
var parent = {
Expand All @@ -978,8 +986,6 @@ func handle_object(obj: Dictionary, layer_node: Node, tileset: TileSet, offset:
if obj.has("properties"):
handle_properties(parent, obj["properties"])

convert_metadata_to_obj_properties(td, obj)

obj_sprite.flip_h = flippedH
obj_sprite.flip_v = flippedV

Expand Down
2 changes: 1 addition & 1 deletion GDScript/runtime/TilesetCreator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,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_width() / _tile_size.x
_tile_count = _columns * _current_atlas_source.texture.get_height() / _tile_size.x

register_atlas_source(added_source_id, _tile_count, -1, _tile_offset)
var atlas_grid_size = _current_atlas_source.get_atlas_grid_size()
Expand Down

0 comments on commit 3cc9f94

Please sign in to comment.