From 0904101d808b7955327d90b7edfa082a175eb093 Mon Sep 17 00:00:00 2001 From: "Wilson E. Alvarez" Date: Wed, 13 Sep 2023 14:05:13 -0400 Subject: [PATCH] Replace LibGDX occurrences to GDX. Turns out GDX Texture Packer uses its own atlas format. --- README.md | 6 +- .../gdx_texture_packer_atlas_reader.gd} | 126 ++++++------- .../gdx_texture_packer_import_plugin.gd} | 178 +++++++++--------- .../plugin.cfg | 4 +- .../plugin.gd | 2 +- project.godot | 2 +- 6 files changed, 159 insertions(+), 159 deletions(-) rename addons/{rubonnek.libgdx_texture_packer_atlas_importer/libgdx_texture_packer_atlas_reader.gd => rubonnek.gdx_texture_packer_atlas_importer/gdx_texture_packer_atlas_reader.gd} (87%) rename addons/{rubonnek.libgdx_texture_packer_atlas_importer/libgdx_texture_packer_atlas_editor_import_plugin.gd => rubonnek.gdx_texture_packer_atlas_importer/gdx_texture_packer_import_plugin.gd} (62%) rename addons/{rubonnek.libgdx_texture_packer_atlas_importer => rubonnek.gdx_texture_packer_atlas_importer}/plugin.cfg (61%) rename addons/{rubonnek.libgdx_texture_packer_atlas_importer => rubonnek.gdx_texture_packer_atlas_importer}/plugin.gd (93%) diff --git a/README.md b/README.md index b39905d..1c7564d 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# Godot LibGDX Texture Packer Atlas Importer +# Godot GDX Texture Packer Atlas Importer -LibGDX Texture Packer atlas importer for the [Godot Game Engine](https://godotengine.org/). +GDX Texture Packer atlas importer for the [Godot Game Engine](https://godotengine.org/). ## Installation -[Download](https://github.com/Rubonnek/godot-libgdx-texture-packer-atlas-importer/archive/refs/heads/main.zip) or clone this repository and copy the contents of the +[Download](https://github.com/Rubonnek/godot-gdx-texture-packer-importer/archive/refs/heads/main.zip) or clone this repository and copy the contents of the `addons` folder to your own project's `addons` folder. Then enable the plugin on the Project Settings. diff --git a/addons/rubonnek.libgdx_texture_packer_atlas_importer/libgdx_texture_packer_atlas_reader.gd b/addons/rubonnek.gdx_texture_packer_atlas_importer/gdx_texture_packer_atlas_reader.gd similarity index 87% rename from addons/rubonnek.libgdx_texture_packer_atlas_importer/libgdx_texture_packer_atlas_reader.gd rename to addons/rubonnek.gdx_texture_packer_atlas_importer/gdx_texture_packer_atlas_reader.gd index 688aba8..707029d 100644 --- a/addons/rubonnek.libgdx_texture_packer_atlas_importer/libgdx_texture_packer_atlas_reader.gd +++ b/addons/rubonnek.gdx_texture_packer_atlas_importer/gdx_texture_packer_atlas_reader.gd @@ -30,7 +30,7 @@ var m_detected_atlas_format : int = m_libgdx_atlas_formats.LEGACY var m_whitespace_regex : RegEx = RegEx.new() func _init() -> void: - # Compile the whitespace regex - we are going to use this soon to clean up the LibGDX Texture Packer Atlas text to make it easier to process: + # Compile the whitespace regex - we are going to use this soon to clean up the GDX Texture Packer Atlas text to make it easier to process: var _success : int = m_whitespace_regex.compile("\\s") @@ -44,7 +44,7 @@ func __read_texture_metadata(p_libgdx_atlas_pool_string_array : PoolStringArray, elif m_detected_atlas_format == m_libgdx_atlas_formats.NEW: return __read_new_texture_metadata(p_libgdx_atlas_pool_string_array, p_starting_at_line, r_packed_texture_dictionary) else: - push_error("Unknown atlas format! This should not happen! Unable to parse LibGDX Texture Packer Atlas!") + push_error("Unknown atlas format! This should not happen! Unable to parse GDX Texture Packer Atlas!") r_packed_texture_dictionary["error"] = ERR_PARSE_ERROR return 0 @@ -62,7 +62,7 @@ func __read_legacy_texture_metadata(p_libgdx_atlas_pool_string_array : PoolStrin sample_legacy_texture_metadata += "format: RGBA8888\n" sample_legacy_texture_metadata += "filter: Nearest, Nearest\n" sample_legacy_texture_metadata += "repeat: none\n" - push_error("Malformed atlas header! Check that the LibGDX Texture Packer Atlas file is not corrupted -- the header should have six lines (including a blank line) and look similar to:\n %s" % sample_legacy_texture_metadata) + push_error("Malformed atlas header! Check that the GDX Texture Packer Atlas file is not corrupted -- the header should have six lines (including a blank line) and look similar to:\n %s" % sample_legacy_texture_metadata) r_packed_texture_dictionary["error"] = ERR_PARSE_ERROR return number_of_lines_read @@ -74,7 +74,7 @@ func __read_legacy_texture_metadata(p_libgdx_atlas_pool_string_array : PoolStrin # Properly convert supported types: # NOTE: Here we are only converting the texture size because - # it's the only common setting between LibGDX TexturePacker + # it's the only common setting between GDX TexturePacker # Atlas formats (i.e. the legacy and new formats). if key == "size": var xy_coordinates_pool_string_array : PoolStringArray = value.split(",") @@ -109,7 +109,7 @@ func __read_new_texture_metadata(p_libgdx_atlas_pool_string_array : PoolStringAr # Properly convert supported types: # NOTE: Here we are only converting the texture size because - # it's the only common setting between LibGDX TexturePacker + # it's the only common setting between GDX TexturePacker # Atlas formats (i.e. the legacy and new formats). if key == "size": var xy_coordinates_pool_string_array : PoolStringArray = value.split(",") @@ -132,11 +132,11 @@ func __get_next_atlas_texture_entry(p_libgdx_atlas_pool_string_array : PoolStrin elif m_detected_atlas_format == m_libgdx_atlas_formats.NEW: return __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_pool_string_array, p_source_file, p_starting_at_line, r_packed_texture_dictionary) else: - push_error("Unknown LibGDX TexturePacker Atlas format! This should not happen!") + push_error("Unknown GDX TexturePacker Atlas format! This should not happen!") r_packed_texture_dictionary["error"] = ERR_PARSE_ERROR return 0 -# In order to process the legacy LibGDX TexturePacker Atlas format, we need to know what keys we expect to read under each atlas texture. +# In order to process the legacy GDX TexturePacker Atlas format, we need to know what keys we expect to read under each atlas texture. # This constant is only meant to be used by the function: __get_next_libgdx_atlas_texture_entry_in_new_atlas_format const m_expected_legacy_libgdx_texture_packer_atlas_format_keys : Array = [ "rotate", @@ -161,7 +161,7 @@ func __get_next_libgdx_atlas_texture_entry_in_legacy_atlas_format(p_libgdx_atlas current_line_to_read += 1 # In-scope variables to store the values we are going to return in - # Godot format where possible. Otherwise we'll use raw LibGDX format. + # Godot format where possible. Otherwise we'll use raw GDX format. var libgdx_atlas_texture_rotate : bool = false var libgdx_atlas_texture_position_vector : Vector2 var libgdx_atlas_texture_size_vector : Vector2 @@ -169,7 +169,7 @@ func __get_next_libgdx_atlas_texture_entry_in_legacy_atlas_format(p_libgdx_atlas var libgdx_atlas_texture_offset_vector : Vector2 var libgdx_atlas_texture_index_string : String - # LibGDX TexturePacker atlases also support defining nine patch rects, + # GDX TexturePacker atlases also support defining nine patch rects, # for which we can also generate NinePatchRect nodes in Godot. # These entries only show up when these objects are defined. var libgdx_nine_patch_rect_patch_margin_rect2 : Rect2 @@ -181,7 +181,7 @@ func __get_next_libgdx_atlas_texture_entry_in_legacy_atlas_format(p_libgdx_atlas # make sure we read allpossible entries. var libgdx_atlas_texture_entry_format_lines_to_read : int = 8 # NOTE: The GDX TexturePacker GUI tool at: https://github.com/crashinvaders/gdx-texture-packer-gui - # Outputs each LibGDX atlas texture entry as follows, in the same order when all entries are present: + # Outputs each GDX atlas texture entry as follows, in the same order when all entries are present: # libgdx_atlas_texture_basename # rotate: false # xy: 2, 2 @@ -212,15 +212,15 @@ func __get_next_libgdx_atlas_texture_entry_in_legacy_atlas_format(p_libgdx_atlas # Process texture atlas key-value entry match libgdx_atlas_texture_entry_key: "rotate": - # Process Rotate entry -- if it's not false, we can't process this LibGDX TexturePacker Atlas in Godot + # Process Rotate entry -- if it's not false, we can't process this GDX TexturePacker Atlas in Godot if not "false" in libgdx_atlas_texture_entry_value: # NOTE: It's impossible to tell Godot to rotate the AtlasTextures -- need to bubble up an error if this happens. - push_error("Found rotated texture in LibGDX TexturePacker Atlas file at \"%s\".\nGodot does not support rotated AtlasTexture resources.\nPlease disable texture rotation in your LibGDX TexturePacker project and repack the atlas." % [ p_source_file ]) + push_error("Found rotated texture in GDX TexturePacker Atlas file at \"%s\".\nGodot does not support rotated AtlasTexture resources.\nPlease disable texture rotation in your GDX TexturePacker project and repack the atlas." % [ p_source_file ]) r_packed_texture_dictionary["error"] = ERR_PARSE_ERROR return current_line_to_read - p_starting_at_line "xy": - # Process LibGDX AtlasTexture Position + # Process GDX AtlasTexture Position # NOTE The coordinates of sprite position on atlas are measured as follows: # x: from left to right # y: from top to bottom @@ -231,7 +231,7 @@ func __get_next_libgdx_atlas_texture_entry_in_legacy_atlas_format(p_libgdx_atlas libgdx_atlas_texture_position_vector = Vector2(int(libgdx_atlas_texture_position_x_string), int(libgdx_atlas_texture_position_y_string)) "size": - # Process LibGDX AtlasTexture Size + # Process GDX AtlasTexture Size # NOTE The coordinates of sprite position on atlas are measured as follows: # x: from left to right # y: from top to bottom @@ -244,7 +244,7 @@ func __get_next_libgdx_atlas_texture_entry_in_legacy_atlas_format(p_libgdx_atlas libgdx_atlas_texture_size_vector = Vector2(int(libgdx_atlas_texture_size_x_string), int(libgdx_atlas_texture_size_y_string)) "split": - # Process LibGDX NinePatchRect Patch Margin + # Process GDX NinePatchRect Patch Margin # In the following entry: # split: 1, 2, 4, 3 # the numbers represent the following: @@ -261,7 +261,7 @@ func __get_next_libgdx_atlas_texture_entry_in_legacy_atlas_format(p_libgdx_atlas libgdx_nine_patch_rect_patch_margin_rect2 = Rect2(libgdx_patch_margin_left, libgdx_patch_margin_right, libgdx_patch_margin_top, libgdx_patch_margin_bottom) "pad": - # Process LibGDX NinePatchRect Content Margin + # Process GDX NinePatchRect Content Margin # In entry: # pad: 1, 2, 4, 3 # the numbers represent the following: @@ -278,14 +278,14 @@ func __get_next_libgdx_atlas_texture_entry_in_legacy_atlas_format(p_libgdx_atlas libgdx_nine_patch_rect_rect_region_rect2 = Rect2(libgdx_rect_region_left, libgdx_rect_region_right, libgdx_rect_region_top, libgdx_rect_region_bottom) "orig": - # LibGDX AtlasTexture Original Size + # GDX AtlasTexture Original Size var libgdx_atlas_texture_original_size_array : Array = libgdx_atlas_texture_entry_value.split(",") var libgdx_atlas_texture_original_size_x_string : String = libgdx_atlas_texture_original_size_array[0] var libgdx_atlas_texture_original_size_y_string : String = libgdx_atlas_texture_original_size_array[1] libgdx_atlas_texture_original_size_vector = Vector2(int(libgdx_atlas_texture_original_size_x_string), int(libgdx_atlas_texture_original_size_y_string)) "offset": - # LibGDX AtlasTexture Offset + # GDX AtlasTexture Offset # NOTE The coordinates of the sprite offset based from the original image are measured as follows: # x: from left to right # y: from bottom to top @@ -296,7 +296,7 @@ func __get_next_libgdx_atlas_texture_entry_in_legacy_atlas_format(p_libgdx_atlas libgdx_atlas_texture_offset_vector = Vector2(int(libgdx_atlas_texture_offset_x_string), int(libgdx_atlas_texture_offset_y_string)) "index": - # LibGDX AtlasTexture Index + # GDX AtlasTexture Index # NOTE: When a set of sprite filenames such as "run_0.png", # "run_1.png", "run_2.png" are included in an atlas, the sprite frame # numbers 0, 1, and 2 respectively ends up as the index entry in the @@ -304,11 +304,11 @@ func __get_next_libgdx_atlas_texture_entry_in_legacy_atlas_format(p_libgdx_atlas libgdx_atlas_texture_index_string = libgdx_atlas_texture_entry_value _: - push_error("Found unknown LibGDX TexturePacker Atlas texture entry key : \"%s\" in file \"%s\" at line %d" % [ libgdx_atlas_texture_entry_key, p_source_file, current_line_to_read - 1 ]) + push_error("Found unknown GDX TexturePacker Atlas texture entry key : \"%s\" in file \"%s\" at line %d" % [ libgdx_atlas_texture_entry_key, p_source_file, current_line_to_read - 1 ]) r_packed_texture_dictionary["error"] = ERR_PARSE_ERROR return current_line_to_read - p_starting_at_line - # Construct LibGDX atlas texture entry dictionary found in the atlas -- + # Construct GDX atlas texture entry dictionary found in the atlas -- # this is all the information that's required to construct a Godot # AtlasTexture resource. var atlas_texture_entry_dictionary : Dictionary = { @@ -332,7 +332,7 @@ func __get_next_libgdx_atlas_texture_entry_in_legacy_atlas_format(p_libgdx_atlas which_key_was_seen = "split" else: which_key_was_seen = "pad" - var error_message : String = "Malformed LibGDX TexturePacker Atlas\n" + var error_message : String = "Malformed GDX TexturePacker Atlas\n" error_message += "Expected to see both \"split\" and \"pad\" entries defined in: %s\n" % [ p_source_file ] error_message += "But only saw the \"%s\" key at around line %d" % [ which_key_was_seen, current_line_to_read - 1] push_error(error_message) @@ -347,7 +347,7 @@ func __get_next_libgdx_atlas_texture_entry_in_legacy_atlas_format(p_libgdx_atlas return current_line_to_read - p_starting_at_line -# In order to process the new LibGDX TexturePacker Atlas format, we need to know what keys we expect to read under each atlas texture. +# In order to process the new GDX TexturePacker Atlas format, we need to know what keys we expect to read under each atlas texture. # This constant is only meant to be used by the function: __get_next_libgdx_atlas_texture_entry_in_new_atlas_format const m_expected_new_libgdx_texture_packer_atlas_format_keys : Array = [ "index", @@ -388,10 +388,10 @@ func __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_po current_line_to_read += 1 # Debug - #print("Processing LibGDX texture: ", libgdx_atlas_texture_basename) + #print("Processing GDX texture: ", libgdx_atlas_texture_basename) # In-scope variables to store the values we are going to return in - # Godot format where possible. Otherwise we'll use raw LibGDX format. + # Godot format where possible. Otherwise we'll use raw GDX format. var libgdx_atlas_texture_rotate : bool = false var libgdx_atlas_texture_position_vector : Vector2 var libgdx_atlas_texture_size_vector : Vector2 @@ -399,7 +399,7 @@ func __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_po var libgdx_atlas_texture_offset_vector : Vector2 var libgdx_atlas_texture_index_string : String = "-1" # this is the default in the legacy format and it means there are no other atlas textures with similar names - # LibGDX TexturePacker atlases also support defining nine patch rects, + # GDX TexturePacker atlases also support defining nine patch rects, # for which we can also generate NinePatchRect nodes in Godot. # These entries only show up when these objects are defined. var libgdx_nine_patch_rect_patch_margin_rect2 : Rect2 @@ -411,13 +411,13 @@ func __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_po var libgdx_atlas_texture_entry_format_lines_to_read : int = 6 # NOTE: We use the following PoolStringArray and Dictionary for sanity checking later on # NOTE: The was_bounds_key_seen variable below is only used to make - # sure we've at least read what we need from the new LibGDX + # sure we've at least read what we need from the new GDX # TexturePacker format in order to create the AtlasTexture resource in # Godot. var was_bounds_key_seen : bool = false # NOTE: The was_offsets_key_seen variable below is used to make sure we # know what the original texture size is (i.e. what the 'orig' entry is - # in the legacy LibGDX TexturePacker Atlas format). If the 'offsets' key is not seen + # in the legacy GDX TexturePacker Atlas format). If the 'offsets' key is not seen # within the new format, then that means the original texture size is # the same as what appears in the 'bounds' key. var was_offsets_key_seen : bool = false @@ -426,8 +426,8 @@ func __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_po # If we reach eof, we've reached the end of the file and that's completely fine. if libgdx_texture_packer_atlas_texture_entry_line > p_libgdx_atlas_pool_string_array.size() - 1: if not was_bounds_key_seen: - # We didn't read the necessary key -- we got to EOF before we could read it. This means this LibGDX atlas file is malformed. - push_error("Malformed LibGDX atlas found at \"%s\".\nReached end of file before the 'bounds' key was read for the atlas texture with basename \"%s\"\n" % [ p_source_file, libgdx_atlas_texture_basename ]) + # We didn't read the necessary key -- we got to EOF before we could read it. This means this GDX atlas file is malformed. + push_error("Malformed GDX atlas found at \"%s\".\nReached end of file before the 'bounds' key was read for the atlas texture with basename \"%s\"\n" % [ p_source_file, libgdx_atlas_texture_basename ]) r_packed_texture_dictionary["error"] = ERR_PARSE_ERROR return current_line_to_read - p_starting_at_line break @@ -441,8 +441,8 @@ func __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_po if was_bounds_key_seen: break else: - # We didn't read the necessary key -- this LibGDX atlas file is malformed. - push_error("Malformed LibGDX atlas found at \"%s\".\nCould not find 'bounds' key around line %d for atlas texture with basename \"%s\"" % [ p_source_file, current_line_to_read, libgdx_atlas_texture_basename ]) + # We didn't read the necessary key -- this GDX atlas file is malformed. + push_error("Malformed GDX atlas found at \"%s\".\nCould not find 'bounds' key around line %d for atlas texture with basename \"%s\"" % [ p_source_file, current_line_to_read, libgdx_atlas_texture_basename ]) r_packed_texture_dictionary["error"] = ERR_PARSE_ERROR return current_line_to_read - p_starting_at_line @@ -455,7 +455,7 @@ func __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_po # Process atlas entry match libgdx_atlas_texture_entry_key: "index": - # LibGDX AtlasTexture Index + # GDX AtlasTexture Index # NOTE: When a set of sprite filenames such as "run_0.png", # "run_1.png", "run_2.png" are included in an atlas, the sprite frame # numbers 0, 1, and 2 respectively ends up as the index entry in the @@ -463,10 +463,10 @@ func __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_po libgdx_atlas_texture_index_string = libgdx_atlas_texture_entry_value "bounds": - # The bounds include the LibGDX AtlasTexture Position and the LibGDX AtlasTexture Size + # The bounds include the GDX AtlasTexture Position and the GDX AtlasTexture Size was_bounds_key_seen = true - # LibGDX AtlasTexture Position + # GDX AtlasTexture Position # NOTE The coordinates of sprite position on atlas are measured as follows: # x: from left to right # y: from top to bottom @@ -476,7 +476,7 @@ func __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_po var libgdx_atlas_texture_position_y_string : String = libgdx_atlas_texture_bounds_array[1] libgdx_atlas_texture_position_vector = Vector2(int(libgdx_atlas_texture_position_x_string), int(libgdx_atlas_texture_position_y_string)) - # LibGDX AtlasTexture Size + # GDX AtlasTexture Size # NOTE The coordinates of sprite position on atlas are measured as follows: # x: from left to right # y: from top to bottom @@ -488,8 +488,8 @@ func __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_po libgdx_atlas_texture_size_vector = Vector2(int(libgdx_atlas_texture_size_x_string), int(libgdx_atlas_texture_size_y_string)) "split": - # Process LibGDX NinePatchRect Patch Margin - # On the following LibGDX Texture Packer atlas entry: + # Process GDX NinePatchRect Patch Margin + # On the following GDX Texture Packer atlas entry: # split: 1, 2, 4, 3 # the numbers represent the following: # 1 represents the nine patch rect margin from the left @@ -505,8 +505,8 @@ func __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_po libgdx_nine_patch_rect_patch_margin_rect2 = Rect2(libgdx_patch_margin_left, libgdx_patch_margin_right, libgdx_patch_margin_top, libgdx_patch_margin_bottom) "pad": - # Process LibGDX NinePatchRect Content Margin - # On the following LibGDX Texture Packer atlas entry: + # Process GDX NinePatchRect Content Margin + # On the following GDX Texture Packer atlas entry: # pad: 1, 2, 4, 3 # the numbers represent the following: # 1 represents the content margin from the left @@ -528,7 +528,7 @@ func __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_po # 2) the sprite original size. was_offsets_key_seen = true - # LibGDX AtlasTexture Offset + # GDX AtlasTexture Offset # NOTE The coordinates of the sprite offset based from the original image are measured as follows: # x: from left to right # y: from bottom to top @@ -538,27 +538,27 @@ func __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_po var libgdx_atlas_texture_offset_y_string : String = libgdx_atlas_texture_offsets_array[1] libgdx_atlas_texture_offset_vector = Vector2(int(libgdx_atlas_texture_offset_x_string), int(libgdx_atlas_texture_offset_y_string)) - # LibGDX AtlasTexture Original Size + # GDX AtlasTexture Original Size var libgdx_atlas_texture_original_size_x_string : String = libgdx_atlas_texture_offsets_array[2] var libgdx_atlas_texture_original_size_y_string : String = libgdx_atlas_texture_offsets_array[3] libgdx_atlas_texture_original_size_vector = Vector2(int(libgdx_atlas_texture_original_size_x_string), int(libgdx_atlas_texture_original_size_y_string)) "rotate": # NOTE: It's impossible to tell Godot to rotate the AtlasTextures -- need to bubble up an error if this happens. - push_error("Found rotated texture in LibGDX TexturePacker Atlas file at \"%s\".\nGodot does not support rotated AtlasTexture resources.\nPlease disable sprites rotation in your LibGDX TexturePacker project and repack the atlas." % [ p_source_file ]) + push_error("Found rotated texture in GDX TexturePacker Atlas file at \"%s\".\nGodot does not support rotated AtlasTexture resources.\nPlease disable sprites rotation in your GDX TexturePacker project and repack the atlas." % [ p_source_file ]) r_packed_texture_dictionary["error"] = ERR_PARSE_ERROR return current_line_to_read - p_starting_at_line _: - push_error("Found unknown LibGDX TexturePacker Atlas texture entry key : \"%s\" in file \"%s\" at line %d" % [ libgdx_atlas_texture_entry_key, p_source_file, current_line_to_read - 1 ]) + push_error("Found unknown GDX TexturePacker Atlas texture entry key : \"%s\" in file \"%s\" at line %d" % [ libgdx_atlas_texture_entry_key, p_source_file, current_line_to_read - 1 ]) r_packed_texture_dictionary["error"] = ERR_PARSE_ERROR return current_line_to_read - p_starting_at_line if not was_offsets_key_seen: - # Need to set the original size vector for the atlas texture which is implicitly given in the new LibGDX TexturePacker Atlas format + # Need to set the original size vector for the atlas texture which is implicitly given in the new GDX TexturePacker Atlas format libgdx_atlas_texture_original_size_vector = libgdx_atlas_texture_size_vector - # Construct LibGDX atlas texture entry dictionary found in the atlas -- + # Construct GDX atlas texture entry dictionary found in the atlas -- # this is all the information that's required to construct a Godot # AtlasTexture resource. var atlas_texture_entry_dictionary : Dictionary = { @@ -583,7 +583,7 @@ func __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_po which_key_was_seen = "split" else: which_key_was_seen = "pad" - var error_message : String = "Malformed LibGDX TexturePacker Atlas\n" + var error_message : String = "Malformed GDX TexturePacker Atlas\n" error_message += "Expected to see both \"split\" and \"pad\" entries defined in: %s\n" % [ p_source_file ] error_message += "But only saw the \"%s\" key at around line %d" % [ which_key_was_seen, current_line_to_read - 1] push_error(error_message) @@ -591,7 +591,7 @@ func __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_po return current_line_to_read - p_starting_at_line # Debug - #print("LibGDX TexturePacker AtlasTexture Dictionary: ", atlas_texture_entry_dictionary) + #print("GDX TexturePacker AtlasTexture Dictionary: ", atlas_texture_entry_dictionary) # Push the atlas_texture_entry_dictionary into r_packed_texture_dictionary r_packed_texture_dictionary["atlas_textures"].push_back(atlas_texture_entry_dictionary) @@ -601,16 +601,16 @@ func __get_next_libgdx_atlas_texture_entry_in_new_atlas_format(p_libgdx_atlas_po return current_line_to_read - p_starting_at_line -# Returns a Godot Dictionary that represents a parsed LibGDX Texture Packer Atlas wrapped within a parse result dictionary. +# Returns a Godot Dictionary that represents a parsed GDX Texture Packer Atlas wrapped within a parse result dictionary. func parse(p_source_file : String) -> Dictionary: - # LibGDXTexturePackerAtlasParseResult mimics JSONParseResult but through a Dictionary object instead - # NOTE: We don't use a class_name for LibGDXTexturePackerAtlasParseResult class just to avoid declaring global classes unnecessarily since it is known to slow down the Editor on complex projects. + # GDXTexturePackerAtlasParseResult mimics JSONParseResult but through a Dictionary object instead + # NOTE: We don't use a class_name for GDXTexturePackerAtlasParseResult class just to avoid declaring global classes unnecessarily since it is known to slow down the Editor on complex projects. var libgdx_texture_packer_atlas_parse_result : Dictionary = { "error" : OK, "result" : {}, } - # Open the LibGDX Texture Packer Atlas file + # Open the GDX Texture Packer Atlas file var file_handle : File = File.new() var error : int = file_handle.open(p_source_file, File.READ) if error != OK: @@ -619,11 +619,11 @@ func parse(p_source_file : String) -> Dictionary: libgdx_texture_packer_atlas_parse_result["error"] = error return libgdx_texture_packer_atlas_parse_result - # Slurp the LibGDX Texture Packer Atlas file into memory. + # Slurp the GDX Texture Packer Atlas file into memory. var libgdx_atlas_pool_string_array : PoolStringArray = file_handle.get_as_text().split("\n") libgdx_atlas_pool_string_array.resize(libgdx_atlas_pool_string_array.size() - 1) # the last entry is an empty string - # Close the LibGDX Texture Packer Atlas file handle -- it's not needed anymore + # Close the GDX Texture Packer Atlas file handle -- it's not needed anymore file_handle.close() # Remove the whitespace out of all the lines. Even if the @@ -634,14 +634,14 @@ func parse(p_source_file : String) -> Dictionary: # Debug #print(libgdx_atlas_pool_string_array) - # Detect whether the LibGDX Texture Packer Atlas file is using the legacy format or the new format: + # Detect whether the GDX Texture Packer Atlas file is using the legacy format or the new format: # NOTE: In the legacy format the data structures are more granular. # The new format is more concise and compact. Both formats contain the # same information, just in different places. Since the legacy format # seems easier to read in my opinion, the # parsed_libgdx_texture_packer_atlas_dictionary will contain entries - # using the legacy format regardless of the LibGDX Texture Packer Atlas format. - # NOTE: Since we are going to parse the LibGDX Texture Packer Atlas line by line, we need + # using the legacy format regardless of the GDX Texture Packer Atlas format. + # NOTE: Since we are going to parse the GDX Texture Packer Atlas line by line, we need # to keep track of the line index we are reading manually var line_index : int = 0 if libgdx_atlas_pool_string_array[0] == "": @@ -650,13 +650,13 @@ func parse(p_source_file : String) -> Dictionary: else: m_detected_atlas_format = m_libgdx_atlas_formats.NEW - # From now on, we'll have to keep track of the parsed LibGDX Texture Packer Atlas + # From now on, we'll have to keep track of the parsed GDX Texture Packer Atlas var parsed_libgdx_texture_packer_atlas_dictionary : Dictionary = { "path" : p_source_file, "packed_textures" : [], } - # NOTE: The LibGDX Texture Packer Atlas format supports multi-page texture atlases within the GDX Texture Packer Atlas file (i.e. the .atlas file). + # NOTE: The GDX Texture Packer Atlas format supports multi-page texture atlases within the GDX Texture Packer Atlas file (i.e. the .atlas file). # Here's a sample of the legacy format which includes multi-page atlases: # # atlas1.png @@ -754,7 +754,7 @@ func parse(p_source_file : String) -> Dictionary: # ] # } - # Let's parse the LibGDX Texture Packer Atlas line by line. + # Let's parse the GDX Texture Packer Atlas line by line. # NOTE: Need to track packed texture dictionaries outside of the scope # below because we will need to update this dictionary across the whole # loop once we stumble upon a new packed texture page we need to @@ -809,13 +809,13 @@ func parse(p_source_file : String) -> Dictionary: # And exit out of the loop break - # If we stumble upon a new line while reading the current atlas textures, this means we are about to start reading data about a new LibGDX packed texture -- including its settings and its atlas textures. + # If we stumble upon a new line while reading the current atlas textures, this means we are about to start reading data about a new GDX packed texture -- including its settings and its atlas textures. # Toggle the reader state back to READING_TEXTURE_HEADER to process the data accordingly if libgdx_atlas_pool_string_array[line_index] == "": # Save the current packed texture dictionary -- we are done reading it parsed_libgdx_texture_packer_atlas_dictionary["packed_textures"].push_back(current_libgdx_packed_texture_dictionary) - # Create a new dictionary and attach it to the current_libgdx_packed_texture_dictionary since we are about to read a new LibGDX Texture Packer Atlas page + # Create a new dictionary and attach it to the current_libgdx_packed_texture_dictionary since we are about to read a new GDX Texture Packer Atlas page current_libgdx_packed_texture_dictionary = { "atlas_textures" : [], "settings" : {}, @@ -828,7 +828,7 @@ func parse(p_source_file : String) -> Dictionary: m_reader_state = m_atlas_reader_states.READING_TEXTURE_HEADER # Debug - #print("Parsed LibGDX Texture Packer Atlas dictionary: ", parsed_libgdx_texture_packer_atlas_dictionary) + #print("Parsed GDX Texture Packer Atlas dictionary: ", parsed_libgdx_texture_packer_atlas_dictionary) # Attach the parsed_libgdx_texture_packer_atlas_dictionary to the parse result: libgdx_texture_packer_atlas_parse_result["result"] = parsed_libgdx_texture_packer_atlas_dictionary diff --git a/addons/rubonnek.libgdx_texture_packer_atlas_importer/libgdx_texture_packer_atlas_editor_import_plugin.gd b/addons/rubonnek.gdx_texture_packer_atlas_importer/gdx_texture_packer_import_plugin.gd similarity index 62% rename from addons/rubonnek.libgdx_texture_packer_atlas_importer/libgdx_texture_packer_atlas_editor_import_plugin.gd rename to addons/rubonnek.gdx_texture_packer_atlas_importer/gdx_texture_packer_import_plugin.gd index c665e52..f942cbc 100644 --- a/addons/rubonnek.libgdx_texture_packer_atlas_importer/libgdx_texture_packer_atlas_editor_import_plugin.gd +++ b/addons/rubonnek.gdx_texture_packer_atlas_importer/gdx_texture_packer_import_plugin.gd @@ -28,12 +28,12 @@ extends EditorImportPlugin # Unique name for the import plugin to let Godot know which import was used func get_importer_name() -> String: - return "rubonnek.libgdx_texture_packer_atlas_importer" + return "rubonnek.gdx_texture_packer_atlas_importer" # Returns the name of the type it imports and it will be shown to the user in the Import dock. func get_visible_name() -> String: - return "LibGDX Atlas" + return "GDX Atlas" # Godot's import system detects file types by their extension. In the @@ -104,7 +104,7 @@ func get_option_visibility(_p_option : String, _p_options : Dictionary) -> bool: return true -# Tweak the import order just so the LibGDX atlas does not get imported before +# Tweak the import order just so the GDX atlas does not get imported before # the texture it depends on. func get_import_order() -> int: # Import the atlas before the scenes @@ -121,22 +121,22 @@ func import(p_source_file : String, p_save_path : String, _p_options : Dictionar # print("Options: " + str(p_options)) # Load the atlas reader: - var libgdx_texture_packer_atlas_reader_gdscript : GDScript = load(get_script().get_path().get_base_dir().plus_file("libgdx_texture_packer_atlas_reader.gd")) - var libgdx_atlas_reader = libgdx_texture_packer_atlas_reader_gdscript.new() + var gdx_texture_packer_atlas_reader_gdscript : GDScript = load(get_script().get_path().get_base_dir().plus_file("gdx_texture_packer_atlas_reader.gd")) + var gdx_atlas_reader = gdx_texture_packer_atlas_reader_gdscript.new() - # If there was an error parsing the LibGDX TexturePacker Atlas, inform the Editor - var libgdx_parse_result : Dictionary = libgdx_atlas_reader.parse(p_source_file) - var error : int = libgdx_parse_result["error"] + # If there was an error parsing the GDX TexturePacker Atlas, inform the Editor + var gdx_parse_result : Dictionary = gdx_atlas_reader.parse(p_source_file) + var error : int = gdx_parse_result["error"] if error != OK: # NOTE: No need to print the error since it was done already. Only need to bubble up the error code to the Editor. return error # There was no error. Grab the result: - var libgdx_atlas_data_dictionary : Dictionary = libgdx_parse_result["result"] + var gdx_atlas_data_dictionary : Dictionary = gdx_parse_result["result"] # Grab the base directory: - var libgdx_atlas_path : String = libgdx_atlas_data_dictionary["path"] # same as p_source_file in the current scope - var atlas_texture_resources_directory : String = libgdx_atlas_path.trim_suffix("." + libgdx_atlas_path.get_extension()) + ".atlas_textures" + var gdx_atlas_path : String = gdx_atlas_data_dictionary["path"] # same as p_source_file in the current scope + var atlas_texture_resources_directory : String = gdx_atlas_path.trim_suffix("." + gdx_atlas_path.get_extension()) + ".atlas_textures" # Make atlas_basename.atlas_textures folder to store all the AtlasTexture resources there. Clean up old directories if any. var directory : Directory = Directory.new() # Debug @@ -144,93 +144,93 @@ func import(p_source_file : String, p_save_path : String, _p_options : Dictionar # __remove_directory_recursively(atlas_texture_resources_directory) if not directory.dir_exists(atlas_texture_resources_directory): if directory.make_dir(atlas_texture_resources_directory) != OK: - __push_error("Can't create AtlasTextures root directory: %s\n\tUnable to continue importing LibGDX Atlas." % [ atlas_texture_resources_directory ]) + __push_error("Can't create AtlasTextures root directory: %s\n\tUnable to continue importing GDX Atlas." % [ atlas_texture_resources_directory ]) return ERR_CANT_CREATE - # The LibGDX TexturePacker Atlas format also supports describing nine + # The GDX TexturePacker Atlas format also supports describing nine # patch rectangles which directly translate to a NinePatchRect node in # Godot. We'll create these scene in a separate folder for organization's sake. - var nine_patch_rect_scenes_directory : String = libgdx_atlas_path.trim_suffix("." + libgdx_atlas_path.get_extension()) + ".nine_patch_rects" + var nine_patch_rect_scenes_directory : String = gdx_atlas_path.trim_suffix("." + gdx_atlas_path.get_extension()) + ".nine_patch_rects" # Debug #if directory.dir_exists(nine_patch_rect_scenes_directory): # __remove_directory_recursively(nine_patch_rect_scenes_directory) var is_a_nine_patch_rect_defined : bool = false - for packed_texture_dictionary in libgdx_atlas_data_dictionary["packed_textures"]: - for libgdx_atlas_texture_dictionary in packed_texture_dictionary["atlas_textures"]: - if "split" in libgdx_atlas_texture_dictionary: + for packed_texture_dictionary in gdx_atlas_data_dictionary["packed_textures"]: + for gdx_atlas_texture_dictionary in packed_texture_dictionary["atlas_textures"]: + if "split" in gdx_atlas_texture_dictionary: is_a_nine_patch_rect_defined = true if is_a_nine_patch_rect_defined: if not directory.dir_exists(nine_patch_rect_scenes_directory): if directory.make_dir(nine_patch_rect_scenes_directory) != OK: - __push_error("Can't create NinePatchRects root directory: %s\n\tUnable to continue importing LibGDX Atlas." % [ nine_patch_rect_scenes_directory ]) + __push_error("Can't create NinePatchRects root directory: %s\n\tUnable to continue importing GDX Atlas." % [ nine_patch_rect_scenes_directory ]) return ERR_CANT_CREATE # For each packed texture found within the GDX Atlas - var libgdx_atlas_base_directory : String = libgdx_atlas_path.get_base_dir() - for packed_texture_dictionary in libgdx_atlas_data_dictionary["packed_textures"]: + var gdx_atlas_base_directory : String = gdx_atlas_path.get_base_dir() + for packed_texture_dictionary in gdx_atlas_data_dictionary["packed_textures"]: # Grab the packed texture filename var packed_texture_filename : String = packed_texture_dictionary["filename"] # Generate the path of the packed texture relative to the GDX Atlas path - var packed_texture_path : String = libgdx_atlas_base_directory.plus_file(packed_texture_filename) - var libgdx_packed_texture_stream_texture : StreamTexture = load(packed_texture_path) - if not is_instance_valid(libgdx_packed_texture_stream_texture): + var packed_texture_path : String = gdx_atlas_base_directory.plus_file(packed_texture_filename) + var gdx_packed_texture_stream_texture : StreamTexture = load(packed_texture_path) + if not is_instance_valid(gdx_packed_texture_stream_texture): var error_message : String = "Unable to load texture atlas at: %s\n" % [ packed_texture_path ] - error_message += "Image was referenced by LibGDX TexturePacker Atlas file at: %s\n" % [ libgdx_atlas_path ] + error_message += "Image was referenced by GDX TexturePacker Atlas file at: %s\n" % [ gdx_atlas_path ] __push_error(error_message) return ERR_CANT_OPEN # Make sure that the texture size matches what we've read from disk: # NOTE: The texture size is the only common metadata between - # LibGDX TexturePacker Atlas formats (i.e. between the legacy - # and new LibGDX TexturePacker Atlas formats). - var libgdx_packed_texture_size : Vector2 = libgdx_packed_texture_stream_texture.get_size() - if libgdx_packed_texture_size != packed_texture_dictionary["settings"]["size"]: - var error_message : String = "Incorrect texture size found in LibGDX TexturePacker Atlas!\n" - error_message += "Make sure that the texture in the LibGDX TexturePacker Atlas at: %s\n" % [ p_source_file ] + # GDX TexturePacker Atlas formats (i.e. between the legacy + # and new GDX TexturePacker Atlas formats). + var gdx_packed_texture_size : Vector2 = gdx_packed_texture_stream_texture.get_size() + if gdx_packed_texture_size != packed_texture_dictionary["settings"]["size"]: + var error_message : String = "Incorrect texture size found in GDX TexturePacker Atlas!\n" + error_message += "Make sure that the texture in the GDX TexturePacker Atlas at: %s\n" % [ p_source_file ] error_message += "match the loaded texture at: %s" % [ packed_texture_path ] __push_error(error_message) return ERR_CANT_ACQUIRE_RESOURCE # Convert GDX atlas texture entries within the packed texture dictionary into Godot's AtlasTexture resources: - for libgdx_atlas_texture_dictionary in packed_texture_dictionary["atlas_textures"]: + for gdx_atlas_texture_dictionary in packed_texture_dictionary["atlas_textures"]: # Create the AtlasTexture resource: var atlas_texture_resource : AtlasTexture = AtlasTexture.new() # Set the atlas texture in the resource: - atlas_texture_resource.set_atlas(libgdx_packed_texture_stream_texture) + atlas_texture_resource.set_atlas(gdx_packed_texture_stream_texture) # Set the atlas texture resource region: - var libgdx_texture_position : Vector2 = libgdx_atlas_texture_dictionary["xy"] - var libgdx_texture_size : Vector2 = libgdx_atlas_texture_dictionary["size"] - atlas_texture_resource.set_region(Rect2(libgdx_texture_position, libgdx_texture_size)) + var gdx_texture_position : Vector2 = gdx_atlas_texture_dictionary["xy"] + var gdx_texture_size : Vector2 = gdx_atlas_texture_dictionary["size"] + atlas_texture_resource.set_region(Rect2(gdx_texture_position, gdx_texture_size)) # Set the margin: - # NOTE: The coordinate system over the y axis within the LibGDX atlas + # NOTE: The coordinate system over the y axis within the GDX atlas # changes for the texture offset and the original size -- that's the # reason for flipping the y axis when setting the margin below, just so # it conforms to Godot's coordinate system: - var libgdx_texture_offset : Vector2 = libgdx_atlas_texture_dictionary["offset"] - var libgdx_texture_original_size : Vector2 = libgdx_atlas_texture_dictionary["orig"] + var gdx_texture_offset : Vector2 = gdx_atlas_texture_dictionary["offset"] + var gdx_texture_original_size : Vector2 = gdx_atlas_texture_dictionary["orig"] # NOTE: the texture offset denotes left-to-right and bottom-to-top offset, # basically denoting the bottom_left edge of the rectangle for the sprite. # The bottom_right_edge is undefined, but can be calculated: - var bottom_right_edge : Vector2 = libgdx_texture_original_size - libgdx_texture_size + var bottom_right_edge : Vector2 = gdx_texture_original_size - gdx_texture_size # Debug #print("Bottom Right Edge margin: " + str(bottom_right_edge)) - # NOTE: Since the LibGDX texture offset y coordinate is considered to + # NOTE: Since the GDX texture offset y coordinate is considered to # be flipped in Godot's coordinate system (since the the y axis in - # LibGDX is measured from bottom_to_top when calculating the offset, + # GDX is measured from bottom_to_top when calculating the offset, # whereas Godot measures it from top_to_bottom), every pixel added over # the y axis on the bottom_right_edge corner in Godot must be - # substracted from the LibGDX texture offset y axis. Otherwise the + # substracted from the GDX texture offset y axis. Otherwise the # sprite offset location will be off over the y axis. In other words, # the bottom_right_edge corner in Godot's coordinate system fills the # image from the right and bottom. The bottom fill minus the y offset - # as determined by LibGDX, is what we need to calculate the image + # as determined by GDX, is what we need to calculate the image # offset in Godot's coordinate system. - var texture_margin : Rect2 = Rect2(libgdx_texture_offset.x, bottom_right_edge.y - libgdx_texture_offset.y, bottom_right_edge.x, bottom_right_edge.y) + var texture_margin : Rect2 = Rect2(gdx_texture_offset.x, bottom_right_edge.y - gdx_texture_offset.y, bottom_right_edge.x, bottom_right_edge.y) # Debug #print("Texture margin: " + str(texture_margin)) @@ -239,17 +239,17 @@ func import(p_source_file : String, p_save_path : String, _p_options : Dictionar # Generate new resource var atlas_texture_resource_path_format = "%s/%s.%s" var atlas_texture_resource_name : String - if libgdx_atlas_texture_dictionary["index"] != "-1": - atlas_texture_resource_name = "%s_%s" % [ libgdx_atlas_texture_dictionary["basename"], libgdx_atlas_texture_dictionary["index"] ] + if gdx_atlas_texture_dictionary["index"] != "-1": + atlas_texture_resource_name = "%s_%s" % [ gdx_atlas_texture_dictionary["basename"], gdx_atlas_texture_dictionary["index"] ] else: - atlas_texture_resource_name = libgdx_atlas_texture_dictionary["basename"] + atlas_texture_resource_name = gdx_atlas_texture_dictionary["basename"] - # The LibGDX TexturePacker format may include relative paths for which we may have to create directories for, thus we handle those here. + # The GDX TexturePacker format may include relative paths for which we may have to create directories for, thus we handle those here. if "/" in atlas_texture_resource_name: var path_to_folder_to_create : String = atlas_texture_resources_directory.plus_file(atlas_texture_resource_name.get_base_dir()) if not directory.dir_exists(path_to_folder_to_create): if directory.make_dir_recursive(path_to_folder_to_create) != OK: - __push_error("Can't create directory: %s\n\tUnable to continue importing LibGDX Atlas." % [ path_to_folder_to_create ]) + __push_error("Can't create directory: %s\n\tUnable to continue importing GDX Atlas." % [ path_to_folder_to_create ]) return ERR_CANT_CREATE var atlas_texture_resource_save_path : String = atlas_texture_resource_path_format % [atlas_texture_resources_directory, atlas_texture_resource_name, get_save_extension()] @@ -263,7 +263,7 @@ func import(p_source_file : String, p_save_path : String, _p_options : Dictionar r_gen_files.push_back(atlas_texture_resource_save_path) # We are done processing the AtlasTexture, but there's a chance the user defined a nine patch rectangle for it which we can translate into a Godot NinePatchRect node. - if "split" in libgdx_atlas_texture_dictionary: + if "split" in gdx_atlas_texture_dictionary: # A nine patch rectangle has been defined. Let's create the node. var godot_nine_patch_rect : NinePatchRect = NinePatchRect.new() @@ -275,59 +275,59 @@ func import(p_source_file : String, p_save_path : String, _p_options : Dictionar # Set the new AtlasTexture Content Margin - var libgdx_nine_patch_content_margin_rect2 : Rect2 = libgdx_atlas_texture_dictionary["pad"] - var libgdx_left_content_margin_padding : int = int(libgdx_nine_patch_content_margin_rect2.position.x) - var libgdx_right_content_margin_padding : int = int(libgdx_nine_patch_content_margin_rect2.position.y) - var libgdx_bottom_content_margin_padding : int = int(libgdx_nine_patch_content_margin_rect2.size.y) - var libgdx_top_content_margin_padding : int = int(libgdx_nine_patch_content_margin_rect2.size.x) + var gdx_nine_patch_content_margin_rect2 : Rect2 = gdx_atlas_texture_dictionary["pad"] + var gdx_left_content_margin_padding : int = int(gdx_nine_patch_content_margin_rect2.position.x) + var gdx_right_content_margin_padding : int = int(gdx_nine_patch_content_margin_rect2.position.y) + var gdx_bottom_content_margin_padding : int = int(gdx_nine_patch_content_margin_rect2.size.y) + var gdx_top_content_margin_padding : int = int(gdx_nine_patch_content_margin_rect2.size.x) # Debug #print("Name: ", atlas_texture_resource_name) - #print("LibGDX Left content margin padding: ", libgdx_left_content_margin_padding) - #print("LibGDX Right content margin padding: ", libgdx_right_content_margin_padding) - #print("LibGDX Bottom content margin padding: ", libgdx_bottom_content_margin_padding) - #print("LibGDX Top content margin padding: ", libgdx_top_content_margin_padding) + #print("GDX Left content margin padding: ", gdx_left_content_margin_padding) + #print("GDX Right content margin padding: ", gdx_right_content_margin_padding) + #print("GDX Bottom content margin padding: ", gdx_bottom_content_margin_padding) + #print("GDX Top content margin padding: ", gdx_top_content_margin_padding) - var godot_content_position_offset : Vector2 = Vector2(libgdx_left_content_margin_padding, libgdx_top_content_margin_padding) - var godot_content_size : Vector2 = Vector2(libgdx_texture_size.x - (libgdx_left_content_margin_padding + libgdx_right_content_margin_padding), libgdx_texture_size.y - (libgdx_top_content_margin_padding + libgdx_bottom_content_margin_padding)) + var godot_content_position_offset : Vector2 = Vector2(gdx_left_content_margin_padding, gdx_top_content_margin_padding) + var godot_content_size : Vector2 = Vector2(gdx_texture_size.x - (gdx_left_content_margin_padding + gdx_right_content_margin_padding), gdx_texture_size.y - (gdx_top_content_margin_padding + gdx_bottom_content_margin_padding)) godot_nine_patch_rect.set_region_rect(Rect2(godot_content_position_offset, godot_content_size)) # Set the size of the NinePatchRect node to be equal to the content size godot_nine_patch_rect.set_size(godot_content_size) # Set the NinePatchRect Patch Margin - var libgdx_nine_patch_margin_rect : Rect2 = libgdx_atlas_texture_dictionary["split"] - var libgdx_left_patch_margin : int = int(libgdx_nine_patch_margin_rect.position.x) - var libgdx_right_patch_margin : int = int(libgdx_nine_patch_margin_rect.position.y) - var libgdx_top_patch_margin : int = int(libgdx_nine_patch_margin_rect.size.x) - var libgdx_bottom_patch_margin : int = int(libgdx_nine_patch_margin_rect.size.y) + var gdx_nine_patch_margin_rect : Rect2 = gdx_atlas_texture_dictionary["split"] + var gdx_left_patch_margin : int = int(gdx_nine_patch_margin_rect.position.x) + var gdx_right_patch_margin : int = int(gdx_nine_patch_margin_rect.position.y) + var gdx_top_patch_margin : int = int(gdx_nine_patch_margin_rect.size.x) + var gdx_bottom_patch_margin : int = int(gdx_nine_patch_margin_rect.size.y) - # Verify that the libgdx margins are inside the content margin. We do this because Godot can't place the nine patch margins outside of the content margin: + # Verify that the gdx margins are inside the content margin. We do this because Godot can't place the nine patch margins outside of the content margin: var warning_message = "Texture \"%s\" has nine patch margins defined outside its \"%s\" content area. This is not supported in Godot. Automatically fixing..." - if libgdx_left_content_margin_padding > libgdx_left_patch_margin: + if gdx_left_content_margin_padding > gdx_left_patch_margin: __push_warning(warning_message % [ atlas_texture_resource_name, "left" ]) - libgdx_left_patch_margin = libgdx_left_content_margin_padding - if libgdx_right_content_margin_padding > libgdx_right_patch_margin: + gdx_left_patch_margin = gdx_left_content_margin_padding + if gdx_right_content_margin_padding > gdx_right_patch_margin: __push_warning(warning_message % [ atlas_texture_resource_name, "right" ]) - libgdx_right_patch_margin = libgdx_right_content_margin_padding - if libgdx_top_content_margin_padding > libgdx_top_patch_margin: + gdx_right_patch_margin = gdx_right_content_margin_padding + if gdx_top_content_margin_padding > gdx_top_patch_margin: __push_warning(warning_message % [ atlas_texture_resource_name, "top" ]) - libgdx_top_patch_margin = libgdx_top_content_margin_padding - if libgdx_bottom_content_margin_padding > libgdx_bottom_patch_margin: + gdx_top_patch_margin = gdx_top_content_margin_padding + if gdx_bottom_content_margin_padding > gdx_bottom_patch_margin: __push_warning(warning_message % [ atlas_texture_resource_name, "bottom" ]) - libgdx_bottom_patch_margin = libgdx_bottom_content_margin_padding + gdx_bottom_patch_margin = gdx_bottom_content_margin_padding # Debug - #print("LibGDX Left patch margin: ", libgdx_left_patch_margin) - #print("LibGDX Right patch margin: ", libgdx_right_patch_margin) - #print("LibGDX Bottom patch margin: ", libgdx_bottom_patch_margin) - #print("LibGDX Top patch margin: ", libgdx_top_patch_margin) + #print("GDX Left patch margin: ", gdx_left_patch_margin) + #print("GDX Right patch margin: ", gdx_right_patch_margin) + #print("GDX Bottom patch margin: ", gdx_bottom_patch_margin) + #print("GDX Top patch margin: ", gdx_top_patch_margin) - # In LibGDX the patch margin is calculated from the edges, but in Godot the patch margin is relative to the content padding. Here we convert the coordinates as required. - var godot_right_patch_margin : int = libgdx_right_patch_margin - libgdx_right_content_margin_padding - var godot_left_patch_margin : int = libgdx_left_patch_margin - libgdx_left_content_margin_padding - var godot_top_patch_margin : int = libgdx_top_patch_margin - libgdx_top_content_margin_padding - var godot_bottom_patch_margin : int = libgdx_bottom_patch_margin - libgdx_bottom_content_margin_padding + # In GDX the patch margin is calculated from the edges, but in Godot the patch margin is relative to the content padding. Here we convert the coordinates as required. + var godot_right_patch_margin : int = gdx_right_patch_margin - gdx_right_content_margin_padding + var godot_left_patch_margin : int = gdx_left_patch_margin - gdx_left_content_margin_padding + var godot_top_patch_margin : int = gdx_top_patch_margin - gdx_top_content_margin_padding + var godot_bottom_patch_margin : int = gdx_bottom_patch_margin - gdx_bottom_content_margin_padding godot_nine_patch_rect.set_patch_margin(MARGIN_LEFT, godot_left_patch_margin) godot_nine_patch_rect.set_patch_margin(MARGIN_RIGHT, godot_right_patch_margin) @@ -335,12 +335,12 @@ func import(p_source_file : String, p_save_path : String, _p_options : Dictionar godot_nine_patch_rect.set_patch_margin(MARGIN_BOTTOM, godot_bottom_patch_margin) # Save the NinePatchRect node - # NOTE: The LibGDX TexturePacker format may include relative paths for which we may have to create directories for, thus we handle those here for the NinePatchRect nodes as well. + # NOTE: The GDX TexturePacker format may include relative paths for which we may have to create directories for, thus we handle those here for the NinePatchRect nodes as well. if "/" in atlas_texture_resource_name: var path_to_folder_to_create : String = nine_patch_rect_scenes_directory.plus_file(atlas_texture_resource_name.get_base_dir()) if not directory.dir_exists(path_to_folder_to_create): if directory.make_dir_recursive(path_to_folder_to_create) != OK: - __push_error("Can't create directory: %s\n\tUnable to continue importing LibGDX Atlas." % [ path_to_folder_to_create ]) + __push_error("Can't create directory: %s\n\tUnable to continue importing GDX Atlas." % [ path_to_folder_to_create ]) return ERR_CANT_CREATE var godot_nine_patch_scene_save_path : String = atlas_texture_resource_path_format % [nine_patch_rect_scenes_directory, atlas_texture_resource_name, "tscn"] @@ -355,7 +355,7 @@ func import(p_source_file : String, p_save_path : String, _p_options : Dictionar if ResourceSaver.save(godot_nine_patch_scene_save_path, godot_nine_patch_packed_scene) != OK: return ERR_PARSE_ERROR else: - __push_error("Unable to pack converted LibGDX nine patch rect as a NinePatchRect scene. Cannot continue.") + __push_error("Unable to pack converted GDX nine patch rect as a NinePatchRect scene. Cannot continue.") return ERR_CANT_CREATE # Let Godot know about the generated files during the import process so it can recreate them if they are deleted @@ -365,7 +365,7 @@ func import(p_source_file : String, p_save_path : String, _p_options : Dictionar godot_nine_patch_rect.free() # Do the final for the original import (p_source_file): - # NOTE: Here we save the LibGDX Atlas file as a raw Resource because + # NOTE: Here we save the GDX Atlas file as a raw Resource because # the atlas itself does not provide any value other than generating all # the other AtlasTexture resources, and also by doing this the engine # will also re-import the atlas resource should the atlas file change. @@ -373,7 +373,7 @@ func import(p_source_file : String, p_save_path : String, _p_options : Dictionar # Private methods -var m_plugin_name = "LibGDX Texture Packer Atlas Importer" +var m_plugin_name = "GDX Texture Packer Atlas Importer" func __push_error(p_message : String) -> void: push_error("%s: %s" % [ m_plugin_name, p_message ]) diff --git a/addons/rubonnek.libgdx_texture_packer_atlas_importer/plugin.cfg b/addons/rubonnek.gdx_texture_packer_atlas_importer/plugin.cfg similarity index 61% rename from addons/rubonnek.libgdx_texture_packer_atlas_importer/plugin.cfg rename to addons/rubonnek.gdx_texture_packer_atlas_importer/plugin.cfg index fd59a48..84cac77 100644 --- a/addons/rubonnek.libgdx_texture_packer_atlas_importer/plugin.cfg +++ b/addons/rubonnek.gdx_texture_packer_atlas_importer/plugin.cfg @@ -1,7 +1,7 @@ [plugin] -name="LibGDX TexturePacker Atlas Importer" -description="Import plugin for LibGDX TexturePacker atlas format. +name="GDX TexturePacker Atlas Importer" +description="Import plugin for GDX TexturePacker atlas format. A GUI to create these atlases is available at: https://github.com/crashinvaders/gdx-texture-packer-gui" author="Wilson E. Alvarez" diff --git a/addons/rubonnek.libgdx_texture_packer_atlas_importer/plugin.gd b/addons/rubonnek.gdx_texture_packer_atlas_importer/plugin.gd similarity index 93% rename from addons/rubonnek.libgdx_texture_packer_atlas_importer/plugin.gd rename to addons/rubonnek.gdx_texture_packer_atlas_importer/plugin.gd index 96d6993..f0ab75b 100644 --- a/addons/rubonnek.libgdx_texture_packer_atlas_importer/plugin.gd +++ b/addons/rubonnek.gdx_texture_packer_atlas_importer/plugin.gd @@ -29,7 +29,7 @@ func _enter_tree() -> void: # Using ResourceLoader.load here instead of preload just so Godot Plugin # Refresher is able to properly reload the import plugin without stumbling # into ResourceLoader's cached entry. - var editor_import_plugin_gdscript : GDScript = ResourceLoader.load(get_script().get_path().get_base_dir().plus_file("libgdx_texture_packer_atlas_editor_import_plugin.gd"), "", true) + var editor_import_plugin_gdscript : GDScript = ResourceLoader.load(get_script().get_path().get_base_dir().plus_file("gdx_texture_packer_import_plugin.gd"), "", true) m_gdx_texture_packer_atlas_importer = editor_import_plugin_gdscript.new() add_import_plugin(m_gdx_texture_packer_atlas_importer) diff --git a/project.godot b/project.godot index df87ef8..edaf8da 100644 --- a/project.godot +++ b/project.godot @@ -16,7 +16,7 @@ config/icon="res://icon.png" [editor_plugins] -enabled=PoolStringArray( "res://addons/rubonnek.libgdx_texture_packer_atlas_importer/plugin.cfg" ) +enabled=PoolStringArray( "res://addons/rubonnek.gdx_texture_packer_importer/plugin.cfg" ) [gui]