Skip to content

Commit 16ff80c

Browse files
committed
removed unused utility functions and filled missing fields on plugin settings
1 parent 7976769 commit 16ff80c

File tree

6 files changed

+93
-84
lines changed

6 files changed

+93
-84
lines changed

addons/ninetailsrabbit.character_generator_importer_tool/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="Character generator importer tool"
44
description="This is an unofficial tool that can be used as a plugin in Godot to speed up the process of creating animations for the character generator"
55
author="Ninetailsrabbit"
6-
version="1.0.0"
6+
version="1.0.1"
77
script="ninetailsrabbit.character_generator_importer_tool.gd"

addons/ninetailsrabbit.character_generator_importer_tool/settings/plugin_settings.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class_name MyPluginSettings extends RefCounted
44
const PluginPrefixName: String = "ninetailsrabbit.character_generator_importer_tool" ## The folder name
55
const GitRepositoryName: String = "character-generator-importer-tool"
66

7-
static var PluginName: String = "MyPlugin"
7+
static var PluginName: String = "CharacterGeneratorImporterTool"
88
static var PluginProjectName: String = ProjectSettings.get_setting("application/config/name")
99
static var PluginBasePath: String = "res://addons/%s" % PluginPrefixName
1010
static var PluginLocalConfigFilePath = "%s/plugin.cfg" % PluginBasePath

addons/ninetailsrabbit.character_generator_importer_tool/src/importer.gd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ func create_spritesheets_parts_as_resources() -> void:
103103
image_format_regex.compile(".png$")
104104

105105
if DirAccess.dir_exists_absolute(input_folder_parts) and DirAccess.dir_exists_absolute(output_folder_parts):
106-
var spritesheets = PluginUtilities.get_files_recursive(input_folder_parts, image_format_regex)
106+
var spritesheets = CharacterGeneratorImporterToolPluginUtilities.get_files_recursive(input_folder_parts, image_format_regex)
107107

108108
if spritesheets.is_empty():
109109
return
110110

111-
PluginUtilities.remove_files_recursive(output_folder_parts)
111+
CharacterGeneratorImporterToolPluginUtilities.remove_files_recursive(output_folder_parts)
112112
DirAccess.make_dir_absolute(output_folder_parts)
113113

114114
DirAccess.make_dir_absolute("%s/Adult" % output_folder_parts)
@@ -155,7 +155,7 @@ func create_spritesheets_parts_as_resources() -> void:
155155

156156
## We assume that each core has 2 threads
157157
var available_threads: int = OS.get_processor_count() * 2
158-
var spritesheet_chunks = PluginUtilities.chunk_array(spritesheets, ceil(spritesheets.size() / available_threads))
158+
var spritesheet_chunks = CharacterGeneratorImporterToolPluginUtilities.chunk_array(spritesheets, ceil(spritesheets.size() / available_threads))
159159

160160
for spritesheet_chunk: Array in spritesheet_chunks:
161161
var thread = Thread.new()
@@ -210,19 +210,19 @@ func generate_animations() -> void:
210210

211211
if _character_spritesheets_are_valid():
212212

213-
PluginUtilities.free_children(self)
213+
CharacterGeneratorImporterToolPluginUtilities.free_children(self)
214214

215215
if not character_spritesheet.is_empty():
216216
var sprite_frames: SpriteFrames = create_sprite_frames(character_spritesheet)
217217
create_animated_sprite(character_spritesheet, sprite_frames)
218218

219219
if not character_spritesheet_folder.is_empty():
220-
for spritesheet_path: String in PluginUtilities.get_files_recursive(character_spritesheet_folder, image_format_regex):
220+
for spritesheet_path: String in CharacterGeneratorImporterToolPluginUtilities.get_files_recursive(character_spritesheet_folder, image_format_regex):
221221
var sprite_frames: SpriteFrames = create_sprite_frames(spritesheet_path)
222222
create_animated_sprite(spritesheet_path, sprite_frames)
223223

