From 41b8737609b3bb5d8b1c178e1d6234940bc5ded8 Mon Sep 17 00:00:00 2001 From: don-tnowe <67479453+don-tnowe@users.noreply.github.com> Date: Fri, 30 Sep 2022 20:56:25 +0300 Subject: [PATCH] Convert case of property names --- .../resources_speadsheet_view/editor_view.gd | 8 ++++++-- .../settings_grid.gd | 14 +------------ .../text_editing_utils.gd | 20 +++++++++++++++++++ 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/addons/resources_speadsheet_view/editor_view.gd b/addons/resources_speadsheet_view/editor_view.gd index 2d77542..fef5190 100644 --- a/addons/resources_speadsheet_view/editor_view.gd +++ b/addons/resources_speadsheet_view/editor_view.gd @@ -197,7 +197,7 @@ func _create_table(columns_changed : bool): for x in columns: new_node = table_header_scene.instance() headers_node.add_child(new_node) - new_node.get_node("Button").text = x + new_node.get_node("Button").text = TextEditingUtils.string_snake_to_naming_case(x) new_node.get_node("Button").hint_tooltip = x new_node.get_node("Button").connect("pressed", self, "_set_sorting", [x]) @@ -258,7 +258,11 @@ func _update_row(row_index : int, color_rows : bool = true): else: current_node = root_node.get_child(row_index * columns.size() + i) - current_node.hint_tooltip = columns[i] + "\nOf " + rows[row_index].resource_path.get_file().get_basename() + current_node.hint_tooltip = ( + TextEditingUtils.string_snake_to_naming_case(columns[i]) + + "\n---\n" + + "Of " + rows[row_index].resource_path.get_file().get_basename() + ) column_editors[i].set_value(current_node, rows[row_index].get(columns[i])) if columns[i] == "resource_path": diff --git a/addons/resources_speadsheet_view/settings_grid.gd b/addons/resources_speadsheet_view/settings_grid.gd index 29c739d..1c6894c 100644 --- a/addons/resources_speadsheet_view/settings_grid.gd +++ b/addons/resources_speadsheet_view/settings_grid.gd @@ -7,7 +7,7 @@ const SETTING_PREFIX = "addons/resources_spreadsheet_view/" func _ready(): for x in get_children(): - var setting = SETTING_PREFIX + camel_case_to_snake_case(x.name) + var setting = SETTING_PREFIX + TextEditingUtils.pascal_case_to_snake_case(x.name) if x is BaseButton: x.connect("toggled", self, "_set_setting", [setting]) if !ProjectSettings.has_setting(setting): @@ -25,17 +25,5 @@ func _ready(): x.value = ProjectSettings.get_setting(setting) -static func camel_case_to_snake_case(string : String) -> String: - var i = 0 - while i < string.length(): - if string.ord_at(i) < 97: - string = string.left(i) + ("_" if i > 0 else "") + string[i].to_lower() + string.substr(i + 1) - i += 1 - - i += 1 - - return string - - func _set_setting(new_value, setting): ProjectSettings.set_setting(setting, new_value) diff --git a/addons/resources_speadsheet_view/text_editing_utils.gd b/addons/resources_speadsheet_view/text_editing_utils.gd index 40d6aa9..390add7 100644 --- a/addons/resources_speadsheet_view/text_editing_utils.gd +++ b/addons/resources_speadsheet_view/text_editing_utils.gd @@ -140,3 +140,23 @@ static func _step_cursor(text : String, start : int, step : int = 1, ctrl_presse return start return 0 + + +static func string_snake_to_naming_case(string : String, add_spaces : bool = true) -> String: + var split = string.split("_") + for i in split.size(): + split[i] = split[i][0].to_upper() + split[i].substr(1).to_lower() + + return (" " if add_spaces else "").join(split) + + +static func pascal_case_to_snake_case(string : String) -> String: + var i = 0 + while i < string.length(): + if string.ord_at(i) < 97: + string = string.left(i) + ("_" if i > 0 else "") + string[i].to_lower() + string.substr(i + 1) + i += 1 + + i += 1 + + return string