@@ -421,6 +421,7 @@ static func _convert_string_to_basis(value: String) -> Basis:
421
421
422
422
# due to some unknown problem, the value after the dot (.0000) has some strange number added after it
423
423
# Tried multiple thing on it, but found nothing to fix the problem
424
+ # Found the reason, it's because of the binary representation of the float, so I need to round it to a certain number
424
425
static func _convert_string_to_proj (value : String ) -> Projection :
425
426
var convert : String = value
426
427
@@ -722,7 +723,7 @@ func has_item(key: String)->bool:
722
723
## [br]
723
724
## Here is an example of what you could get from it:[br]
724
725
## [codeblock]{ "a_string": "little string", "float_object": 0.3241, ..., "vector3 object": (0.1, 1, -5) }[/codeblock]
725
- func get_item_as_dict (key : String )-> Dictionary :
726
+ func get_item (key : String )-> Dictionary :
726
727
727
728
if ! has_item (key ):
728
729
var err = {"error" :str ("The table " ,_table_name ," doesn't contain the item '" ,key ,"' key!" )}
@@ -740,7 +741,11 @@ func get_item_as_dict(key: String)->Dictionary:
740
741
741
742
return rows [key ]
742
743
743
- func get_item (key : String )-> Structure :
744
+ ## Return the data of the item as a dictionary object.[br]
745
+ ## Emit: [signal item_getted] & [signal table_getted][br]
746
+ ## [br]
747
+ ## See [Structure] for more information about the global structure object, and check the generated class for more information about the specific object.
748
+ func get_item_as_object (key : String )-> Structure :
744
749
745
750
var struct_converted_name : String = _struct_name .replace (" " , "_" )
746
751
@@ -750,8 +755,6 @@ func get_item(key: String)->Structure:
750
755
push_error ("Can't return the item by the structure class, the structure_name is empty!" )
751
756
return null
752
757
753
- print (_dt_classDB .class_exist (className ))
754
-
755
758
if ! _dt_classDB .class_exist (className ):
756
759
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
760
return null
@@ -766,7 +769,7 @@ func get_item(key: String)->Structure:
766
769
push_error (str ("Can't return the item by the structure class, the class created is not valid!" ))
767
770
return null
768
771
769
- var _item = _classResource .new (get_item_as_dict (key ))
772
+ var _item = _classResource .new (get_item (key ))
770
773
771
774
if ! _item :
772
775
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?" ))
@@ -812,6 +815,13 @@ func add_item(item_key: String, item_data: Dictionary, save_data: bool = true)->
812
815
813
816
return true
814
817
818
+ ## Add an item inside the datatable[br]
819
+ ## Emit: [signal item_added] & [signal table_saved][br]
820
+ ## [br]
821
+ ## Be careful: All edit on the datatable will be saved inside the "datatable.res" if "save_data" arg is not on "false"!
822
+ func add_item_as_object (item_key : String , item : Structure , save_data : bool = true )-> bool :
823
+ return add_item (item_key , item ._get_dict (_struct_data ), save_data )
824
+
815
825
## Remove an item inside the datatable[br]
816
826
## Emit: [signal item_removed] & [signal table_saved][br]
817
827
## [br]
@@ -872,6 +882,13 @@ func set_item(item_key: String, item_data: Dictionary, save_data: bool = true)->
872
882
873
883
return true
874
884
885
+ ## Set an item inside the datatable[br]
886
+ ## Emit: [signal item_setted] & [signal table_saved][br]
887
+ ## [br]
888
+ ## Be careful: All edit on the datatable will be saved inside the "datatable.res" if "save_data" arg is not on "false"!
889
+ func set_item_as_object (item_key : String , item : Structure , save_data : bool = true )-> bool :
890
+ return set_item (item_key , item ._get_dict (_struct_data ), save_data )
891
+
875
892
## This function return you a dictionary that is pre-filled with the needed key for this table
876
893
func get_void_item ()-> Dictionary :
877
894
var data = {}
@@ -912,11 +929,37 @@ func get_void_item()->Dictionary:
912
929
913
930
return data
914
931
932
+ ## This function return you a the compatible object for the table
933
+ func get_void_item_as_object ()-> Structure :
934
+ var _class = _dt_classDB .class_instantiate ("struct_" + _struct_name .replace (" " , "_" ))
935
+
936
+ if ! _class :
937
+ push_error (str ("Can't create the void item as object, the class created is not valid!" ))
938
+ return null
939
+
940
+ if ! _check_class (_class ):
941
+ push_error (str ("Can't create the void item as object, the class created is not valid!" ))
942
+ return null
943
+
944
+ return _class .new (get_void_item ())
945
+
915
946
## Function to check if the given item is of the same structure as the table_name[br]
916
947
## [br]
917
948
## Return:[br]
918
949
## - True: The item can be added to the table[br]
919
- ## - False: The item can't be added to the table
950
+ ## - False: The item can't be added to the table[br]
951
+ ## [br]
952
+ ## Args:[br]
953
+ ## - item: The item that need to be checked[br]
954
+ ## [br]
955
+ ## Example:[br]
956
+ ## [codeblock]
957
+ ## var item = {"name": "sword", "damage": 10, "durability": 100}
958
+ ## if datatable.is_item_compatible(item):
959
+ ## print("The item is compatible with the table")
960
+ ## else:
961
+ ## print("The item is not compatible with the table")
962
+ ## [/codeblock]
920
963
func is_item_compatible (item : Dictionary )-> bool :
921
964
922
965
if ! _struct_data .has ('params' ):
@@ -931,11 +974,76 @@ func is_item_compatible(item: Dictionary)->bool:
931
974
932
975
return params .keys () == item .keys ()
933
976
934
- ## return all the KEY of items found in the table
977
+ ## Function to check if the given item is of the same structure as the table_name[br]
978
+ ## [br]
979
+ ## Return:[br]
980
+ ## - True: The item can be added to the table[br]
981
+ ## - False: The item can't be added to the table[br]
982
+ ## [br]
983
+ ## Args:[br]
984
+ ## - item: The item that need to be checked[br]
985
+ ## [br]
986
+ ## Example:[br]
987
+ ## We have a structure with the key "name", "damage" & "durability" named "items", we generated the class "struct_items" from it[br]
988
+ ## [codeblock]
989
+ ## var item = struct_items.new({"name": "sword", "damage": 10, "durability": 100})
990
+ ## if datatable.is_item_object_compatible(item):
991
+ ## print("The item is compatible with the table")
992
+ ## else:
993
+ ## print("The item is not compatible with the table")
994
+ ## [/codeblock]
995
+ func is_item_object_compatible (item : Structure )-> bool :
996
+ return is_item_compatible (item ._get_dict (_struct_data ))
997
+
998
+ ## return all the KEY of items found in the table[br]
999
+ ## Example: [br]
1000
+ ## We have a table with the item "sword", "axe", "bow", and we want to get all the key inside this table[br]
1001
+ ## [codeblock]
1002
+ ## var keys = datatable.get_items_list()
1003
+ ## print(keys) # ["sword", "axe", "bow"] - Will print all the key of the item in the table
1004
+ ##
1005
+ ## var swordValue = datatable.get_item("sword") # Get the item "sword" from the table
1006
+ ## print(swordValue) # Will print the item "sword" value
1007
+ ## [/codeblock]
935
1008
func get_items_list ()-> Array :
936
1009
937
1010
var rows = _get_table_rows ()
938
1011
939
1012
return rows .keys ()
940
1013
1014
+ ## Return the name of the rows of the table[br]
1015
+ ## Example: [br]
1016
+ ## We have a structure with the key "name", "damage" & "durability"[br]
1017
+ ## We have a table with the item "sword", "axe", "bow", and we want to get all the key inside this table[br]
1018
+ ## [codeblock]
1019
+ ## var keys = datatable.get_keys_list()
1020
+ ## print(keys) # ["name", "damage", "durability"] - Will print all the key of the structure used in the table
1021
+ ## [/codeblock]
1022
+ func get_keys_list ()-> Array :
1023
+
1024
+ var keys = []
1025
+
1026
+ for i in _struct_data ['params' ]:
1027
+ keys .append (i )
1028
+
1029
+ return keys
1030
+
1031
+ ## Return all the values linked to the key, the key need to be one of the key of the structure[br]
1032
+ ## Example: [br]
1033
+ ## We have a structure with the key "name", "damage" & "durability"[br]
1034
+ ## We have a table with the item "sword", "axe", "bow", and we want to get all the "name" key value[br]
1035
+ ## [codeblock]
1036
+ ## var names = datatable.get_value_of_key("name")
1037
+ ## print(names) # ["sword", "axe", "bow"] - Will print all the name of all the item in the table
1038
+ ## [/codeblock]
1039
+ func get_value_of_key (key : String ):
1040
+
1041
+ var rows = _get_table_rows ()
1042
+
1043
+ var values = []
941
1044
1045
+ for i in rows :
1046
+ if rows [i ].has (key ):
1047
+ values .append (rows [i ][key ])
1048
+
1049
+ return values
0 commit comments