Implement CSV import/export/edit

This commit is contained in:
don-tnowe 2023-01-24 20:28:21 +02:00
parent d05569d429
commit 26779d3486
10 changed files with 217 additions and 133 deletions

View File

@ -82,7 +82,7 @@ func display_folder(folderpath : String, sort_by : String = "", sort_reverse : b
node_recent_paths.add_path_to_recent(folderpath)
first_row = node_page_manager.first_row
last_row = min(node_page_manager.last_row, rows.size())
_load_resources_from_folder(folderpath, sort_by, sort_reverse)
_load_resources_from_path(folderpath, sort_by, sort_reverse)
if columns.size() == 0: return
@ -107,12 +107,17 @@ func refresh(force_rebuild : bool = true):
display_folder(current_path, sorting_by, sorting_reverse, force_rebuild)
func _load_resources_from_folder(path : String, sort_by : String, sort_reverse : bool):
func _load_resources_from_path(path : String, sort_by : String, sort_reverse : bool):
if path.ends_with("/"):
io = SpreadsheetEditFormatTres.new()
else:
io = load(path).view_script.new()
var loaded = load(path)
if loaded is SpreadsheetImport:
io = loaded.view_script.new()
else:
io = SpreadsheetEditFormatTres.new()
io.editor_view = self
rows = io.import_from_path(path, insert_row_sorted, sort_by, sort_reverse)

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=26 format=3 uid="uid://tmleonv20aqk"]
[gd_scene load_steps=27 format=3 uid="uid://tmleonv20aqk"]
[ext_resource type="Script" path="res://addons/resources_spreadsheet_view/editor_view.gd" id="1_wfx75"]
[ext_resource type="Script" path="res://addons/resources_spreadsheet_view/editor_color_setter.gd" id="2_t2s7k"]
@ -14,6 +14,7 @@
[ext_resource type="PackedScene" uid="uid://rww3gpl052bn" path="res://addons/resources_spreadsheet_view/typed_editors/dock_texture.tscn" id="12_4kr6q"]
[ext_resource type="PackedScene" uid="uid://dhunxgcae6h1" path="res://addons/resources_spreadsheet_view/settings_grid.tscn" id="13_as1sh"]
[ext_resource type="Script" path="res://addons/resources_spreadsheet_view/main_screen/input_handler.gd" id="14_2t57a"]
[ext_resource type="PackedScene" uid="uid://b413igx28kkvb" path="res://addons/resources_spreadsheet_view/import_export/import_export_dialog.tscn" id="14_3p12b"]
[ext_resource type="Script" path="res://addons/resources_spreadsheet_view/main_screen/selection_manager.gd" id="15_mx6qn"]
[ext_resource type="Script" path="res://addons/resources_spreadsheet_view/typed_cells/cell_editor_enum_array.gd" id="16_p7n52"]
[ext_resource type="Script" path="res://addons/resources_spreadsheet_view/typed_cells/cell_editor_array.gd" id="17_sofdw"]
@ -170,6 +171,12 @@ clip_text = true
fit_to_longest_item = false
script = ExtResource("4_umoob")
[node name="ImportExport" type="Button" parent="HeaderContentSplit/VBoxContainer/HBoxContainer/HBoxContainer2"]
layout_mode = 2
text = "Import/Export CSV..."
script = ExtResource("3_7ja2l")
icon_name = "TextFile"
[node name="Search" type="VBoxContainer" parent="HeaderContentSplit/VBoxContainer"]
visible = false
layout_mode = 2
@ -415,26 +422,23 @@ mouse_filter = 2
[node name="FileDialog" type="FileDialog" parent="Control"]
title = "Open"
size = Vector2i(1168, 630)
size = Vector2i(1000, 800)
popup_window = true
ok_button_text = "Select Current Folder"
min_size = Vector2i(800, 400)
ok_button_text = "Open"
mode_overrides_title = false
file_mode = 2
file_mode = 3
filters = PackedStringArray("*.tres")
[node name="Control" type="Control" parent="Control/FileDialog"]
custom_minimum_size = Vector2(1152, 573)
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 8.0
offset_top = 8.0
offset_right = 8.0
offset_bottom = -67.0
grow_horizontal = 2
grow_vertical = 2
auto_translate = false
mouse_filter = 2
[node name="FileDialogText" type="FileDialog" parent="Control"]
title = "Open"
size = Vector2i(1000, 800)
popup_window = true
min_size = Vector2i(800, 400)
ok_button_text = "Open"
mode_overrides_title = false
file_mode = 0
filters = PackedStringArray("*.csv")
[node name="Info" type="AcceptDialog" parent="Control"]
title = "About"
@ -486,6 +490,16 @@ min_size = Vector2i(500, 300)
[node name="Settings" parent="Control/Settings" instance=ExtResource("13_as1sh")]
[node name="ImportExport" type="Window" parent="Control"]
process_mode = 3
size = Vector2i(600, 400)
visible = false
transient = true
exclusive = true
min_size = Vector2i(600, 400)
[node name="ImportExport" parent="Control/ImportExport" instance=ExtResource("14_3p12b")]
[node name="SelectionActions" parent="Control" instance=ExtResource("23_m53sx")]
visible = false
layout_mode = 2
@ -512,10 +526,14 @@ node_property_editors = NodePath("../HeaderContentSplit/MarginContainer/FooterCo
[connection signal="text_submitted" from="HeaderContentSplit/VBoxContainer/HBoxContainer/HBoxContainer/Path" to="." method="_on_path_text_submitted"]
[connection signal="pressed" from="HeaderContentSplit/VBoxContainer/HBoxContainer/HBoxContainer/SelectDir" to="Control/FileDialog" method="popup_centered"]
[connection signal="pressed" from="HeaderContentSplit/VBoxContainer/HBoxContainer/HBoxContainer/DeletePath" to="HeaderContentSplit/VBoxContainer/HBoxContainer/HBoxContainer2/RecentPaths" method="remove_selected_path_from_recent"]
[connection signal="pressed" from="HeaderContentSplit/VBoxContainer/HBoxContainer/HBoxContainer2/ImportExport" to="Control/FileDialogText" method="popup_centered"]
[connection signal="text_submitted" from="HeaderContentSplit/VBoxContainer/Search/Search/SearchCond" to="." method="_on_search_cond_text_submitted"]
[connection signal="text_submitted" from="HeaderContentSplit/VBoxContainer/Search/Search/ProcessExpr" to="." method="_on_process_expr_text_submitted"]
[connection signal="pressed" from="HeaderContentSplit/VBoxContainer/HBoxContainer3/Refresh" to="." method="_on_path_text_submitted"]
[connection signal="value_changed" from="HeaderContentSplit/VBoxContainer/HBoxContainer3/Pages/LineEdit" to="HeaderContentSplit/VBoxContainer/HBoxContainer3/Pages" method="_on_LineEdit_value_changed"]
[connection signal="dir_selected" from="Control/FileDialog" to="." method="_on_FileDialog_dir_selected"]
[connection signal="file_selected" from="Control/FileDialog" to="." method="_on_FileDialog_dir_selected"]
[connection signal="dir_selected" from="Control/FileDialogText" to="Control/ImportExport/ImportExport" method="_on_file_selected"]
[connection signal="file_selected" from="Control/FileDialogText" to="Control/ImportExport/ImportExport" method="_on_file_selected"]
[connection signal="cells_rightclicked" from="SelectionManager" to="Control/SelectionActions" method="_on_grid_cells_rightclicked"]
[connection signal="cells_selected" from="SelectionManager" to="Control/SelectionActions" method="_on_grid_cells_selected"]

View File

@ -26,8 +26,7 @@ func save_entries(all_entries : Array, indices : Array, repeat : bool = true):
x[i] = " " + x[i]
file.store_csv_line(x, import_data.delimeter[0])
file.close()
if repeat:
timer = editor_view.get_tree().create_timer(3.0)
timer.timeout.connect(save_entries.bind(all_entries, indices, false))
@ -86,5 +85,4 @@ func import_from_path(path : String, insert_func : Callable, sort_by : String, s
resource_original_positions[res] = i
editor_view.fill_property_data(rows[0])
file.close()
return rows

View File

@ -2,6 +2,10 @@ class_name SpreadsheetExportFormatCsv
extends RefCounted
static func can_edit_path(path : String):
return path.ends_with(".csv")
static func export_to_file(entries_array : Array, column_names : Array, into_path : String, import_data):
var file = FileAccess.open(into_path, FileAccess.WRITE)
@ -26,5 +30,3 @@ static func export_to_file(entries_array : Array, column_names : Array, into_pat
line[j] = " " + line[j]
file.store_csv_line(line, import_data.delimeter[0])
file.close()

View File

@ -6,6 +6,10 @@ static func can_edit_path(path : String):
return path.ends_with(".csv")
static func get_properties(entries, import_data):
return Array(entries[0])
static func import_as_arrays(import_data) -> Array:
var file = FileAccess.open(import_data.edited_path, FileAccess.READ)
@ -38,12 +42,12 @@ static func import_as_arrays(import_data) -> Array:
elif line.size() != 1:
line.resize(text_lines[0].size())
text_lines.append(line)
file.close()
var entries = []
entries.resize(text_lines.size())
for i in entries.size():
entries[i] = text_lines[i]
import_data.prop_names = entries[0]
return entries

View File

@ -1,16 +1,17 @@
@tool
extends Window
extends Control
@export var prop_list_item_scene : PackedScene
@export var formats_export : Array[Script]
@export var formats_import : Array[Script]
@onready var editor_view := $"../.."
@onready var node_filename_options := $"TabContainer/Import/MarginContainer/ScrollContainer/VBoxContainer/GridContainer/OptionButton"
@onready var node_classname_field := $"TabContainer/Import/MarginContainer/ScrollContainer/VBoxContainer/GridContainer/LineEdit"
@onready var node_filename_props := $"TabContainer/Import/MarginContainer/ScrollContainer/VBoxContainer/GridContainer/OptionButton"
@onready var prop_list := $"TabContainer/Import/MarginContainer/ScrollContainer/VBoxContainer"
@onready var editor_view := $"../../.."
@onready var filename_options := $"Import/Margins/Scroll/Box/Grid/UseAsFilename"
@onready var classname_field := $"Import/Margins/Scroll/Box/Grid/Classname"
@onready var prop_list := $"Import/Margins/Scroll/Box"
@onready var file_dialog = $"../../FileDialogText"
var format_extension := ".csv"
var entries := []
var property_used_as_filename := 0
@ -19,56 +20,60 @@ var import_data : SpreadsheetImport
func _ready():
var create_file_button = Button.new()
$"../FileDialogText".get_child(3).get_child(3).add_child(create_file_button)
file_dialog.get_child(3, true).get_child(3, true).add_child(create_file_button)
create_file_button.get_parent().move_child(create_file_button, 2)
create_file_button.text = "Create File"
create_file_button.visible = true
create_file_button.icon = get_theme_icon("New", "EditorIcons")
create_file_button.icon = get_theme_icon(&"New", &"EditorIcons")
create_file_button.pressed.connect(_on_create_file_pressed)
hide()
show()
get_parent().min_size = Vector2(600, 400)
get_parent().size = Vector2(600, 400)
func _on_create_file_pressed():
var new_name = (
$"../FileDialogText".get_child(3).get_child(3).get_child(1).text
file_dialog.get_child(3, true).get_child(3, true).get_child(1, true).text
)
if new_name == "":
new_name += editor_view.current_path.get_base_dir().get_file()
var file = FileAccess.open(
$"../FileDialogText".get_child(3).get_child(0).get_child(4).text
+ "/"
+ new_name.get_basename() + ".csv", FileAccess.WRITE
)
file.close()
$"../FileDialogText".invalidate()
var file = FileAccess.open((
file_dialog.get_child(3, true).get_child(0, true).get_child(6, true).text
+ "/"
+ new_name.get_basename() + format_extension
), FileAccess.WRITE)
file_dialog.invalidate()
func _on_FileDialogText_file_selected(path : String):
func _on_file_selected(path : String):
import_data = SpreadsheetImport.new()
import_data.initialize(path)
_reset_controls()
_open_dialog(path)
popup_centered()
get_parent().popup_centered()
position = Vector2.ZERO
func _open_dialog(path : String):
node_classname_field.text = import_data.edited_path.get_file().get_basename()\
classname_field.text = import_data.edited_path.get_file().get_basename()\
.capitalize().replace(" ", "")
import_data.script_classname = node_classname_field.text
import_data.script_classname = classname_field.text
for x in formats_import:
if x.new().can_edit_path(path):
entries = x.new().import_as_arrays(import_data)
_load_property_names()
_load_property_names(path)
_create_prop_editors()
$"TabContainer/Import/MarginContainer/ScrollContainer/VBoxContainer/StyleSettingsI"._send_signal()
$"Import/Margins/Scroll/Box/StyleSettingsI"._send_signal()
func _load_property_names():
import_data.prop_names = Array(entries[0])
import_data.prop_types.resize(import_data.prop_names.size())
import_data.prop_types.fill(4)
func _load_property_names(path):
var prop_types = import_data.prop_types
prop_types.resize(import_data.prop_names.size())
prop_types.fill(4)
for i in import_data.prop_names.size():
import_data.prop_names[i] = entries[0][i]\
.replace("\"", "")\
@ -83,17 +88,17 @@ func _load_property_names():
# Don't guess Ints automatically - further rows might have floats
if entries[1][i].is_valid_float():
import_data.prop_types[i] = SpreadsheetImport.PropType.FLOAT
prop_types[i] = SpreadsheetImport.PropType.FLOAT
elif entries[1][i].begins_with("res://"):
import_data.prop_types[i] = SpreadsheetImport.PropType.OBJECT
prop_types[i] = SpreadsheetImport.PropType.OBJECT
else:
import_data.prop_types[i] = SpreadsheetImport.PropType.STRING
prop_types[i] = SpreadsheetImport.PropType.STRING
node_filename_options.clear()
filename_options.clear()
for i in import_data.prop_names.size():
node_filename_options.add_item(import_data.prop_names[i], i)
filename_options.add_item(import_data.prop_names[i], i)
func _create_prop_editors():
@ -101,7 +106,7 @@ func _create_prop_editors():
if !x is GridContainer: x.free()
for i in import_data.prop_names.size():
var new_node = prop_list_item_scene.instance()
var new_node = prop_list_item_scene.instantiate()
prop_list.add_child(new_node)
new_node.display(import_data.prop_names[i], import_data.prop_types[i])
new_node.connect_all_signals(self, i)
@ -131,41 +136,41 @@ func _export_tres_folder():
func _on_import_to_tres_pressed():
hide()
_generate_class()
_export_tres_folder()
await get_tree().process_frame
editor_view.display_folder(import_data.edited_path.get_basename() + "/")
await get_tree().process_frame
editor_view.refresh()
close()
func _on_import_edit_pressed():
hide()
_generate_class(false)
import_data.prop_used_as_filename = ""
import_data.save()
await get_tree().process_frame
editor_view.display_folder(import_data.resource_path)
editor_view.hidden_columns[editor_view.current_path] = {
editor_view.node_columns.hidden_columns[editor_view.current_path] = {
"resource_path" : true,
"resource_local_to_scene" : true,
}
editor_view.save_data()
await get_tree().process_frame
editor_view.refresh()
close()
func _on_export_csv_pressed():
hide()
var exported_cols = editor_view.columns.duplicate()
exported_cols.erase("resource_local_to_scene")
for x in editor_view.hidden_columns[editor_view.current_path].keys():
for x in editor_view.node_columns.hidden_columns[editor_view.current_path].keys():
exported_cols.erase(x)
SpreadsheetExportFormatCsv.export_to_file(editor_view.rows, exported_cols, import_data.edited_path, import_data)
await get_tree().process_frame
editor_view.refresh()
close()
# Input controls
@ -175,8 +180,8 @@ func _on_classname_field_text_changed(new_text : String):
func _on_remove_first_row_toggled(button_pressed : bool):
import_data.remove_first_row = button_pressed
$"TabContainer/Export/HBoxContainer2/Button".pressed = true
$"TabContainer/Export/HBoxContainer3/CheckBox".pressed = true
# $"Export/Box2/Button".button_pressed = true
$"Export/Box3/CheckBox".button_pressed = button_pressed
func _on_filename_options_item_selected(index):
@ -204,9 +209,13 @@ func _on_export_space_toggled(button_pressed : bool):
func _reset_controls():
$"TabContainer/Export/HBoxContainer2/CheckBox".pressed = false
$"Export/Box/CheckBox".button_pressed = false
_on_remove_first_row_toggled(true)
func _on_enum_format_changed(case, delimiter, bool_yes, bool_no):
import_data.enum_format = [case, delimiter, bool_yes, bool_no]
func close():
get_parent().hide()

View File

@ -1,104 +1,103 @@
[gd_scene load_steps=5 format=3 uid="uid://b413igx28kkvb"]
[gd_scene load_steps=7 format=3 uid="uid://b413igx28kkvb"]
[ext_resource type="Script" path="res://addons/resources_spreadsheet_view/import_export/import_export_dialog.gd" id="1"]
[ext_resource type="PackedScene" path="res://addons/resources_spreadsheet_view/import_export/property_list_item.tscn" id="2"]
[ext_resource type="Script" path="res://addons/resources_spreadsheet_view/import_export/formats_import/import_csv.gd" id="3"]
[ext_resource type="PackedScene" path="res://addons/resources_spreadsheet_view/import_export/import_export_enum_format.tscn" id="4"]
[ext_resource type="Script" path="res://addons/resources_spreadsheet_view/import_export/formats_export/export_csv.gd" id="2_33c6s"]
[ext_resource type="Script" path="res://addons/resources_spreadsheet_view/import_export/formats_import/import_csv.gd" id="2_fxayt"]
[ext_resource type="PackedScene" uid="uid://b8llymigbprh6" path="res://addons/resources_spreadsheet_view/import_export/property_list_item.tscn" id="2_xfhmf"]
[ext_resource type="PackedScene" uid="uid://ckhf3bqy2rqjr" path="res://addons/resources_spreadsheet_view/import_export/import_export_enum_format.tscn" id="4"]
[node name="Control" type="Window"]
size = Vector2i(600, 373)
wrap_controls = true
min_size = Vector2i(600, 0)
script = ExtResource("1")
prop_list_item_scene = ExtResource("2")
formats_import = [ExtResource("3")]
[sub_resource type="ButtonGroup" id="ButtonGroup_080hd"]
[node name="TabContainer" type="TabContainer" parent="."]
[node name="TabContainer" type="TabContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_right = -552.0
offset_bottom = -275.0
grow_horizontal = 2
grow_vertical = 2
use_hidden_tabs_for_min_size = true
script = ExtResource("1")
prop_list_item_scene = ExtResource("2_xfhmf")
formats_export = [ExtResource("2_33c6s")]
formats_import = [ExtResource("2_fxayt")]
[node name="Import" type="VBoxContainer" parent="TabContainer"]
[node name="Import" type="VBoxContainer" parent="."]
layout_mode = 2
mouse_filter = 2
[node name="MarginContainer" type="MarginContainer" parent="TabContainer/Import"]
[node name="Margins" type="MarginContainer" parent="Import"]
layout_mode = 2
size_flags_vertical = 3
[node name="ScrollContainer" type="ScrollContainer" parent="TabContainer/Import/MarginContainer"]
[node name="Scroll" type="ScrollContainer" parent="Import/Margins"]
layout_mode = 2
[node name="VBoxContainer" type="VBoxContainer" parent="TabContainer/Import/MarginContainer/ScrollContainer"]
[node name="Box" type="VBoxContainer" parent="Import/Margins/Scroll"]
layout_mode = 2
size_flags_horizontal = 3
[node name="GridContainer" type="GridContainer" parent="TabContainer/Import/MarginContainer/ScrollContainer/VBoxContainer"]
[node name="Grid" type="GridContainer" parent="Import/Margins/Scroll/Box"]
layout_mode = 2
columns = 2
[node name="Label" type="Label" parent="TabContainer/Import/MarginContainer/ScrollContainer/VBoxContainer/GridContainer"]
[node name="Label" type="Label" parent="Import/Margins/Scroll/Box/Grid"]
layout_mode = 2
text = "Use as filename:"
[node name="OptionButton" type="OptionButton" parent="TabContainer/Import/MarginContainer/ScrollContainer/VBoxContainer/GridContainer"]
[node name="UseAsFilename" type="OptionButton" parent="Import/Margins/Scroll/Box/Grid"]
layout_mode = 2
size_flags_horizontal = 3
[node name="Label2" type="Label" parent="TabContainer/Import/MarginContainer/ScrollContainer/VBoxContainer/GridContainer"]
[node name="Label2" type="Label" parent="Import/Margins/Scroll/Box/Grid"]
visible = false
layout_mode = 2
text = "Class Name"
[node name="LineEdit" type="LineEdit" parent="TabContainer/Import/MarginContainer/ScrollContainer/VBoxContainer/GridContainer"]
[node name="Classname" type="LineEdit" parent="Import/Margins/Scroll/Box/Grid"]
visible = false
layout_mode = 2
caret_blink = true
caret_blink_interval = 0.5
[node name="CheckBox" type="CheckBox" parent="TabContainer/Import/MarginContainer/ScrollContainer/VBoxContainer/GridContainer"]
[node name="RemoveFirstRow" type="CheckBox" parent="Import/Margins/Scroll/Box/Grid"]
layout_mode = 2
text = "First row contains property names"
[node name="Control" type="Control" parent="TabContainer/Import/MarginContainer/ScrollContainer/VBoxContainer/GridContainer"]
[node name="Control" type="Control" parent="Import/Margins/Scroll/Box/Grid"]
layout_mode = 2
[node name="Control2" type="Control" parent="TabContainer/Import/MarginContainer/ScrollContainer/VBoxContainer/GridContainer"]
[node name="Control2" type="Control" parent="Import/Margins/Scroll/Box/Grid"]
visible = false
layout_mode = 2
[node name="StyleSettingsI" parent="TabContainer/Import/MarginContainer/ScrollContainer/VBoxContainer" instance=ExtResource("4")]
[node name="StyleSettingsI" parent="Import/Margins/Scroll/Box" instance=ExtResource("4")]
layout_mode = 2
[node name="HBoxContainer" type="HBoxContainer" parent="TabContainer/Import"]
[node name="Box" type="HBoxContainer" parent="Import"]
layout_mode = 2
mouse_filter = 2
alignment = 1
[node name="Ok2" type="Button" parent="TabContainer/Import/HBoxContainer"]
[node name="Ok2" type="Button" parent="Import/Box"]
layout_mode = 2
text = "Confirm and edit"
[node name="Ok" type="Button" parent="TabContainer/Import/HBoxContainer"]
[node name="Ok" type="Button" parent="Import/Box"]
layout_mode = 2
text = "Convert to Resources and edit"
[node name="Cancel" type="Button" parent="TabContainer/Import/HBoxContainer"]
[node name="Cancel" type="Button" parent="Import/Box"]
layout_mode = 2
text = "Cancel"
[node name="Control" type="Control" parent="TabContainer/Import"]
[node name="Control" type="Control" parent="Import"]
layout_mode = 2
mouse_filter = 2
[node name="Export" type="VBoxContainer" parent="TabContainer"]
[node name="Export" type="VBoxContainer" parent="."]
visible = false
layout_mode = 2
[node name="Info" type="Label" parent="TabContainer/Export"]
[node name="Info" type="Label" parent="Export"]
layout_mode = 2
size_flags_vertical = 0
text = "The currently edited folder will be exported into the selected file.
@ -108,65 +107,83 @@ Rows hidden by the filter will NOT be exported, and order follows the current so
Hidden columns will NOT be exported."
autowrap_mode = 2
[node name="HSeparator" type="HSeparator" parent="TabContainer/Export"]
[node name="HSeparator" type="HSeparator" parent="Export"]
layout_mode = 2
[node name="HBoxContainer2" type="HBoxContainer" parent="TabContainer/Export"]
[node name="Box" type="HBoxContainer" parent="Export"]
layout_mode = 2
alignment = 1
[node name="Label2" type="Label" parent="TabContainer/Export/HBoxContainer2"]
[node name="Label2" type="Label" parent="Export/Box"]
layout_mode = 2
size_flags_horizontal = 3
text = "Delimeter:"
[node name="Button" type="Button" parent="TabContainer/Export/HBoxContainer2"]
[node name="Button" type="Button" parent="Export/Box"]
layout_mode = 2
toggle_mode = true
button_group = SubResource("ButtonGroup_080hd")
text = "Comma (,)"
[node name="Button2" type="Button" parent="TabContainer/Export/HBoxContainer2"]
[node name="Button2" type="Button" parent="Export/Box"]
layout_mode = 2
toggle_mode = true
button_group = SubResource("ButtonGroup_080hd")
text = "Semicolon (;)"
[node name="Button3" type="Button" parent="TabContainer/Export/HBoxContainer2"]
[node name="Button3" type="Button" parent="Export/Box"]
layout_mode = 2
toggle_mode = true
button_group = SubResource("ButtonGroup_080hd")
text = "Tab"
[node name="CheckBox" type="CheckBox" parent="TabContainer/Export/HBoxContainer2"]
[node name="CheckBox" type="CheckBox" parent="Export/Box"]
layout_mode = 2
text = "With space after"
[node name="HBoxContainer3" type="HBoxContainer" parent="TabContainer/Export"]
[node name="Box3" type="HBoxContainer" parent="Export"]
layout_mode = 2
[node name="CheckBox" type="CheckBox" parent="TabContainer/Export/HBoxContainer3"]
[node name="CheckBox" type="CheckBox" parent="Export/Box3"]
layout_mode = 2
text = "First row contains property names (CSV)"
[node name="StyleSettingsE" parent="TabContainer/Export" instance=ExtResource("4")]
[node name="StyleSettingsE" parent="Export" instance=ExtResource("4")]
layout_mode = 2
[node name="Control" type="Control" parent="TabContainer/Export"]
[node name="Control" type="Control" parent="Export"]
layout_mode = 2
size_flags_vertical = 3
[node name="HBoxContainer" type="HBoxContainer" parent="TabContainer/Export"]
[node name="Box2" type="HBoxContainer" parent="Export"]
layout_mode = 2
alignment = 1
[node name="Button" type="Button" parent="TabContainer/Export/HBoxContainer"]
[node name="Button" type="Button" parent="Export/Box2"]
layout_mode = 2
text = "Export to CSV"
[node name="Cancel" type="Button" parent="TabContainer/Export/HBoxContainer"]
[node name="Cancel" type="Button" parent="Export/Box2"]
layout_mode = 2
text = "Cancel"
[node name="Control2" type="Control" parent="TabContainer/Export"]
[node name="Control2" type="Control" parent="Export"]
layout_mode = 2
[connection signal="pressed" from="TabContainer/Import/HBoxContainer/Cancel" to="." method="hide"]
[connection signal="pressed" from="TabContainer/Export/HBoxContainer/Cancel" to="." method="hide"]
[connection signal="item_selected" from="Import/Margins/Scroll/Box/Grid/UseAsFilename" to="." method="_on_filename_options_item_selected"]
[connection signal="text_changed" from="Import/Margins/Scroll/Box/Grid/Classname" to="." method="_on_classname_field_text_changed"]
[connection signal="toggled" from="Import/Margins/Scroll/Box/Grid/RemoveFirstRow" to="." method="_on_remove_first_row_toggled"]
[connection signal="format_changed" from="Import/Margins/Scroll/Box/StyleSettingsI" to="." method="_on_enum_format_changed"]
[connection signal="format_changed" from="Import/Margins/Scroll/Box/StyleSettingsI" to="Export/StyleSettingsE" method="_on_format_changed"]
[connection signal="pressed" from="Import/Box/Ok2" to="." method="_on_import_edit_pressed"]
[connection signal="pressed" from="Import/Box/Ok" to="." method="_on_import_to_tres_pressed"]
[connection signal="pressed" from="Import/Box/Cancel" to="." method="close"]
[connection signal="pressed" from="Export/Box/Button" to="." method="_on_export_delimeter_pressed" binds= [","]]
[connection signal="pressed" from="Export/Box/Button2" to="." method="_on_export_delimeter_pressed" binds= [";"]]
[connection signal="pressed" from="Export/Box/Button3" to="." method="_on_export_delimeter_pressed" binds= [" "]]
[connection signal="toggled" from="Export/Box/CheckBox" to="." method="_on_export_space_toggled"]
[connection signal="toggled" from="Export/Box3/CheckBox" to="." method="_on_remove_first_row_toggled"]
[connection signal="format_changed" from="Export/StyleSettingsE" to="." method="_on_enum_format_changed"]
[connection signal="format_changed" from="Export/StyleSettingsE" to="Import/Margins/Scroll/Box/StyleSettingsI" method="_on_format_changed"]
[connection signal="pressed" from="Export/Box2/Button" to="." method="_on_export_csv_pressed"]
[connection signal="pressed" from="Export/Box2/Cancel" to="." method="close"]

View File

@ -19,12 +19,29 @@ size_flags_horizontal = 3
layout_mode = 2
size_flags_horizontal = 3
clip_text = true
item_count = 4
selected = 2
popup/item_0/text = "all lower"
popup/item_0/id = 0
popup/item_1/text = "caps Except First"
popup/item_1/id = 1
popup/item_2/text = "Caps Every Word"
popup/item_2/id = 2
popup/item_3/text = "ALL CAPS"
popup/item_3/id = 3
[node name="Separator" type="OptionButton" parent="HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.5
clip_text = true
item_count = 3
popup/item_0/text = "Space \" \""
popup/item_0/id = 0
popup/item_1/text = "Underscore \"_\""
popup/item_1/id = 1
popup/item_2/text = "Kebab \"-\""
popup/item_2/id = 2
[node name="Label4" type="Label" parent="."]
layout_mode = 2

View File

@ -16,3 +16,19 @@ layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 5
size_flags_stretch_ratio = 0.25
item_count = 7
fit_to_longest_item = false
popup/item_0/text = "Bool"
popup/item_0/id = 1
popup/item_1/text = "Integer Number"
popup/item_1/id = 2
popup/item_2/text = "Floating Point Number"
popup/item_2/id = 3
popup/item_3/text = "String/Other"
popup/item_3/id = 4
popup/item_4/text = "Color"
popup/item_4/id = 14
popup/item_5/text = "Resource Path"
popup/item_5/id = 17
popup/item_6/text = "Enumeration"
popup/item_6/id = 101

View File

@ -7,11 +7,7 @@ enum PropType {
INT,
FLOAT,
STRING,
VECTOR2,
RECT2,
VECTOR3,
COLOR,
ARRAY,
OBJECT,
ENUM,
MAX,
@ -57,7 +53,8 @@ func initialize(path):
func save():
ResourceSaver.call_deferred("save", edited_path.get_basename() + SUFFIX, self)
resource_path = edited_path.get_basename() + SUFFIX
ResourceSaver.call_deferred("save", self)
func string_to_property(string : String, col_index : int):
@ -69,7 +66,7 @@ func string_to_property(string : String, col_index : int):
string = string.to_lower()
if string == enum_format[2].to_lower(): return true
if string == enum_format[3].to_lower(): return false
return !string in ["no", "disabled", "-", "false", "absent", "wrong", "off", ""]
return !string in ["no", "disabled", "-", "false", "absent", "wrong", "off", "0", ""]
PropType.FLOAT:
return string.to_float()
@ -118,6 +115,7 @@ func property_to_string(value, col_index : int) -> String:
PropType.ENUM:
var dict = uniques[col_index]
print(dict)
for k in dict:
if dict[k] == value:
return change_name_to_format(k, enum_format[0], enum_format[1])
@ -141,13 +139,13 @@ func create_property_line_for_prop(col_index : int) -> String:
return result + "= 0\r\n"
PropType.COLOR:
return result + "= Color.white\r\n"
return result + "= Color.WHITE\r\n"
PropType.OBJECT:
return result + " Resource\r\n"
PropType.ENUM:
return result + ": %s\r\n" % _escape_forbidden_enum_names(prop_names[col_index].capitalize().replace(" ", ""))
return result + " %s\r\n" % _escape_forbidden_enum_names(prop_names[col_index].capitalize().replace(" ", ""))
# return result.replace(
# "@export var",
# "@export_enum(" + _escape_forbidden_enum_names(
@ -165,7 +163,7 @@ func _escape_forbidden_enum_names(string : String) -> String:
# Not in ClassDB, but are engine types and can be property names
if string in [
"Color", "String", "Plane",
"Color", "String", "Plane", "Projection",
"Basis", "Transform", "Variant",
]:
return string + "_"
@ -194,11 +192,11 @@ func create_enum_for_prop(col_index) -> String:
func generate_script(entries, has_classname = true) -> GDScript:
var source = ""
if has_classname and script_classname != "":
source = "class_name " + script_classname + " \r\nextends Resource\r\n\r\n"
else:
source = "extends Resource\r\n\r\n"
# if has_classname and script_classname != "":
# source = "class_name " + script_classname + " \r\nextends Resource\r\n\r\n"
#
# else:
source = "extends Resource\r\n\r\n"
# Enums
uniques = get_uniques(entries)