Skip to content

Commit

Permalink
Character Editor: Trim common prefix when importing portraits from fo…
Browse files Browse the repository at this point in the history
…lder (#2382)

It now does a scan and identifies whether all the portraits have a common prefix, and if so, removes it from the portrait name.
  • Loading branch information
Jowan-Spooner committed Sep 9, 2024
1 parent 598962f commit 882b288
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions addons/dialogic/Editor/CharacterEditor/character_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,27 @@ func import_portraits_from_folder(path:String) -> void:
var dir := DirAccess.open(path)
dir.list_dir_begin()
var file_name: String = dir.get_next()
var files := []
while file_name != "":
if not dir.current_is_dir():
var file_lower := file_name.to_lower()
if '.svg' in file_lower or '.png' in file_lower:
if not '.import' in file_lower:
var final_name := path.path_join(file_name)
%PortraitTree.add_portrait_item(file_name.trim_suffix('.'+file_name.get_extension()),
{'scene':"",'export_overrides':{'image':var_to_str(final_name)}, 'scale':1, 'offset':Vector2(), 'mirror':false}, parent)
files.append(file_name)
file_name = dir.get_next()

var prefix: String = files[0]
for file in files:
while true:
if file.begins_with(prefix):
break
if prefix.is_empty():
break
prefix = prefix.substr(0, len(prefix)-1)

for file in files:
%PortraitTree.add_portrait_item(file.trim_prefix(prefix).trim_suffix('.'+file.get_extension()),
{'scene':"",'export_overrides':{'image':var_to_str(path.path_join(file))}, 'scale':1, 'offset':Vector2(), 'mirror':false}, parent)

## Handle selection
if parent.get_child_count():
Expand Down Expand Up @@ -673,4 +685,3 @@ func _on_fit_preview_toggle_toggled(button_pressed):
func _on_reference_manger_button_pressed() -> void:
editors_manager.reference_manager.open()
%PortraitChangeInfo.hide()

0 comments on commit 882b288

Please sign in to comment.