Skip to content

Commit 5d7414f

Browse files
committed
fix bug with autoupdate & other addition
- added way to get object as pre-generated class
1 parent 5932a04 commit 5d7414f

File tree

8 files changed

+227
-84
lines changed

8 files changed

+227
-84
lines changed

addons/datatable_godot/class/class_datatable.gd

+42-2
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,10 @@ func _get_structure()->Dictionary:
680680
assert(false, str("Can't find the structure: ", _struct_name))
681681
return {}
682682

683+
func _check_class(Class_to_check: Resource) -> bool:
684+
# For now it's empty, need to complete it
685+
return true
686+
683687
## Function to check if the return data is an error or not.[br]
684688
## More precisely, it check if the data has the "error" key in it (if it is, it's an error).[br][br]
685689
## Return:[br]
@@ -713,12 +717,12 @@ func has_item(key: String)->bool:
713717

714718
return rows.has(key)
715719

716-
## Return the data of the item.[br]
720+
## Return the data of the item as a dictionary object.[br]
717721
## Emit: [signal item_getted] & [signal table_getted][br]
718722
## [br]
719723
## Here is an example of what you could get from it:[br]
720724
## [codeblock]{ "a_string": "little string", "float_object": 0.3241, ..., "vector3 object": (0.1, 1, -5) }[/codeblock]
721-
func get_item(key: String)->Dictionary:
725+
func get_item_as_dict(key: String)->Dictionary:
722726

723727
if !has_item(key):
724728
var err = {"error":str("The table ",_table_name," doesn't contain the item '",key,"' key!")}
@@ -736,6 +740,40 @@ func get_item(key: String)->Dictionary:
736740

737741
return rows[key]
738742

743+
func get_item(key: String)->Structure:
744+
745+
var struct_converted_name: String = _struct_name.replace(" ", "_")
746+
747+
var className = str("struct_",struct_converted_name)
748+
749+
if struct_converted_name.is_empty():
750+
push_error("Can't return the item by the structure class, the structure_name is empty!")
751+
return null
752+
753+
print(_dt_classDB.class_exist(className))
754+
755+
if !_dt_classDB.class_exist(className):
756+
push_error(str("Can't return the item by the structure class, the class of the structure (",className,") doesn't exist!\nYou need to create it or generate it first!"))
757+
return null
758+
759+
var _classResource: Resource = _dt_classDB.class_instantiate(className)
760+
761+
if !_classResource:
762+
push_error(str("Can't return the item by the structure class, the class created is not valid!"))
763+
return null
764+
765+
if !_check_class(_classResource):
766+
push_error(str("Can't return the item by the structure class, the class created is not valid!"))
767+
return null
768+
769+
var _item = _classResource.new(get_item_as_dict(key))
770+
771+
if !_item:
772+
push_error(str("Can't return the item created with the structure class, the item created is not valid, maybe an error with the data provided?"))
773+
return null
774+
775+
return _item
776+
739777
## Add an item inside the datatable[br]
740778
## Emit: [signal item_added] & [signal table_saved][br]
741779
## [br]
@@ -899,3 +937,5 @@ func get_items_list()->Array:
899937
var rows = _get_table_rows()
900938

901939
return rows.keys()
940+
941+

addons/datatable_godot/class/class_struct.gd

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ extends Object
44
##
55
## @experimental
66
class_name Structure
7+

0 commit comments

Comments
 (0)