From 77111d0ee0b15740ebe3a1d8eeb153793858ae94 Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 26 Jan 2022 18:58:49 +0100 Subject: [PATCH] Implement a folders array for the data managers's settings resource similar to how the json used to be. --- game/addons/data_manager/_data/settings.res | Bin 311 -> 0 bytes game/addons/data_manager/_data/settings.tres | 7 ++ .../resources/data_manager_addon_settings.gd | 113 ++++++++++++++++++ 3 files changed, 120 insertions(+) delete mode 100644 game/addons/data_manager/_data/settings.res create mode 100644 game/addons/data_manager/_data/settings.tres diff --git a/game/addons/data_manager/_data/settings.res b/game/addons/data_manager/_data/settings.res deleted file mode 100644 index b361966420442dc5cc16927f463a649138e9b83d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 311 zcmbtQ%L>9U5R8h59z1yRD-2$}_7Bnz2ure*LYqi7{=c)af;~Gh>?6zUY+Ua;vtWm~ z2Q?l+$C6(qFw*~^f>*FCf_}<@CSS9cz=_TI_bt)P=75fbGCr%>Al0(}l$Y#BUbxmV4RRY|Q$0bdIf2;STyznzx?Fo(P~Gbl3WqOy1F2&= AIRF3v diff --git a/game/addons/data_manager/_data/settings.tres b/game/addons/data_manager/_data/settings.tres new file mode 100644 index 00000000..ae915a2d --- /dev/null +++ b/game/addons/data_manager/_data/settings.tres @@ -0,0 +1,7 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://addons/data_manager/resources/data_manager_addon_settings.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +folder_count = 0 diff --git a/game/addons/data_manager/resources/data_manager_addon_settings.gd b/game/addons/data_manager/resources/data_manager_addon_settings.gd index 2ec21290..fd25b531 100644 --- a/game/addons/data_manager/resources/data_manager_addon_settings.gd +++ b/game/addons/data_manager/resources/data_manager_addon_settings.gd @@ -1,4 +1,117 @@ tool extends Resource +class SettingEntry: + var folder : String = "" + var header : String = "" + var name : String = "" + var type : String = "" +var folders : Array = Array() + +func _get(property): + if property == "folder_count": + return folders.size() + + if property.begins_with("folders/"): + var sindex : String = property.get_slice("/", 1) + + if sindex == "": + return null + + var index : int = sindex.to_int() + + if index < 0 || index >= folders.size(): + return null + + var p : String = property.get_slice("/", 2) + + if p == "folder": + return folders[index].folder + elif p == "header": + return folders[index].header + elif p == "name": + return folders[index].name + elif p == "type": + return folders[index].type + else: + return null + + return null + +func _set(property, val): + if property == "folder_count": + set_folder_count(val) + return true + + if property.begins_with("folders/"): + var sindex : String = property.get_slice("/", 1) + + if sindex == "": + return null + + var index : int = sindex.to_int() + + if index < 0: + return false + + if index >= folders.size(): + return false + + var p : String = property.get_slice("/", 2) + + if p == "folder": + folders[index].folder = val + return true + elif p == "header": + folders[index].header = val + return true + elif p == "name": + folders[index].name = val + return true + elif p == "type": + folders[index].type = val + return true + + return false + +func _get_property_list() -> Array: + var props : Array = Array() + + props.append({ + "name": "folder_count", + "type": TYPE_INT, + }) + + for i in range(folders.size()): + props.append({ + "name": "folders/" + str(i) + "/folder", + "type": TYPE_STRING, + }) + props.append({ + "name": "folders/" + str(i) + "/header", + "type": TYPE_STRING, + }) + props.append({ + "name": "folders/" + str(i) + "/name", + "type": TYPE_STRING, + }) + props.append({ + "name": "folders/" + str(i) + "/type", + "type": TYPE_STRING, + }) + + return props + +func apply_folder_size(val : int) -> void: + folders.resize(val) + + for i in range(folders.size()): + if !folders[i]: + folders[i] = SettingEntry.new() + +func set_folder_count(val : int) -> void: + apply_folder_size(val) + + emit_changed() + property_list_changed_notify()