Skip to content

Commit 4b13da4

Browse files
committed
Include data table addon.
1 parent 20b04c7 commit 4b13da4

File tree

176 files changed

+12320
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+12320
-5
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ mono_crash.*.json
1515

1616
.dist/
1717

18-
release*
18+
release*
19+
20+
datatable_backup/

addons/datatable_godot/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024-present Ward727
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

addons/datatable_godot/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# 💾Godot DataTable Plugin
2+
3+
A plugin that give you the ability to create datatable directly inside the editor.
4+
5+
### ![ ](https://raw.githubusercontent.com/Ward727a/godot_datatable_plugin/master/images/preview2.png)
6+
7+
If you got some suggestions (features, types, etc.), found a bug, or want to say something about it, [open an issue!](https://github.com/Ward727a/godot_datatable_plugin/issues) 🙂
8+
9+
[Download it on the Godot Asset store](https://godotengine.org/asset-library/asset/2986) or [on GitHub!](https://github.com/Ward727a/godot_datatable_plugin/releases/latest)
10+
11+
## ✨Features
12+
13+
- Nearly all types supported (int, string, Rect2, Vector4, Projection, etc.)
14+
15+
- A nice UI directly integrated within the editor
16+
17+
- A class that give you the ability to get, set or remove element inside a table
18+
19+
- An auto-update system (But you can choose to don't do the update if you want!)
20+
**Original Creator: [Nathanhoad for Godot Input Helper](https://github.com/nathanhoad/godot_input_helper/tree/main) under MIT License**
21+
22+
- The ability to create an element that is an array inside a table with other elements
23+
24+
- Complete class documentation with example and details
25+
26+
- All data are saved inside a [PackedDataContainer](https://docs.godotengine.org/en/stable/classes/class_packeddatacontainer.html) that allow you to serielizes them with ease!
27+
28+
- Collection system - A feature that allow you to create multiple datatable file for one project
29+
30+
- Setting a default value for each parameters of a structure
31+
32+
- Generate a base class from your structure
33+
34+
## 👨‍💻Upcoming Features
35+
36+
- The ability to link other table / table item inside another table
37+
38+
- Example project
39+
40+
- [And more!](https://github.com/users/Ward727a/projects/2)
41+
42+
- Want something and don't see it here? [Make an issue!](https://github.com/Ward727a/godot_datatable_plugin/issues)🙂
43+
44+
## ❔FAQ
45+
46+
#### Can I use C# with this plugin?
47+
48+
The C# is not actually supported, I will work on it if it's needed, but for now I want first to finish this plugin feature before maybe doing it. If needed, please [open an issue](https://github.com/Ward727a/godot_datatable_plugin/issues)
49+
50+
#### I created my table, and added elements in it, how can I access it?
51+
52+
You can access it by using the `Collection` class!
53+
54+
## ©License
55+
56+
This plugin is licensed under the MIT License, see [License](https://github.com/Ward727a/godot_datatable_plugin/blob/master/LICENSE) for more info.
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
extends Object
2+
class_name Collection
3+
##
4+
## This class is used for getting a collection of datatable.
5+
##
6+
## To get the collection, you need the path to your collection file (should end by ".tableCollection.res", or just ".res" if you use the old collection system)[br]
7+
## [br]
8+
## Example:
9+
## [codeblock]
10+
## func _ready():
11+
##
12+
## var collection: Collection = Collection.new("res://datatable.tableCollection.res")
13+
##
14+
## if !collection.has_table("myTable"): # Checking if the table exist
15+
## push_error("The table 'myTable' doesn't exist!")
16+
## return
17+
##
18+
## var datatable: Datatable = collection.get_table("myTable") # Getting the table with the name "myTable"
19+
##
20+
## if !datatable.has_item("myItem"): # Checking if the item exist inside the table "myTable"
21+
## push_error("The table 'myTable' doesn't have 'myItem' key!")
22+
## return
23+
##
24+
## var item: Dictionary = datatable.get_item("myItem") # Getting the item "myItem" inside "myTable"
25+
##
26+
## print(item) # print the result
27+
## [/codeblock]
28+
## [b]
29+
## You can copy a personalised template code for your own item / table by right clicking on your table / item
30+
## [/b]
31+
32+
var _collection_path: String
33+
34+
var _collection: Object
35+
36+
const _collection_required_key = ["table", "type"]
37+
38+
func _init(collection_path: String):
39+
40+
if !ResourceLoader.exists(collection_path, "PackedDataContainer"):
41+
assert(false, str("The path ", collection_path, " isn't an collection!"))
42+
43+
var collection = ResourceLoader.load(collection_path)
44+
45+
var required_key: int = 0
46+
47+
for i in collection:
48+
if _collection_required_key.has(i):
49+
required_key += 1
50+
51+
if required_key != _collection_required_key.size():
52+
assert(false, str("The path ", collection_path, " isn't a valid collection file! (missing key)"))
53+
54+
_collection = collection
55+
_collection_path = collection_path
56+
57+
## Get the table with the given name inside this collection
58+
func get_table(table_name: String) -> Datatable:
59+
60+
if has_table(table_name):
61+
var table = Datatable.new(_collection, table_name)
62+
63+
table.table_saved.connect(_on_save_collection)
64+
65+
return table
66+
67+
return null
68+
69+
## Check if the table exist inside this collection[br]
70+
## For your information: This function is called each time you try to get a table!
71+
func has_table(table_name: String) -> bool:
72+
73+
var data = _get_table_datas()
74+
75+
return data.has(table_name)
76+
77+
## Check if the structure exist inside this collection[br]
78+
## For your information: This function is called each time you try to get a structure!
79+
func has_struct(struct_name: String) -> bool:
80+
81+
var data = _get_table_structs()
82+
83+
return data.has(struct_name)
84+
85+
## Return the structure data.
86+
## [br]
87+
## You can use that to manually check the data that you can get from a table
88+
## Dictionary key:[br]
89+
## - name[br]
90+
## - params[br]
91+
## - params.[b](key)[/b].name[br]
92+
## - params.[b](key)[/b].size[br]
93+
## - params.[b](key)[/b].type[br]
94+
## [br]
95+
## Example:
96+
## [codeblock]
97+
## {
98+
## "name": "Simple structure",
99+
## "params": {
100+
## "A string": {
101+
## "name": "A String",
102+
## "size": 0,
103+
## "type": 0
104+
## },
105+
## "Lot of float": {
106+
## "name": "An array of float",
107+
## "size": 1,
108+
## "type": 2
109+
## }
110+
## }
111+
## }
112+
## [/codeblock]
113+
func get_struct(struct_name: String) -> Dictionary:
114+
115+
if has_struct(struct_name):
116+
return _get_table_structs()[struct_name]
117+
118+
return {"error": str("The structure ",struct_name," doesn't exist!")}
119+
120+
# Return the tables list of the datatable
121+
func _get_table_datas()->Dictionary:
122+
123+
var table_datas = {}
124+
125+
var packedData = _collection
126+
127+
var table_data = packedData['table']
128+
129+
for main_key in table_data:
130+
131+
var data = table_data[main_key]
132+
133+
table_datas[main_key] = {"size": data['size'], "structure": data['structure'], "rows": {}}
134+
135+
136+
for row_key in data['rows']:
137+
138+
var row_data = data['rows'][row_key] # name, columns
139+
140+
141+
table_datas[main_key]['rows'][row_key] = {}
142+
143+
144+
for column_key in row_data['columns']:
145+
146+
var column_data = row_data['columns'][column_key] # name, value, type
147+
148+
149+
# As the "size" object has been created after first release, we do a check so if the size
150+
# is not inside the data, we add it with the default value
151+
if column_data.size() == 3:
152+
column_data['size'] = Datatable.ItemSize.SIZE_SINGLE
153+
154+
if column_data['size'] == Datatable.ItemSize.SIZE_ARRAY:
155+
var arr_raw: String = column_data['value']
156+
157+
if arr_raw.begins_with(" ARR/ "):
158+
arr_raw = arr_raw.replace(" ARR/ ", "")
159+
160+
var arr: PackedStringArray = arr_raw.split(";")
161+
162+
var arr_value = []
163+
164+
if arr.size() == 1:
165+
if arr[0].is_empty():
166+
table_datas[main_key]['rows'][row_key][column_key] = arr_value
167+
continue
168+
169+
for item in arr:
170+
171+
var arr_item = Datatable._convert_complex_string_to_data(column_data["type"], item)
172+
173+
arr_value.append(arr_item)
174+
175+
table_datas[main_key]['rows'][row_key][column_key] = arr_value
176+
continue
177+
178+
table_datas[main_key]['rows'][row_key][column_key] = Datatable._convert_complex_string_to_data(column_data['type'], column_data['value'])
179+
180+
181+
return table_datas
182+
183+
# Return the structs list of the datatable
184+
func _get_table_structs()->Dictionary:
185+
186+
var table_types = {}
187+
188+
var packedData = _collection
189+
190+
var type_data = packedData['type']
191+
192+
for main_key in type_data: # name of type
193+
194+
var type = type_data[main_key]
195+
196+
197+
table_types[main_key] = {"name": type['name'], "params":{}}
198+
199+
for param_key in type['params']:
200+
201+
var param = type["params"][param_key]
202+
203+
204+
table_types[main_key]["params"][param_key] = {"name":param['name'], "type": param['type'], "size": param['size']}
205+
206+
return table_types
207+
208+
# response for the save_data signal emitted by the Datatable object
209+
func _on_save_collection(data:PackedDataContainer):
210+
211+
ResourceSaver.save(data, _collection_path)

0 commit comments

Comments
 (0)