224224
if create_animation_player:
225-
for animated_sprite: AnimatedSprite2D in PluginUtilities.find_nodes_of_type(self, AnimatedSprite2D.new()):
225+
for animated_sprite: AnimatedSprite2D in CharacterGeneratorImporterToolPluginUtilities.find_nodes_of_type(self, AnimatedSprite2D.new()):
226226
create_animation_player_for(animated_sprite)
227227

228228
create_spritesheets_parts_as_resources()
@@ -1053,5 +1053,5 @@ func _on_tool_button_pressed(text: String) -> void:
10531053
"Generate Animations":
10541054
generate_animations()
10551055
"Clear Animations":
1056-
PluginUtilities.free_children(self)
1056+
CharacterGeneratorImporterToolPluginUtilities.free_children(self)
10571057
#endregion

addons/ninetailsrabbit.character_generator_importer_tool/updater/update_progress_bar.gd

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func _ready() -> void:
2929

3030
@warning_ignore("return_value_discarded")
3131
func run_update(progress_steps: int = 5, message: String = "Press 'Start Update' to start!") -> void:
32-
if PluginUtilities.is_valid_url(download_url):
32+
if _is_valid_url(download_url):
3333
show()
3434
set_process(true)
3535
get_cancel_button().disabled = true
@@ -148,9 +148,9 @@ func on_http_request_request_completed(result: int, response_code: int, headers:
148148

149149
if MyPluginSettings.DebugMode:
150150
if DirAccess.dir_exists_absolute(MyPluginSettings.PluginDebugDirectoryPath):
151-
PluginUtilities.remove_files_recursive(MyPluginSettings.PluginDebugDirectoryPath)
151+
_remove_files_recursive(MyPluginSettings.PluginDebugDirectoryPath)
152152
else:
153-
PluginUtilities.remove_files_recursive(MyPluginSettings.PluginBasePath)
153+
_remove_files_recursive(MyPluginSettings.PluginBasePath)
154154

155155
EditorInterface.get_resource_filesystem().scan()
156156

@@ -159,9 +159,9 @@ func on_http_request_request_completed(result: int, response_code: int, headers:
159159
if MyPluginSettings.DebugMode:
160160
if not DirAccess.dir_exists_absolute(MyPluginSettings.PluginDebugDirectoryPath):
161161
DirAccess.make_dir_absolute(MyPluginSettings.PluginDebugDirectoryPath)
162-
PluginUtilities.copy_directory_recursive(MyPluginSettings.PluginTemporaryReleaseUpdateDirectoryPath, MyPluginSettings.PluginDebugDirectoryPath)
162+
_copy_directory_recursive(MyPluginSettings.PluginTemporaryReleaseUpdateDirectoryPath, MyPluginSettings.PluginDebugDirectoryPath)
163163
else:
164-
PluginUtilities.copy_directory_recursive(MyPluginSettings.PluginTemporaryReleaseUpdateDirectoryPath, "res://")
164+
_copy_directory_recursive(MyPluginSettings.PluginTemporaryReleaseUpdateDirectoryPath, "res://")
165165

166166
EditorInterface.get_resource_filesystem().scan()
167167

@@ -175,3 +175,80 @@ func on_http_request_request_completed(result: int, response_code: int, headers:
175175
enable_plugin()
176176
hide()
177177
update_finished.emit()
178+
179+
180+
#region Utils
181+
func _is_valid_url(url: String) -> bool:
182+
var regex = RegEx.new()
183+
var url_pattern = "/(https:\\/\\/www\\.|http:\\/\\/www\\.|https:\\/\\/|http:\\/\\/)?[a-zA-Z]{2,}(\\.[a-zA-Z]{2,})(\\.[a-zA-Z]{2,})?\\/[a-zA-Z0-9]{2,}|((https:\\/\\/www\\.|http:\\/\\/www\\.|https:\\/\\/|http:\\/\\/)?[a-zA-Z]{2,}(\\.[a-zA-Z]{2,})(\\.[a-zA-Z]{2,})?)|(https:\\/\\/www\\.|http:\\/\\/www\\.|https:\\/\\/|http:\\/\\/)?[a-zA-Z0-9]{2,}\\.[a-zA-Z0-9]{2,}\\.[a-zA-Z0-9]{2,}(\\.[a-zA-Z0-9]{2,})?/g"
184+
regex.compile(url_pattern)
185+
186+
return regex.search(url) != null
187+
188+
189+
func _copy_directory_recursive(from_dir :String, to_dir :String) -> bool:
190+
if not DirAccess.dir_exists_absolute(from_dir):
191+
push_error("copy_directory_recursive: directory not found '%s'" % from_dir)
192+
return false
193+
194+
if not DirAccess.dir_exists_absolute(to_dir):
195+
196+
var err := DirAccess.make_dir_recursive_absolute(to_dir)
197+
if err != OK:
198+
push_error("copy_directory_recursive: Can't create directory '%s'. Error: %s" % [to_dir, error_string(err)])
199+
return false
200+
201+
var source_dir := DirAccess.open(from_dir)
202+
var dest_dir := DirAccess.open(to_dir)
203+
204+
if source_dir != null:
205+
source_dir.list_dir_begin()
206+
var next := "."
207+
208+
while next != "":
209+
next = source_dir.get_next()
210+
if next == "" or next == "." or next == "..":
211+
continue
212+
var source := source_dir.get_current_dir() + "/" + next
213+
var dest := dest_dir.get_current_dir() + "/" + next
214+
215+
if source_dir.current_is_dir():
216+
_copy_directory_recursive(source + "/", dest)
217+
continue
218+
219+
var err := source_dir.copy(source, dest)
220+
221+
if err != OK:
222+
push_error("_copy_directory_recursive: Error checked copy file '%s' to '%s'" % [source, dest])
223+
return false
224+
225+
return true
226+
else:
227+
push_error("copy_directory_recursive: Directory not found: " + from_dir)
228+
return false
229+
230+
231+
func _remove_files_recursive(path: String, regex: RegEx = null) -> void:
232+
var directory = DirAccess.open(path)
233+
234+
if DirAccess.get_open_error() == OK:
235+
directory.list_dir_begin()
236+
237+
var file_name = directory.get_next()
238+
239+
while file_name != "":
240+
if directory.current_is_dir():
241+
_remove_files_recursive(directory.get_current_dir().path_join(file_name), regex)
242+
else:
243+
if regex != null:
244+
if regex.search(file_name):
245+
directory.remove(file_name)
246+
else:
247+
directory.remove(file_name)
248+
249+
file_name = directory.get_next()
250+
251+
directory.remove(path)
252+
else:
253+
push_error("remove_recursive: An error %s happened open directory: %s " % [DirAccess.get_open_error(), path])
254+
#endregion

addons/ninetailsrabbit.character_generator_importer_tool/utils/plugin_utilities.gd

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,6 @@
1-
class_name PluginUtilities
1+
class_name CharacterGeneratorImporterToolPluginUtilities
22

33

4-
static func is_valid_url(url: String) -> bool:
5-
var regex = RegEx.new()
6-
var url_pattern = "/(https:\\/\\/www\\.|http:\\/\\/www\\.|https:\\/\\/|http:\\/\\/)?[a-zA-Z]{2,}(\\.[a-zA-Z]{2,})(\\.[a-zA-Z]{2,})?\\/[a-zA-Z0-9]{2,}|((https:\\/\\/www\\.|http:\\/\\/www\\.|https:\\/\\/|http:\\/\\/)?[a-zA-Z]{2,}(\\.[a-zA-Z]{2,})(\\.[a-zA-Z]{2,})?)|(https:\\/\\/www\\.|http:\\/\\/www\\.|https:\\/\\/|http:\\/\\/)?[a-zA-Z0-9]{2,}\\.[a-zA-Z0-9]{2,}\\.[a-zA-Z0-9]{2,}(\\.[a-zA-Z0-9]{2,})?/g"
7-
regex.compile(url_pattern)
8-
9-
return regex.search(url) != null
10-
11-
12-
static func filepath_is_valid(path: String):
13-
return not path.is_empty() and path.is_absolute_path() and ResourceLoader.exists(path)
14-
15-
16-
static func dirpath_is_valid(path: String):
17-
return not path.is_empty() and path.is_absolute_path() and DirAccess.dir_exists_absolute(path)
18-
19-
20-
static func directory_exist_on_executable_path(directory_path: String) -> Error:
21-
var real_path = OS.get_executable_path().get_base_dir().path_join(directory_path)
22-
var directory = DirAccess.open(real_path)
23-
24-
if directory == null:
25-
return DirAccess.get_open_error()
26-
27-
return OK
28-
294
## Supports RegEx expressions
305
static func get_files_recursive(path: String, regex: RegEx = null) -> Array:
316
if path.is_empty() or not DirAccess.dir_exists_absolute(path):
@@ -59,48 +34,6 @@ static func get_files_recursive(path: String, regex: RegEx = null) -> Array:
5934
return []
6035

6136

62-
static func copy_directory_recursive(from_dir :String, to_dir :String) -> bool:
63-
if not DirAccess.dir_exists_absolute(from_dir):
64-
push_error("PluginUtilities->copy_directory_recursive: directory not found '%s'" % from_dir)
65-
return false
66-
67-
if not DirAccess.dir_exists_absolute(to_dir):
68-
69-
var err := DirAccess.make_dir_recursive_absolute(to_dir)
70-
if err != OK:
71-
push_error("PluginUtilities->copy_directory_recursive: Can't create directory '%s'. Error: %s" % [to_dir, error_string(err)])
72-
return false
73-
74-
var source_dir := DirAccess.open(from_dir)
75-
var dest_dir := DirAccess.open(to_dir)
76-
77-
if source_dir != null:
78-
source_dir.list_dir_begin()
79-
var next := "."
80-
81-
while next != "":
82-
next = source_dir.get_next()
83-
if next == "" or next == "." or next == "..":
84-
continue
85-
var source := source_dir.get_current_dir() + "/" + next
86-
var dest := dest_dir.get_current_dir() + "/" + next
87-
88-
if source_dir.current_is_dir():
89-
copy_directory_recursive(source + "/", dest)
90-
continue
91-
92-
var err := source_dir.copy(source, dest)
93-
94-
if err != OK:
95-
push_error("PluginUtilities->copy_directory_recursive: Error checked copy file '%s' to '%s'" % [source, dest])
96-
return false
97-
98-
return true
99-
else:
100-
push_error("PluginUtilities->copy_directory_recursive: Directory not found: " + from_dir)
101-
return false
102-
103-
10437
static func remove_files_recursive(path: String, regex: RegEx = null) -> void:
10538
var directory = DirAccess.open(path)
10639

@@ -126,7 +59,6 @@ static func remove_files_recursive(path: String, regex: RegEx = null) -> void:
12659
push_error("PluginUtilities->remove_recursive: An error %s happened open directory: %s " % [DirAccess.get_open_error(), path])
12760

12861

129-
13062
static func find_nodes_of_type(node: Node, type_to_find: Node) -> Array:
13163
var result := []
13264

project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ config_version=5
1212

1313
config/name="Character generator tool importer"
1414
config/description="This is an unofficial tool that can be used as a plugin in Godot to speed up the process of creating animations for the character generator 2.0"
15-
config/version="1.0.0"
15+
config/version="1.0.1"
1616
config/features=PackedStringArray("4.3", "GL Compatibility")
1717
config/icon="res://icon.svg"
1818

0 commit comments

Comments
 (0)