@@ -680,6 +680,10 @@ func _get_structure()->Dictionary:
680
680
assert (false , str ("Can't find the structure: " , _struct_name ))
681
681
return {}
682
682
683
+ func _check_class (Class_to_check : Resource ) -> bool :
684
+ # For now it's empty, need to complete it
685
+ return true
686
+
683
687
## Function to check if the return data is an error or not.[br]
684
688
## More precisely, it check if the data has the "error" key in it (if it is, it's an error).[br][br]
685
689
## Return:[br]
@@ -713,12 +717,12 @@ func has_item(key: String)->bool:
713
717
714
718
return rows .has (key )
715
719
716
- ## Return the data of the item.[br]
720
+ ## Return the data of the item as a dictionary object .[br]
717
721
## Emit: [signal item_getted] & [signal table_getted][br]
718
722
## [br]
719
723
## Here is an example of what you could get from it:[br]
720
724
## [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 :
722
726
723
727
if ! has_item (key ):
724
728
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:
736
740
737
741
return rows [key ]
738
742
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!\n You 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
+
739
777
## Add an item inside the datatable[br]
740
778
## Emit: [signal item_added] & [signal table_saved][br]
741
779
## [br]
@@ -899,3 +937,5 @@ func get_items_list()->Array:
899
937
var rows = _get_table_rows ()
900
938
901
939
return rows .keys ()
940
+
941
+
0 commit comments