Skip to content

Commit c97fbf5

Browse files
committed
v2.2.0
1 parent 5d7414f commit c97fbf5

File tree

5 files changed

+141
-11
lines changed

5 files changed

+141
-11
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ nv.file_system/
3636
test/test.tableCollection.res
3737
/datatable_backup
3838
/test
39+
/.vscode

addons/datatable_godot/class/class_datatable.gd

+115-7
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ static func _convert_string_to_basis(value: String) -> Basis:
421421

422422
# due to some unknown problem, the value after the dot (.0000) has some strange number added after it
423423
# 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
424425
static func _convert_string_to_proj(value: String) -> Projection:
425426
var convert : String = value
426427

@@ -722,7 +723,7 @@ func has_item(key: String)->bool:
722723
## [br]
723724
## Here is an example of what you could get from it:[br]
724725
## [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:
726727

727728
if !has_item(key):
728729
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:
740741

741742
return rows[key]
742743

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:
744749

745750
var struct_converted_name: String = _struct_name.replace(" ", "_")
746751

@@ -750,8 +755,6 @@ func get_item(key: String)->Structure:
750755
push_error("Can't return the item by the structure class, the structure_name is empty!")
751756
return null
752757

753-
print(_dt_classDB.class_exist(className))
754-
755758
if !_dt_classDB.class_exist(className):
756759
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!"))
757760
return null
@@ -766,7 +769,7 @@ func get_item(key: String)->Structure:
766769
push_error(str("Can't return the item by the structure class, the class created is not valid!"))
767770
return null
768771

769-
var _item = _classResource.new(get_item_as_dict(key))
772+
var _item = _classResource.new(get_item(key))
770773

771774
if !_item:
772775
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)->
812815

813816
return true
814817

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+
815825
## Remove an item inside the datatable[br]
816826
## Emit: [signal item_removed] & [signal table_saved][br]
817827
## [br]
@@ -872,6 +882,13 @@ func set_item(item_key: String, item_data: Dictionary, save_data: bool = true)->
872882

873883
return true
874884

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+
875892
## This function return you a dictionary that is pre-filled with the needed key for this table
876893
func get_void_item()->Dictionary:
877894
var data = {}
@@ -912,11 +929,37 @@ func get_void_item()->Dictionary:
912929

913930
return data
914931

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+
915946
## Function to check if the given item is of the same structure as the table_name[br]
916947
## [br]
917948
## Return:[br]
918949
## - 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]
920963
func is_item_compatible(item: Dictionary)->bool:
921964

922965
if !_struct_data.has('params'):
@@ -931,11 +974,76 @@ func is_item_compatible(item: Dictionary)->bool:
931974

932975
return params.keys() == item.keys()
933976

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]
9351008
func get_items_list()->Array:
9361009

9371010
var rows = _get_table_rows()
9381011

9391012
return rows.keys()
9401013

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 = []
9411044

1045+
for i in rows:
1046+
if rows[i].has(key):
1047+
values.append(rows[i][key])
1048+
1049+
return values
+22-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
extends Object
2-
## This class is for the DataTable Plugin, it's useless at the moment, I created it if I need it for the plugin in the futur
2+
## This class is for the DataTable Plugin pre-generated structure class code.
33
## [br]I discourage you to delete it, but do as you want!
44
##
55
## @experimental
66
class_name Structure
77

8+
func _get_dict(_structure: Dictionary):
9+
10+
var _data: Dictionary = {}
11+
12+
for i in get_property_list():
13+
if(i['name'].begins_with("_")):
14+
15+
var _name: String = i['name'].substr(1, i['name'].length() - 1)
16+
var _var_name: String
17+
18+
if _structure['params'].has(_name):
19+
if i['type'] == TYPE_OBJECT:
20+
if get(i['name']) == null:
21+
_data[_name] = "res://"
22+
else:
23+
if get(i['name']).get_class() == "Resource":
24+
_data[_name] = get(i['name']).get_path()
25+
26+
continue
27+
_data[_name] = get(i['name'])
28+
return _data

addons/datatable_godot/datatable.tscn

+2-2
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,12 @@ alignment = 2
356356

357357
[node name="version_status" type="RichTextLabel" parent="MarginContainer/bg_main/Panel/VBoxContainer/HBoxContainer/HBoxContainer3"]
358358
layout_mode = 2
359-
tooltip_text = "The plugin is check for an update..."
359+
tooltip_text = "You good to go, you got the last version available!"
360360
mouse_default_cursor_shape = 2
361361
theme_override_styles/focus = SubResource("StyleBoxFlat_w7rfg")
362362
theme_override_styles/normal = SubResource("StyleBoxFlat_w7rfg")
363363
bbcode_enabled = true
364-
text = "[img]res://addons/datatable_godot/icons/Reload.png[/img] Checking for update... "
364+
text = "[img]res://addons/datatable_godot/icons/StatusSuccess.png[/img] [color=lightgreen]Version up-to-date! "
365365
fit_content = true
366366
autowrap_mode = 0
367367
script = ExtResource("7_76wdw")

addons/datatable_godot/plugin.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name="DataTable"
33
description="A simple datatable system to use in godot"
44
author="Ward"
5-
version="2.1.0"
5+
version="2.2.0"
66
script="datatable.gd"
77

88
[update]

0 commit comments

Comments
 (0)