Replace godot_db_manager plugin with native DB, port lod plugin
godot_db_manager was incompatible with Godot 4 (used WindowDialog, Tabs, PopupPanel which were all removed). Replace with a minimal Database.gd that parses the same ahog.json format and exposes the same surface API (get_table_by_name, get_data_at_row_idx, edit_data, save_db, etc.) used by the M* model classes — no changes needed in MBase/MScene/MLevel/MSetting. Also port the lod plugin: fix class_name syntax (Godot 4 uses @icon separately from class_name extends) and Particles -> GPUParticles3D. Rewrite Global.gd async scene loading: the convert-3to4 tool mapped load_interactive -> load_threaded_request but those have different APIs (stage count, poll vs. status enum). Reimplement using the new load_threaded_get_status / load_threaded_get pair. Clean project.godot: drop the old _global_script_classes table (Godot 4 uses inline class_name declarations), remove gddb_* autoloads, and remove the godot_db_manager entry from editor_plugins. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Binary file not shown.
@@ -1,7 +0,0 @@
|
||||
[gd_resource type="FontFile" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/Roboto-Regular.ttf" type="FontFile" id=1]
|
||||
|
||||
[resource]
|
||||
size = 8
|
||||
font_data = ExtResource( 1 )
|
||||
@@ -1,7 +0,0 @@
|
||||
[gd_resource type="FontFile" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/Roboto-Regular.ttf" type="FontFile" id=1]
|
||||
|
||||
[resource]
|
||||
size = 10
|
||||
font_data = ExtResource( 1 )
|
||||
@@ -1,7 +0,0 @@
|
||||
[gd_resource type="FontFile" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/Roboto-Regular.ttf" type="FontFile" id=1]
|
||||
|
||||
[resource]
|
||||
size = 12
|
||||
font_data = ExtResource( 1 )
|
||||
@@ -1,7 +0,0 @@
|
||||
[gd_resource type="FontFile" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/Roboto-Regular.ttf" type="FontFile" id=1]
|
||||
|
||||
[resource]
|
||||
size = 14
|
||||
font_data = ExtResource( 1 )
|
||||
@@ -1,6 +0,0 @@
|
||||
[gd_resource type="FontFile" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/Roboto-Regular.ttf" type="FontFile" id=1]
|
||||
|
||||
[resource]
|
||||
font_data = ExtResource( 1 )
|
||||
@@ -1,7 +0,0 @@
|
||||
[gd_resource type="FontFile" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/Roboto-Regular.ttf" type="FontFile" id=1]
|
||||
|
||||
[resource]
|
||||
size = 18
|
||||
font_data = ExtResource( 1 )
|
||||
@@ -1,7 +0,0 @@
|
||||
[gd_resource type="FontFile" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/Roboto-Regular.ttf" type="FontFile" id=1]
|
||||
|
||||
[resource]
|
||||
size = 20
|
||||
font_data = ExtResource( 1 )
|
||||
@@ -1,7 +0,0 @@
|
||||
[gd_resource type="FontFile" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/Roboto-Regular.ttf" type="FontFile" id=1]
|
||||
|
||||
[resource]
|
||||
size = 22
|
||||
font_data = ExtResource( 1 )
|
||||
@@ -1,7 +0,0 @@
|
||||
[gd_resource type="FontFile" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/Roboto-Regular.ttf" type="FontFile" id=1]
|
||||
|
||||
[resource]
|
||||
size = 24
|
||||
font_data = ExtResource( 1 )
|
||||
@@ -1,7 +0,0 @@
|
||||
[gd_resource type="FontFile" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/Roboto-Regular.ttf" type="FontFile" id=1]
|
||||
|
||||
[resource]
|
||||
size = 26
|
||||
font_data = ExtResource( 1 )
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 KiB |
@@ -1,34 +0,0 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/debug.png-72578d6223132f8bc16d1922f9da1248.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/godot_db_manager/assets/tex/debug.png"
|
||||
dest_files=[ "res://.import/debug.png-72578d6223132f8bc16d1922f9da1248.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 6.7 KiB |
@@ -1,34 +0,0 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/gui.png-1d6d47ba1ecd00882b63b6f57f502e61.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/godot_db_manager/assets/tex/gui.png"
|
||||
dest_files=[ "res://.import/gui.png-1d6d47ba1ecd00882b63b6f57f502e61.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
@@ -1,38 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBConstants
|
||||
"""
|
||||
|
||||
class_name GDDBConstants
|
||||
|
||||
extends Node
|
||||
|
||||
# GDDB signature
|
||||
const c_gddb_signature = "GDDB_ver"
|
||||
|
||||
# GDDB ver
|
||||
const c_gddb_ver = "2.0"
|
||||
|
||||
# invalid id to initialize integer properties
|
||||
const c_invalid_id = -1
|
||||
|
||||
# maximum database name length
|
||||
const c_max_db_name_len = 16
|
||||
|
||||
# maximum table name length
|
||||
const c_max_table_name_len = 16
|
||||
|
||||
# characters that should not be part of the database name
|
||||
const c_invalid_characters = "`~!@#$%^&*()=+[]{}\\|;:'\",<.>/?"
|
||||
|
||||
# addon main path
|
||||
const c_addon_main_path = "res://addons/godot_db_manager/"
|
||||
|
||||
# maximum tables list width
|
||||
const c_max_tables_list_width = 400.0
|
||||
|
||||
# minimum cell width
|
||||
const c_min_cell_width = 150.0
|
||||
|
||||
# maximum cell width
|
||||
const c_max_cell_width = 400.0
|
||||
@@ -1,96 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBGlobals
|
||||
"""
|
||||
|
||||
class_name GDDBGlobals
|
||||
|
||||
extends Node
|
||||
|
||||
# a flag that tells if the tool's interface is active or not
|
||||
var m_is_interface_active : bool = false
|
||||
|
||||
# sets the active flag
|
||||
func set_interface_active(active : bool) -> void :
|
||||
m_is_interface_active = active
|
||||
|
||||
# returns true if the tool's interface is active
|
||||
func is_interface_active() -> bool :
|
||||
return m_is_interface_active
|
||||
|
||||
# returns the name of the data type
|
||||
func get_data_name(data_type : int) -> String :
|
||||
if(data_type == gddb_types.e_prop_type_bool):
|
||||
return "Bool"
|
||||
elif(data_type == gddb_types.e_prop_type_int):
|
||||
return "Integer"
|
||||
elif(data_type == gddb_types.e_prop_type_float):
|
||||
return "Float"
|
||||
elif(data_type == gddb_types.e_prop_type_string):
|
||||
return "String"
|
||||
elif(data_type == gddb_types.e_prop_type_resource):
|
||||
return "Resource"
|
||||
|
||||
print("GDDBGlobals::get_data_name(" + str(data_type) + ")")
|
||||
return "Unknown data type"
|
||||
|
||||
# returns the name of the data filter
|
||||
func get_data_filter_name(data_filter_type : int) -> String :
|
||||
if(data_filter_type == gddb_types.e_data_filter_equal):
|
||||
return "Equal"
|
||||
elif(data_filter_type == gddb_types.e_data_filter_not_equal):
|
||||
return "Not equal"
|
||||
elif(data_filter_type == gddb_types.e_data_filter_less):
|
||||
return "Less"
|
||||
elif(data_filter_type == gddb_types.e_data_filter_greater):
|
||||
return "Greater"
|
||||
elif(data_filter_type == gddb_types.e_data_filter_lequal):
|
||||
return "Less or equal"
|
||||
elif(data_filter_type == gddb_types.e_data_filter_gequal):
|
||||
return "Greater or equal"
|
||||
|
||||
print("GDDBGlobals::get_data_filter_name(" + str(data_filter_type) + ")")
|
||||
return "Unknown data filter type"
|
||||
|
||||
# checks the name of the database
|
||||
func check_db_name(db_name : String) -> bool :
|
||||
for idx in range(0, db_name.length()):
|
||||
for jdx in range(0, gddb_constants.c_invalid_characters.length()):
|
||||
if(db_name[idx] == gddb_constants.c_invalid_characters[jdx]):
|
||||
return false
|
||||
return true
|
||||
|
||||
# returns a json from a row from a table
|
||||
func get_json_from_row(table : Object, row_idx : int) -> String :
|
||||
var json = "{"
|
||||
var row = table.get_data_at_row_idx(row_idx)
|
||||
for jdx in range(0, row.size()):
|
||||
var prop = table.get_prop_at(jdx)
|
||||
json += "\"" + prop.get_prop_name() + "\":"
|
||||
json += "\"" + row[jdx].get_data() + "\""
|
||||
if(jdx < row.size() - 1):
|
||||
json += ", "
|
||||
json += "}"
|
||||
return json
|
||||
|
||||
# returns the digits count from a number
|
||||
func get_digits_count(number : int) -> int :
|
||||
if(number == 0):
|
||||
return 1
|
||||
|
||||
var digits_count = 0
|
||||
while(number > 0):
|
||||
number /= 10
|
||||
digits_count += 1
|
||||
|
||||
return digits_count
|
||||
|
||||
# replace special characters in a string to handle properly saving into database
|
||||
func handle_string(text : String) -> String :
|
||||
var string = ""
|
||||
for idx in range(0, text.length()):
|
||||
if(text[idx] == "\n"):
|
||||
string += "\\n"
|
||||
else:
|
||||
string += text[idx]
|
||||
return string
|
||||
@@ -1,45 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBTypes
|
||||
"""
|
||||
|
||||
class_name GDDBTypes
|
||||
|
||||
extends Node
|
||||
|
||||
# Database loading errors
|
||||
enum {
|
||||
e_db_invalid_file = -11,
|
||||
e_db_invalid_ver = -10,
|
||||
e_db_valid = 0
|
||||
}
|
||||
|
||||
# Property types
|
||||
enum {
|
||||
e_prop_type_bool = 0
|
||||
e_prop_type_int = 1,
|
||||
e_prop_type_float = 2,
|
||||
e_prop_type_string = 3,
|
||||
|
||||
# TODO: insert more data types here and increase e_prop_type_resource
|
||||
|
||||
e_prop_type_resource = 4,
|
||||
|
||||
e_prop_types_count
|
||||
}
|
||||
|
||||
# Data filters
|
||||
enum {
|
||||
e_data_filter_equal = 0,
|
||||
e_data_filter_not_equal = 1,
|
||||
e_data_filter_less = 2,
|
||||
e_data_filter_greater = 3,
|
||||
e_data_filter_lequal = 4, # less or equal
|
||||
e_data_filter_gequal = 5 # greater or equal
|
||||
}
|
||||
|
||||
# new table dlg type
|
||||
enum {
|
||||
e_new_dlg_type_new = 0,
|
||||
e_new_dlg_type_edit = 1
|
||||
}
|
||||
@@ -1,325 +0,0 @@
|
||||
"""
|
||||
GDDatabase class
|
||||
"""
|
||||
|
||||
class_name GDDatabase
|
||||
|
||||
extends Object
|
||||
|
||||
# database types
|
||||
enum {
|
||||
e_db_type_json = 0, # JSON database
|
||||
e_db_type_binary = 1 # binary database - to be designed / implemented
|
||||
}
|
||||
|
||||
# database type
|
||||
var m_db_type : int = e_db_type_json
|
||||
|
||||
# the id of the database
|
||||
var m_db_id : int = gddb_constants.c_invalid_id
|
||||
|
||||
# the name of the database
|
||||
var m_db_name : String = ""
|
||||
|
||||
# tables in the database
|
||||
var m_tables : Array = []
|
||||
|
||||
# the path of the database
|
||||
var m_db_filepath : String = ""
|
||||
|
||||
# if the database is not saved, it is dirty
|
||||
var m_is_dirty : bool = false
|
||||
|
||||
# sets the id of the database
|
||||
func set_db_id(db_id : int) -> void :
|
||||
m_db_id = db_id
|
||||
|
||||
# returns the database id
|
||||
func get_db_id() -> int :
|
||||
return m_db_id
|
||||
|
||||
# set the name of the database
|
||||
# the name of the database should not contain special characters
|
||||
func set_db_name(db_name : String) -> bool :
|
||||
if(!gddb_globals.check_db_name(db_name)):
|
||||
print("ERROR: GDDatabase::set_db_name(" + db_name + ") - the name of the database contains invalid characters")
|
||||
return false
|
||||
# print("GDDatabase::set_db_name(" + db_name + ")")
|
||||
m_db_name = db_name
|
||||
return true
|
||||
|
||||
# returns the name of the database
|
||||
func get_db_name() -> String :
|
||||
return m_db_name
|
||||
|
||||
# sets the database file path
|
||||
func set_db_filepath(filepath : String) -> void :
|
||||
m_db_filepath = filepath
|
||||
|
||||
# returns the path of the database
|
||||
func get_db_filepath() -> String :
|
||||
return m_db_filepath
|
||||
|
||||
# checks if a table with the name "table_name" can be added into database
|
||||
func can_add_table(table_name : String, table_id : int = -1) -> bool :
|
||||
# print("GDDatabase::can_add_table(" + table_name + ", " + str(table_id) + ")")
|
||||
for idx in range(0, m_tables.size()):
|
||||
if(m_tables[idx].get_table_name() == table_name):
|
||||
if(m_tables[idx].get_table_id() == table_id):
|
||||
continue
|
||||
print("WARNING: GDDatabase::can_add_table(" + table_name + ", " + str(table_id) + ") - table already exists")
|
||||
return false
|
||||
return true
|
||||
|
||||
# adds a new table
|
||||
# returns the table id; if already exists, it will fire an warning on output console and returns an invalid id
|
||||
func add_table(table_name : String) -> int :
|
||||
if(!can_add_table(table_name)):
|
||||
print("WARNING: GDDatabase::add_table(" + table_name + ") - cannot add table")
|
||||
return gddb_constants.c_invalid_id
|
||||
|
||||
# print("GDDatabase::add_table(" + table_name + ") to \"" + m_db_name + "\" database")
|
||||
|
||||
var table_id = generate_new_table_id()
|
||||
var table = load(gddb_constants.c_addon_main_path + "core/db_table.gd").new()
|
||||
table.set_table_id(table_id)
|
||||
table.set_table_name(table_name)
|
||||
table.set_parent_database(self)
|
||||
m_tables.push_back(table)
|
||||
return table_id
|
||||
|
||||
# edits a table name
|
||||
func edit_table_name(table_name : String, table_id : int) -> bool :
|
||||
if(!can_add_table(table_name, table_id)):
|
||||
return false
|
||||
for idx in range(0, m_tables.size()):
|
||||
if(m_tables[idx].get_table_id() == table_id):
|
||||
m_tables[idx].set_table_name(table_name)
|
||||
break
|
||||
return true
|
||||
|
||||
# deletes a table at index
|
||||
func delete_table_at(idx : int) -> void :
|
||||
if(idx < 0 || idx > m_tables.size() - 1):
|
||||
print("GDDatabase::delete_table_at(" + str(idx) + ") - index out of bounds")
|
||||
return
|
||||
m_tables[idx].clear()
|
||||
m_tables[idx].free()
|
||||
m_tables.remove(idx)
|
||||
|
||||
# deletes a table by id
|
||||
func delete_table_by_id(table_id: int) -> void :
|
||||
for idx in range(0, m_tables.size()):
|
||||
if(m_tables[idx].get_table_id() == table_id):
|
||||
# print("GDDatabase::delete_table_by_id(" + str(table_id) + ")")
|
||||
m_tables[idx].clear()
|
||||
m_tables[idx].free()
|
||||
m_tables.remove(idx)
|
||||
return
|
||||
print("ERROR: GDDatabase::delete_table_by_id(" + str(table_id) + ") - cannot erase table; id not found")
|
||||
|
||||
# deletes a table by name
|
||||
func delete_table_by_name(table_name: String) -> void :
|
||||
for idx in range(0, m_tables.size()):
|
||||
if(m_tables[idx].get_table_name() == table_name):
|
||||
# print("GDDatabase::delete_table_by_name(" + table_name + ")")
|
||||
m_tables[idx].clear()
|
||||
m_tables[idx].free()
|
||||
m_tables.remove(idx)
|
||||
return
|
||||
print("ERROR: GDDatabase::delete_table_by_name(" + table_name + ") - cannot erase table; name not found")
|
||||
|
||||
# generates a new table id
|
||||
func generate_new_table_id() -> int :
|
||||
if(m_tables.size() == 0):
|
||||
return 0
|
||||
return m_tables[m_tables.size()-1].get_table_id() + 1
|
||||
|
||||
# returns the count of the tables in the database
|
||||
func get_tables_count() -> int :
|
||||
return m_tables.size()
|
||||
|
||||
# returns true if the table exists in the database, false otherwise
|
||||
# this is equivalent with (get_table_by_name(table name) != null) function, but without firing the error in case the table doesn't exist
|
||||
func is_table_exists(table_name : String) -> bool :
|
||||
for idx in range(0, m_tables.size()):
|
||||
if(m_tables[idx].get_table_name() == table_name):
|
||||
return true
|
||||
return false
|
||||
|
||||
# returns a table by an index or null if the index is invalid
|
||||
func get_table_at(idx: int) -> Object :
|
||||
if(idx < 0 || idx >= m_tables.size()):
|
||||
print("ERROR: GDDatabase::get_table_at(" + str(idx) + ") - cannot obtain table with index")
|
||||
return null
|
||||
return m_tables[idx]
|
||||
|
||||
# returns a table by its id or null if a table with id doesn's exist
|
||||
func get_table_by_id(table_id: int) -> Object :
|
||||
for idx in range(0, m_tables.size()):
|
||||
if(m_tables[idx].get_table_id() == table_id):
|
||||
return m_tables[idx]
|
||||
print("ERROR: GDDatabase::get_table_by_id(" + str(table_id) + ") - cannot obtain table with id")
|
||||
return null
|
||||
|
||||
# returns a table by its name or null if the name of the table doesn's exist
|
||||
func get_table_by_name(table_name: String) -> Object :
|
||||
for idx in range(0, m_tables.size()):
|
||||
if(m_tables[idx].get_table_name() == table_name):
|
||||
return m_tables[idx]
|
||||
print("ERROR: GDDatabase::get_table_by_id(" + table_name + ") - cannot obtain table with name")
|
||||
return null
|
||||
|
||||
# deletes all the tables
|
||||
func clear() -> void :
|
||||
# print("GDDatabase::clear()")
|
||||
m_db_name = ""
|
||||
for idx in range(0, m_tables.size()):
|
||||
m_tables[idx].clear()
|
||||
m_tables.clear()
|
||||
|
||||
# sets the database dirty; it is not saved
|
||||
func set_dirty(dirty : bool) -> void :
|
||||
m_is_dirty = dirty
|
||||
|
||||
# returns true if a database is dirty (should be saved), false otherwise
|
||||
func is_dirty() -> bool :
|
||||
return m_is_dirty
|
||||
|
||||
# serialization
|
||||
func save_db() -> void :
|
||||
if(m_db_name.is_empty()):
|
||||
print("ERROR: GDDatabase::save_db() - current database doesn't have a name")
|
||||
return
|
||||
|
||||
if(m_db_filepath.is_empty()):
|
||||
print("ERROR: GDDatabase::save_db() - current database doesn't have a path file")
|
||||
return
|
||||
|
||||
# print("GDDatabase::save_db() - " + m_db_name + " to: " + m_db_filepath)
|
||||
var text = "{"
|
||||
text += "\n\t\"" + gddb_constants.c_gddb_signature + "\":\"" + gddb_constants.c_gddb_ver + "\","
|
||||
text += "\n\t\"db_name\":\"" + m_db_name + "\","
|
||||
text += "\n\t\"tables\":["
|
||||
for idx in range(0, m_tables.size()):
|
||||
text += "\n\t\t{"
|
||||
text += "\n\t\t\t\"table_name\":\"" + m_tables[idx].get_table_name() + "\","
|
||||
text += "\n\t\t\t\"props\":["
|
||||
for jdx in range(0, m_tables[idx].get_props_count()):
|
||||
var db_prop = m_tables[idx].get_prop_at(jdx)
|
||||
text += "\n\t\t\t\t\t{"
|
||||
text += "\"name\":\"" + str(db_prop.get_prop_name()) + "\","
|
||||
|
||||
var prop_type = db_prop.get_prop_type()
|
||||
if(prop_type < gddb_types.e_prop_types_count):
|
||||
text += "\"type\":\"" + str(prop_type) + "\","
|
||||
else:
|
||||
# print("GDDatabase::save_db() - prop_type: " + str(prop_type))
|
||||
var table_id = prop_type - gddb_types.e_prop_types_count
|
||||
var table = get_table_by_id(table_id)
|
||||
if(null == table):
|
||||
print("GDDatabase::save_db() - table not found with id: " + str(table_id))
|
||||
text += "\"type\":\"" + "table" + "\","
|
||||
text += "\"table_name\":\"" + table.get_table_name() + "\","
|
||||
|
||||
text += "\"auto_increment\":\"" + str(int(db_prop.has_autoincrement())) + "\""
|
||||
|
||||
text += "}"
|
||||
if(jdx < m_tables[idx].get_props_count() - 1):
|
||||
text += ","
|
||||
text += "\n\t\t\t],"
|
||||
|
||||
text += "\n\t\t\t\"data\":["
|
||||
for jdx in range(0, m_tables[idx].get_data_size()):
|
||||
#var the_data = m_tables[idx].get_data_at(jdx)
|
||||
#print("getting data at " + str(jdx) + " : " + the_data)
|
||||
text += "\"" + m_tables[idx].get_data_at(jdx) + "\""
|
||||
if(jdx < m_tables[idx].get_data_size() - 1):
|
||||
text += ","
|
||||
text += "]" # end of data
|
||||
text += "\n\t\t}" # end of table
|
||||
|
||||
if(idx < m_tables.size() - 1):
|
||||
text += ","
|
||||
|
||||
text += "\n\t]\n}"
|
||||
|
||||
var save_file = File.new()
|
||||
save_file.open(m_db_filepath, File.WRITE)
|
||||
save_file.store_string(text)
|
||||
save_file.close()
|
||||
|
||||
set_dirty(false)
|
||||
|
||||
# deserialization
|
||||
func load_db() -> int :
|
||||
var file = File.new()
|
||||
file.open(get_db_filepath(), File.READ)
|
||||
var content = file.get_as_text()
|
||||
file.close()
|
||||
var test_json_conv = JSON.new()
|
||||
test_json_conv.parse(content).result
|
||||
var dictionary = test_json_conv.get_data()
|
||||
|
||||
# check the signature
|
||||
if(!dictionary.has(gddb_constants.c_gddb_signature)):
|
||||
print("GDDatabase::load_db() - invalid database file")
|
||||
return gddb_types.e_db_invalid_file
|
||||
|
||||
var gddb_signature = dictionary[gddb_constants.c_gddb_signature]
|
||||
if(gddb_signature != gddb_constants.c_gddb_ver):
|
||||
print("GDDatabase::load_db() - invalid database version")
|
||||
return gddb_types.e_db_invalid_ver
|
||||
|
||||
clear()
|
||||
m_db_name = dictionary["db_name"]
|
||||
var tables = dictionary["tables"]
|
||||
for idx in range(0, tables.size()):
|
||||
var table_id = add_table(tables[idx]["table_name"])
|
||||
var table = get_table_by_id(table_id)
|
||||
|
||||
var props_count = tables[idx]["props"].size()
|
||||
if(props_count == 0):
|
||||
continue
|
||||
|
||||
for jdx in range(0, props_count):
|
||||
var prop_type = tables[idx]["props"][jdx]["type"]
|
||||
|
||||
var prop_id = -1
|
||||
if(prop_type == "table"):
|
||||
var table_name = tables[idx]["props"][jdx]["table_name"]
|
||||
prop_id = table.add_table_prop(tables[idx]["props"][jdx]["name"], table_name)
|
||||
else:
|
||||
prop_id = table.add_prop(prop_type.to_int(), tables[idx]["props"][jdx]["name"])
|
||||
|
||||
var prop = table.get_prop_by_id(prop_id)
|
||||
var enable_autoincrement = tables[idx]["props"][jdx]["auto_increment"].to_int()
|
||||
prop.enable_autoincrement(bool(enable_autoincrement))
|
||||
|
||||
var data_count = tables[idx]["data"].size()
|
||||
#print("********* set data to db - begin")
|
||||
for jdx in range(0, data_count / props_count):
|
||||
var row_data = []
|
||||
for kdx in range(0, props_count):
|
||||
var cell_data = tables[idx]["data"][jdx * props_count + kdx]
|
||||
# print("cell_data: " + cell_data)
|
||||
row_data.push_back(cell_data)
|
||||
#print("row_data: " + str(row_data))
|
||||
table.add_row(row_data)
|
||||
#print("********* set data to db - end")
|
||||
|
||||
# link custom data to tables
|
||||
for idx in range(0, m_tables.size()):
|
||||
m_tables[idx].link_tables_props()
|
||||
|
||||
return gddb_types.e_db_valid
|
||||
|
||||
# dumps the database
|
||||
func dump() -> String :
|
||||
var dump_text = "\nDatabase dump. id: " + str(m_db_id) + ", name: " + m_db_name + ", filepath: " + m_db_filepath
|
||||
dump_text += "\n------------------------------------------------------------------------------------\n"
|
||||
|
||||
for idx in range(0, m_tables.size()):
|
||||
dump_text += "\n" + m_tables[idx].dump()
|
||||
|
||||
return dump_text
|
||||
@@ -1,40 +0,0 @@
|
||||
"""
|
||||
GDDBData class
|
||||
"""
|
||||
|
||||
class_name GDDBData
|
||||
|
||||
extends Object
|
||||
|
||||
var m_prop_id : int = -1
|
||||
var m_row_idx : int = -1
|
||||
var m_data : String = ""
|
||||
|
||||
# sets the property id
|
||||
func set_prop_id(prop_id : int) -> void :
|
||||
m_prop_id = prop_id
|
||||
|
||||
# returns the property id
|
||||
func get_prop_id() -> int :
|
||||
return m_prop_id
|
||||
|
||||
# sets the row index
|
||||
func set_row_idx(row_idx : int) -> void :
|
||||
m_row_idx = row_idx
|
||||
|
||||
# returns the row index
|
||||
func get_row_idx() -> int :
|
||||
return m_row_idx
|
||||
|
||||
# sets the data
|
||||
func set_data(data : String) -> void :
|
||||
m_data = data
|
||||
|
||||
# returns the data
|
||||
func get_data() -> String :
|
||||
return m_data
|
||||
|
||||
# dumps the data
|
||||
func dump() -> String :
|
||||
var dump_text = "prop_id: " + str(m_prop_id) + ", row_idx: " + str(m_row_idx) + ", data: " + m_data
|
||||
return dump_text
|
||||
@@ -1,141 +0,0 @@
|
||||
"""
|
||||
GDDBMan class
|
||||
"""
|
||||
|
||||
class_name GDDBMan
|
||||
|
||||
extends Object
|
||||
|
||||
var m_databases = []
|
||||
|
||||
# adds a database
|
||||
func add_database(db_name : String) -> int :
|
||||
if(!can_add_db(db_name)):
|
||||
print("ERROR: GDDBMan::add_database(" + db_name + ") already exists")
|
||||
return gddb_constants.c_invalid_id
|
||||
# print("GDDBMan::add_database(" + db_name + ")")
|
||||
var db_id = generate_new_db_id()
|
||||
var db = load(gddb_constants.c_addon_main_path + "core/database.gd").new()
|
||||
db.set_db_id(db_id)
|
||||
db.set_db_name(db_name)
|
||||
m_databases.push_back(db)
|
||||
return db_id
|
||||
|
||||
# loads a database from a file
|
||||
func load_database(filepath : String) -> int :
|
||||
var db_id = generate_new_db_id()
|
||||
var db = load(gddb_constants.c_addon_main_path + "core/database.gd").new()
|
||||
db.set_db_id(db_id)
|
||||
db.set_db_filepath(filepath)
|
||||
|
||||
if(db.load_db() == gddb_types.e_db_invalid_file):
|
||||
db.free()
|
||||
return gddb_types.e_db_invalid_file
|
||||
|
||||
elif(db.load_db() == gddb_types.e_db_invalid_ver):
|
||||
db.free()
|
||||
return gddb_types.e_db_invalid_ver
|
||||
|
||||
m_databases.push_back(db)
|
||||
return db_id
|
||||
|
||||
# erases a database at index
|
||||
# it does not erase the database file
|
||||
func erase_db_at(idx : int) -> void :
|
||||
if(idx < 0 || idx > m_databases.size() - 1):
|
||||
print("ERROR: GDDBMan::erase_db_at(" + str(idx) + ") - index out of bounds")
|
||||
|
||||
m_databases[idx].clear()
|
||||
m_databases[idx].free()
|
||||
m_databases.remove(idx)
|
||||
|
||||
# erases a database by id
|
||||
# it does not erase the database file
|
||||
func erase_db_by_id(db_id : int) -> void :
|
||||
var db_found = false
|
||||
for idx in range(0, m_databases.size()):
|
||||
if(m_databases[idx].get_db_id() == db_id):
|
||||
m_databases[idx].clear()
|
||||
m_databases[idx].free()
|
||||
m_databases.remove(idx)
|
||||
db_found = true
|
||||
break
|
||||
|
||||
if(!db_found):
|
||||
print("ERROR: GDDBMan::erase_db_by_id(" + str(db_id) + ") - database not found")
|
||||
|
||||
# erases a database by name
|
||||
# it does not erase the database file
|
||||
func erase_db_by_name(db_name : String) -> void :
|
||||
var db_found = false
|
||||
for idx in range(0, m_databases.size()):
|
||||
if(m_databases[idx].get_db_name() == db_name):
|
||||
m_databases[idx].clear()
|
||||
m_databases[idx].free()
|
||||
m_databases.remove(idx)
|
||||
db_found = true
|
||||
break
|
||||
|
||||
if(!db_found):
|
||||
print("ERROR: GDDBMan::erase_db_by_id(" + db_name + ") - database not found")
|
||||
|
||||
# returns the databases count
|
||||
func get_databases_count() -> int :
|
||||
return m_databases.size()
|
||||
|
||||
# returns a database at index
|
||||
func get_db_at(idx : int) -> Object :
|
||||
if(idx < 0 || idx >= m_databases.size()):
|
||||
print("ERROR: GDDBMan::get_db_at(" + str(idx) + ") - invalid index")
|
||||
return null
|
||||
return m_databases[idx]
|
||||
|
||||
# returns a database by an id
|
||||
func get_db_by_id(db_id : int) -> Object :
|
||||
for idx in range(0, m_databases.size()):
|
||||
if(m_databases[idx].get_db_id() == db_id):
|
||||
return m_databases[idx]
|
||||
print("ERROR: GDDBMan::get_db_by_id(" + str(db_id) + ") - invalid id")
|
||||
return null
|
||||
|
||||
# returns a database by a name
|
||||
func get_db_by_name(db_name : String) -> Object :
|
||||
for idx in range(0, m_databases.size()):
|
||||
if(m_databases[idx].get_db_name() == db_name):
|
||||
return m_databases[idx]
|
||||
return null
|
||||
|
||||
# generates a new table id
|
||||
func generate_new_db_id() -> int :
|
||||
if(m_databases.size() == 0):
|
||||
return 0
|
||||
return m_databases[m_databases.size()-1].get_db_id() + 1
|
||||
|
||||
# checks if a database already exists
|
||||
func can_add_db(db_name : String) -> bool :
|
||||
for idx in range(0, m_databases.size()):
|
||||
if(m_databases[idx].get_db_name() == db_name):
|
||||
print("ERROR: Database with name \"" + db_name + "\" already exists")
|
||||
return false
|
||||
return true
|
||||
|
||||
# deletes all databases
|
||||
func clear() -> void :
|
||||
for idx in range(0, m_databases.size()):
|
||||
m_databases[idx].clear()
|
||||
m_databases[idx].free()
|
||||
m_databases.clear()
|
||||
|
||||
# dumps all databases
|
||||
func dump(to_console : bool = false) -> String :
|
||||
var dump_text = "\nDatabase manager - dump"
|
||||
|
||||
dump_text += "\n===================================================================================="
|
||||
for idx in range(0, m_databases.size()):
|
||||
dump_text += m_databases[idx].dump()
|
||||
dump_text += "===================================================================================="
|
||||
|
||||
if(to_console):
|
||||
print(dump_text)
|
||||
|
||||
return dump_text
|
||||
@@ -1,71 +0,0 @@
|
||||
"""
|
||||
GDDBProperty class
|
||||
"""
|
||||
|
||||
class_name GDDBProperty
|
||||
|
||||
extends Object
|
||||
|
||||
var m_prop_id : int = -1
|
||||
var m_prop_type : int = gddb_types.e_prop_type_int
|
||||
var m_custom_type : String = ""
|
||||
var m_prop_name : String = ""
|
||||
|
||||
var m_autoincrement : bool = false
|
||||
|
||||
# sets the property id
|
||||
func set_prop_id(prop_id : int) -> void :
|
||||
m_prop_id = prop_id
|
||||
|
||||
# returns the property id
|
||||
func get_prop_id() -> int :
|
||||
return m_prop_id
|
||||
|
||||
# sets the property type
|
||||
func set_prop_type(prop_type : int) -> void :
|
||||
m_prop_type = prop_type
|
||||
|
||||
# returns the property type
|
||||
func get_prop_type() -> int :
|
||||
return m_prop_type
|
||||
|
||||
# sets the custom type
|
||||
func set_prop_custom_type(prop_type : String) -> void :
|
||||
m_custom_type = prop_type
|
||||
|
||||
# returns the custom type
|
||||
func get_prop_custom_type() -> String :
|
||||
return m_custom_type
|
||||
|
||||
# sets the property name
|
||||
func set_prop_name(prop_name : String) -> void :
|
||||
m_prop_name = prop_name
|
||||
|
||||
# returns the property name
|
||||
func get_prop_name() -> String :
|
||||
return m_prop_name
|
||||
|
||||
# enables or disables the auto increment property
|
||||
func enable_autoincrement(enable : bool) -> void :
|
||||
if(enable && m_prop_type != gddb_types.e_prop_type_int):
|
||||
if(m_prop_type < gddb_types.e_prop_types_count):
|
||||
print("ERROR: autoincrement option can be set to integer data type only. Type is: " + gddb_types.get_data_name(m_prop_type))
|
||||
else:
|
||||
print("ERROR: autoincrement option can be set to integer data type only. Custom type is: " + m_custom_type)
|
||||
return
|
||||
m_autoincrement = enable
|
||||
|
||||
# returns if the property has auto increment
|
||||
func has_autoincrement() -> bool :
|
||||
return m_autoincrement
|
||||
|
||||
# dumps the property
|
||||
func dump() -> String :
|
||||
var dump_text = "prop_id: " + str(m_prop_id) + ", prop_name: " + m_prop_name
|
||||
|
||||
if(m_prop_type <= gddb_types.e_prop_type_resource):
|
||||
dump_text += ", prop_type: " + gddb_globals.get_data_name(m_prop_type)
|
||||
else:
|
||||
dump_text += ", custom_prop_type: " + m_custom_type
|
||||
|
||||
return dump_text
|
||||
@@ -1,574 +0,0 @@
|
||||
"""
|
||||
GDDBTable class
|
||||
"""
|
||||
|
||||
class_name GDDBTable
|
||||
|
||||
extends Object
|
||||
|
||||
var m_table_id : int = gddb_constants.c_invalid_id
|
||||
var m_table_name : String = ""
|
||||
var m_props : Array = []
|
||||
var m_data : Array = []
|
||||
var m_rows_count : int = 0
|
||||
|
||||
var m_parent_database : Object = null
|
||||
|
||||
# sets the table id
|
||||
func set_table_id(table_id : int) -> void :
|
||||
# print("GDDBDTable::set_table_id(" + str(table_id) + ")")
|
||||
m_table_id = table_id
|
||||
|
||||
# returns the table id
|
||||
func get_table_id() -> int :
|
||||
return m_table_id
|
||||
|
||||
# sets the table name
|
||||
func set_table_name(table_name: String) -> void :
|
||||
# print("GDDBDTable::set_table_name(" + table_name + ")")
|
||||
m_table_name = table_name
|
||||
|
||||
# returns the table name
|
||||
func get_table_name() -> String :
|
||||
return m_table_name
|
||||
|
||||
# sets the parent database
|
||||
func set_parent_database(db : Object) -> void :
|
||||
# print("GDDBTable::set_parent_database(" + str(db) + ")")
|
||||
m_parent_database = db
|
||||
|
||||
# returns parent database
|
||||
func get_parent_database() -> Object :
|
||||
return m_parent_database
|
||||
|
||||
# adds a property in the table structure as a base type
|
||||
# returns prop ID
|
||||
func add_prop(prop_type : int, prop_name : String) -> int :
|
||||
var prop_id = generate_new_prop_id()
|
||||
|
||||
# print("GDDBDTable::add_prop(" + str(prop_id) + ", " + str(prop_type) + ", " + prop_name + ")")
|
||||
var prop = load(gddb_constants.c_addon_main_path + "core/db_prop.gd").new()
|
||||
prop.set_prop_id(prop_id)
|
||||
prop.set_prop_type(prop_type)
|
||||
prop.set_prop_name(prop_name)
|
||||
m_props.push_back(prop)
|
||||
|
||||
# adding blank data to all existing rows
|
||||
# TODO: find a way to make this better; this is ugly
|
||||
if(m_data.size() > 0):
|
||||
var new_data_array = []
|
||||
var data_idx = 0
|
||||
var row_idx = 0
|
||||
while(true):
|
||||
var data = m_data[data_idx]
|
||||
row_idx = data.get_row_idx()
|
||||
if(data.get_prop_id() + 1 == prop_id):
|
||||
new_data_array.push_back(data)
|
||||
var new_data = load(gddb_constants.c_addon_main_path + "core/db_data.gd").new()
|
||||
new_data.set_prop_id(prop_id)
|
||||
new_data.set_row_idx(row_idx)
|
||||
|
||||
if(prop_type == gddb_types.e_prop_type_bool):
|
||||
new_data.set_data("0")
|
||||
|
||||
elif(prop_type == gddb_types.e_prop_type_int):
|
||||
if(prop.has_autoincrement()):
|
||||
new_data.set_data(str(m_rows_count+1))
|
||||
else:
|
||||
new_data.set_data("0")
|
||||
|
||||
elif(prop_type == gddb_types.e_prop_type_float):
|
||||
new_data.set_data("0.0")
|
||||
|
||||
elif(prop_type == gddb_types.e_prop_type_string):
|
||||
new_data.set_data("")
|
||||
|
||||
elif(prop_type == gddb_types.e_prop_type_resource):
|
||||
new_data.set_data("res://")
|
||||
|
||||
elif(prop_type >= gddb_types.e_prop_types_count):
|
||||
new_data.set_data(str(-1))
|
||||
|
||||
new_data_array.push_back(new_data)
|
||||
else:
|
||||
new_data_array.push_back(data)
|
||||
|
||||
data_idx += 1
|
||||
if(data_idx >= m_data.size()):
|
||||
break
|
||||
|
||||
m_data.clear()
|
||||
for idx in range(0, new_data_array.size()):
|
||||
m_data.push_back(new_data_array[idx])
|
||||
|
||||
return prop_id
|
||||
|
||||
# adds a property in the table structure as a table type
|
||||
# returns prop ID
|
||||
func add_table_prop(prop_name : String, table_name : String) -> int :
|
||||
# print("GDDBTable::add_table_prop(" + prop_name + ", " + table_name + ")")
|
||||
var prop_id = generate_new_prop_id()
|
||||
|
||||
# print("GDDBDTable::add_prop(" + str(prop_id) + ", " + str(prop_type) + ", " + prop_name + ")")
|
||||
var prop = load(gddb_constants.c_addon_main_path + "core/db_prop.gd").new()
|
||||
prop.set_prop_id(prop_id)
|
||||
prop.set_prop_name(prop_name)
|
||||
prop.set_prop_custom_type(table_name)
|
||||
m_props.push_back(prop)
|
||||
|
||||
return prop_id
|
||||
|
||||
# links custom properties from tables
|
||||
func link_tables_props() -> void :
|
||||
for idx in range(0, m_props.size()):
|
||||
var custom_prop_type = m_props[idx].get_prop_custom_type()
|
||||
if(!custom_prop_type.is_empty()):
|
||||
var table = m_parent_database.get_table_by_name(custom_prop_type)
|
||||
m_props[idx].set_prop_type(gddb_types.e_prop_types_count + table.get_table_id())
|
||||
m_props[idx].set_prop_custom_type("")
|
||||
|
||||
# edits a property in the table structure
|
||||
func edit_prop(prop_id : int, prop_type : int, prop_name: String) -> void :
|
||||
for idx in range(0, m_props.size()):
|
||||
if(m_props[idx].get_prop_id() == prop_id):
|
||||
m_props[idx].set_prop_type(prop_type)
|
||||
m_props[idx].set_prop_name(prop_name)
|
||||
return
|
||||
|
||||
print("ERROR: GDDBDTable::edit_prop(" + str(prop_id) + ", " + str(prop_type) + ", " + prop_name + ") - property not found")
|
||||
|
||||
# enables or disables autoincrement on a property
|
||||
func enable_prop_autoincrement(prop_id : int, enable : bool) -> void :
|
||||
for idx in range(0, m_props.size()):
|
||||
if(m_props[idx].get_prop_id() == prop_id):
|
||||
m_props[idx].enable_autoincrement(enable)
|
||||
break
|
||||
|
||||
# deletes a property and all the data from the table have the same property
|
||||
func delete_prop(prop_id : int) -> void :
|
||||
# print("db_table::delete_prop(" + str(prop_id) + ")")
|
||||
var prop_found = false
|
||||
for idx in range(0, m_props.size()):
|
||||
if(m_props[idx].get_prop_id() == prop_id):
|
||||
# print("Removing prop with id " + str(prop_id))
|
||||
m_props[idx].free()
|
||||
m_props.remove(idx)
|
||||
prop_found = true
|
||||
break
|
||||
|
||||
if(!prop_found):
|
||||
print("ERROR: GDDBDTable::delete_prop( " + str(prop_id) + " ) - property not found !")
|
||||
return
|
||||
|
||||
# remove the data
|
||||
# this is very ugly, but I can't erase a subarray from an array in GDscript :(
|
||||
# backup what needs to be saved only
|
||||
var tmp_data = []
|
||||
for idx in range(0, m_data.size()):
|
||||
if(m_data[idx].get_prop_id() == prop_id):
|
||||
continue
|
||||
tmp_data.push_back(m_data[idx])
|
||||
# clear and restore data
|
||||
m_data.clear()
|
||||
for idx in range(0, tmp_data.size()):
|
||||
m_data.push_back(tmp_data[idx])
|
||||
|
||||
# generates a new table id
|
||||
func generate_new_prop_id() -> int :
|
||||
if(m_props.size() == 0):
|
||||
return 0
|
||||
|
||||
return m_props[m_props.size()-1].get_prop_id() + 1
|
||||
|
||||
# returns the properties count
|
||||
func get_props_count() -> int :
|
||||
return m_props.size()
|
||||
|
||||
# returns the property at index or null if the index is out of bounds
|
||||
func get_prop_at(idx : int) -> Object :
|
||||
if(idx < 0 || idx >= m_props.size()):
|
||||
print("ERROR: GDDBDTable::get_prop_id( " + str(idx) + " ) - index out of bounds; max properties: " + str(m_props.size()))
|
||||
return null
|
||||
|
||||
return m_props[idx]
|
||||
|
||||
# returns a property by id or null if the id is not found
|
||||
func get_prop_by_id(prop_id : int) -> Object :
|
||||
for idx in range(0, m_props.size()):
|
||||
if(m_props[idx].get_prop_id() == prop_id):
|
||||
return m_props[idx]
|
||||
|
||||
print("ERROR: GDDBDTable::get_prop_by_id(" + str(prop_id) + ") - property with id not found")
|
||||
return null
|
||||
|
||||
# returns a property by name
|
||||
func get_prop_by_name(pror_name : String) -> Object :
|
||||
for idx in range(0, m_props.size()):
|
||||
if(m_props[idx].get_prop_name() == pror_name):
|
||||
return m_props[idx]
|
||||
|
||||
print("ERROR: GDDBDTable::get_prop_by_name(" + str(pror_name) + ") - property with name not found")
|
||||
return null
|
||||
|
||||
# adds a row with blank data
|
||||
func add_blank_row() -> void :
|
||||
# print("GDDBTable::add_blank_row()")
|
||||
var prop_type = gddb_types.e_prop_type_bool
|
||||
|
||||
for idx in range(0, m_props.size()):
|
||||
var data = load(gddb_constants.c_addon_main_path + "core/db_data.gd").new()
|
||||
data.set_prop_id(m_props[idx].get_prop_id())
|
||||
data.set_row_idx(m_rows_count)
|
||||
|
||||
prop_type = m_props[idx].get_prop_type()
|
||||
|
||||
if(prop_type == gddb_types.e_prop_type_bool):
|
||||
data.set_data("0")
|
||||
|
||||
elif(prop_type == gddb_types.e_prop_type_int):
|
||||
if(m_props[idx].has_autoincrement()):
|
||||
data.set_data(str(m_rows_count+1))
|
||||
else:
|
||||
data.set_data("0")
|
||||
|
||||
elif(prop_type == gddb_types.e_prop_type_float):
|
||||
data.set_data("0.0")
|
||||
|
||||
elif(prop_type == gddb_types.e_prop_type_string):
|
||||
data.set_data("")
|
||||
|
||||
elif(prop_type == gddb_types.e_prop_type_resource):
|
||||
data.set_data("res://")
|
||||
|
||||
elif(prop_type >= gddb_types.e_prop_types_count):
|
||||
data.set_data(str(-1))
|
||||
|
||||
m_data.push_back(data)
|
||||
|
||||
m_rows_count += 1
|
||||
|
||||
# adds a row with data
|
||||
func add_row(data_array : Array) -> void :
|
||||
if(data_array.size() != m_props.size()):
|
||||
print("ERROR: GDDBDTable::add_row( " + str(data_array) + " ) - cannot add row; properties count = " + str(m_props.size()) + " and data size = " + str(data_array.size()))
|
||||
return
|
||||
|
||||
var prop_type = gddb_types.e_prop_type_bool
|
||||
var the_data = ""
|
||||
|
||||
for idx in range(0, m_props.size()):
|
||||
var data = load(gddb_constants.c_addon_main_path + "core/db_data.gd").new()
|
||||
# print("adding data: [" + str(m_props[idx].get_prop_id()) + ", " + data_array[idx] + "]")
|
||||
# print("setting prop id: " + str(m_props[idx].get_prop_id()))
|
||||
|
||||
data.set_prop_id(m_props[idx].get_prop_id())
|
||||
data.set_row_idx(m_rows_count)
|
||||
|
||||
# ignore data if the property has autoincrement option
|
||||
if(m_props[idx].has_autoincrement()):
|
||||
data.set_data(str(m_rows_count+1))
|
||||
m_data.push_back(data)
|
||||
continue
|
||||
|
||||
prop_type = m_props[idx].get_prop_type()
|
||||
the_data = data_array[idx]
|
||||
|
||||
if(prop_type == gddb_types.e_prop_type_bool):
|
||||
data.set_data(str(the_data))
|
||||
elif(prop_type == gddb_types.e_prop_type_int):
|
||||
data.set_data(str(the_data))
|
||||
elif(prop_type == gddb_types.e_prop_type_float):
|
||||
data.set_data(str(the_data))
|
||||
elif(prop_type == gddb_types.e_prop_type_string):
|
||||
data.set_data(gddb_globals.handle_string(the_data))
|
||||
elif(prop_type == gddb_types.e_prop_type_resource):
|
||||
data.set_data(the_data)
|
||||
else:
|
||||
print("ERROR: data type doesn't exist - " + str(m_props[idx].get_prop_type()))
|
||||
|
||||
m_data.push_back(data)
|
||||
|
||||
m_rows_count += 1
|
||||
|
||||
# removes a row
|
||||
func remove_row(row_idx : int) -> void :
|
||||
for idx in range(m_data.size()-1, 0, -1):
|
||||
if(m_data[idx].get_row_idx() == row_idx):
|
||||
m_data[idx].remove(idx)
|
||||
m_rows_count -= 1
|
||||
|
||||
# returns the rows count
|
||||
func get_rows_count() -> int :
|
||||
return m_rows_count
|
||||
|
||||
# edits the data
|
||||
func edit_data(prop_id : int, row_idx : int, data : String) -> void :
|
||||
# print("#1: GDDBTable::edit_data( " + str(prop_id) + ", " + str(row_idx) + ", " + data + " )")
|
||||
for idx in range(0, m_data.size()):
|
||||
# print("checking ( " + str(m_data[idx].get_row_idx()) + ", " + str(m_data[idx].get_prop_id()) + " )")
|
||||
if(m_data[idx].get_row_idx() == row_idx && m_data[idx].get_prop_id() == prop_id):
|
||||
# print("#2: GDDBTable::edit_data( " + str(prop_id) + ", " + str(row_idx) + ", " + data + " )")
|
||||
m_data[idx].set_data(data)
|
||||
return
|
||||
|
||||
print("ERROR: GDDBDTable::edit_data(" + str(prop_id) + ", " + str(row_idx) + ", " + data + ") - can't find data to edit")
|
||||
|
||||
# edits the data
|
||||
func edit_data_by_prop_name(prop_name : String, row_idx : int, data : String) -> void :
|
||||
# print("#1: GDDBTable::edit_data( " + str(prop_id) + ", " + str(row_idx) + ", " + data + " )")
|
||||
|
||||
var prop_id = get_prop_by_name(prop_name).get_prop_id()
|
||||
edit_data(prop_id, row_idx, data)
|
||||
|
||||
# returns data count
|
||||
func get_data_size() -> int :
|
||||
return m_data.size()
|
||||
|
||||
# returns all data
|
||||
func get_all_data() -> Array :
|
||||
return m_data
|
||||
|
||||
# returns the data at index
|
||||
func get_data_at(idx : int) -> String :
|
||||
if(idx < 0 || idx >= m_data.size()):
|
||||
print("ERROR: GDDBDTable::get_data_at( " + str(idx) + ") - max data size: " + str(m_data.size()))
|
||||
return ""
|
||||
|
||||
return m_data[idx].get_data()
|
||||
|
||||
# returns a dictionary containing the data at index
|
||||
func get_dictionary_at(idx : int) -> Dictionary :
|
||||
var dict = {}
|
||||
|
||||
if(idx < 0 || idx >= m_data.size()):
|
||||
print("ERROR: GDDBDTable::get_data_at( " + str(idx) + ") - max data size: " + str(m_data.size()))
|
||||
return dict
|
||||
|
||||
var prop_idx = idx % m_props.size()
|
||||
var data_prop_name = m_props[prop_idx].get_prop_name()
|
||||
dict[data_prop_name] = m_data[idx].get_data()
|
||||
|
||||
return dict
|
||||
|
||||
# returns the data by a property id and a row index
|
||||
func get_data(prop_id : int, row_idx : int) -> String :
|
||||
for idx in range(m_data.size()-1, 0, -1):
|
||||
if(m_data[idx].get_row_idx() == row_idx && m_data[idx].get_prop_id() == prop_id):
|
||||
return m_data[idx].get_data()
|
||||
|
||||
print("ERROR: GDDBDTable::get_data(" + str(prop_id) + ", " + str(row_idx) + ")")
|
||||
return ""
|
||||
|
||||
# returns a dictionary containing the data by a property id and a row index
|
||||
func get_dictionary(prop_id : int, row_idx : int) -> Dictionary :
|
||||
var dict = {}
|
||||
|
||||
for idx in range(m_data.size()-1, 0, -1):
|
||||
if(m_data[idx].get_row_idx() == row_idx && m_data[idx].get_prop_id() == prop_id):
|
||||
var prop = get_prop_by_id(prop_id)
|
||||
var data_prop_name = prop.get_prop_name()
|
||||
dict[data_prop_name] = m_data[idx].get_data()
|
||||
return dict
|
||||
|
||||
print("ERROR: GDDBDTable::get_data(" + str(prop_id) + ", " + str(row_idx) + ")")
|
||||
return dict
|
||||
|
||||
# returns an array of data at row index
|
||||
func get_data_at_row_idx(row_idx : int) -> Array :
|
||||
var data = []
|
||||
for idx in range(0, m_data.size()):
|
||||
if(m_data[idx].get_row_idx() == row_idx):
|
||||
data.push_back(m_data[idx])
|
||||
|
||||
if(data.size() == -1):
|
||||
print("ERROR: GDDBDTable::get_data_at_row_idx(" + str(row_idx) + ") - invalid row index")
|
||||
|
||||
return data
|
||||
|
||||
# returns a dictionary of data at row index
|
||||
func get_dictionary_at_row_idx(row_idx : int) -> Dictionary :
|
||||
var dict = {}
|
||||
|
||||
var prop_idx = 0
|
||||
for idx in range(0, m_data.size()):
|
||||
if(m_data[idx].get_row_idx() == row_idx):
|
||||
var data_prop_name = m_props[prop_idx].get_prop_name()
|
||||
dict[data_prop_name] = m_data[idx].get_data()
|
||||
prop_idx += 1
|
||||
|
||||
if(dict.is_empty()):
|
||||
print("ERROR: GDDBDTable::get_data_at_row_idx(" + str(row_idx) + ") - invalid row index")
|
||||
|
||||
return dict
|
||||
|
||||
# returns an array of data filtered by property id
|
||||
func get_data_by_prop_id(prop_id : int, data_filter : int = gddb_types.e_data_filter_equal) -> Array :
|
||||
var data = []
|
||||
|
||||
if(data_filter < gddb_types.e_data_filter_equal || data_filter >= gddb_types.e_data_filter_gequal):
|
||||
print("ERROR: cannot process filter " + str(data_filter))
|
||||
return data
|
||||
|
||||
for idx in range(0, m_data.size()):
|
||||
if(data_filter == gddb_types.e_data_filter_equal):
|
||||
if(m_data[idx].get_prop_id() == prop_id):
|
||||
data.push_back(m_data[idx])
|
||||
|
||||
elif(data_filter == gddb_types.e_data_filter_not_equal):
|
||||
if(m_data[idx].get_prop_id() != prop_id):
|
||||
data.push_back(m_data[idx])
|
||||
|
||||
elif(data_filter == gddb_types.e_data_filter_less):
|
||||
if(m_data[idx].get_prop_id() < prop_id):
|
||||
data.push_back(m_data[idx])
|
||||
|
||||
elif(data_filter == gddb_types.e_data_filter_greater):
|
||||
if(m_data[idx].get_prop_id() > prop_id):
|
||||
data.push_back(m_data[idx])
|
||||
|
||||
elif(data_filter == gddb_types.e_data_filter_lequal):
|
||||
if(m_data[idx].get_prop_id() <= prop_id):
|
||||
data.push_back(m_data[idx])
|
||||
|
||||
elif(data_filter == gddb_types.e_data_filter_gequal):
|
||||
if(m_data[idx].get_prop_id() >= prop_id):
|
||||
data.push_back(m_data[idx])
|
||||
|
||||
if(data.size() == 0):
|
||||
print("ERROR: GDDBDTable::get_data_by_prop_id(" + str(prop_id) + ", " + gddb_globals.get_data_filter_name(data_filter) + ") - filtered data not found")
|
||||
|
||||
return data
|
||||
|
||||
# returns an array of data by property name
|
||||
func get_data_by_prop_name(prop_name : String) -> Array :
|
||||
var prop_id = -1
|
||||
for idx in range(0, m_props.size()):
|
||||
if(m_props[idx].get_prop_name() == prop_name):
|
||||
prop_id = m_props[idx].get_prop_id()
|
||||
break
|
||||
|
||||
if(prop_id == -1):
|
||||
print("ERROR: GDDBDTable::get_data_by_prop_name(" + prop_name + ") - property not found")
|
||||
return []
|
||||
|
||||
return get_data_by_prop_id(prop_id)
|
||||
|
||||
# returns an array of data filtered by data
|
||||
# filters "<", ">", "<=" and ">=" are working for integer and float data types
|
||||
func get_data_by_data(data_value : String, data_filter : int = gddb_types.e_data_filter_equal) -> Array :
|
||||
var data = []
|
||||
|
||||
if(data_filter < gddb_types.e_data_filter_equal || data_filter >= gddb_types.e_data_filter_gequal):
|
||||
print("ERROR: cannot process filter " + str(data_filter))
|
||||
return data
|
||||
|
||||
for idx in range(0, m_data.size()):
|
||||
if(data_filter == gddb_types.e_data_filter_equal):
|
||||
if(m_data[idx].get_data() == data_value):
|
||||
data.push_back(m_data[idx])
|
||||
|
||||
elif(data_filter == gddb_types.e_data_filter_not_equal):
|
||||
if(m_data[idx].get_data() != data_value):
|
||||
data.push_back(m_data[idx])
|
||||
|
||||
elif(data_filter == gddb_types.e_data_filter_less):
|
||||
if(m_props[idx].get_prop_type() < gddb_types.e_prop_type_resource):
|
||||
if(m_data[idx].get_data() < data_value):
|
||||
data.push_back(m_data[idx])
|
||||
|
||||
elif(data_filter == gddb_types.e_data_filter_greater):
|
||||
if(m_props[idx].get_prop_type() < gddb_types.e_prop_type_resource):
|
||||
if(m_data[idx].get_data() > data_value):
|
||||
data.push_back(m_data[idx])
|
||||
|
||||
elif(data_filter == gddb_types.e_data_filter_lequal):
|
||||
if(m_props[idx].get_prop_type() < gddb_types.e_prop_type_resource):
|
||||
if(m_data[idx].get_data() <= data_value):
|
||||
data.push_back(m_data[idx])
|
||||
|
||||
elif(data_filter == gddb_types.e_data_filter_gequal):
|
||||
if(m_props[idx].get_prop_type() < gddb_types.e_prop_type_resource):
|
||||
if(m_data[idx].get_data() >= data_value):
|
||||
data.push_back(m_data[idx])
|
||||
|
||||
if(data.size() == 0):
|
||||
print("ERROR: GDDBDTable::get_data_by_data(" + data_value + ", " + gddb_globals.get_data_filter_name(data_filter) + ") - filtered data not found")
|
||||
|
||||
return data
|
||||
|
||||
# returns an array of data by a property name and a data value
|
||||
# similar to: select * from users where user_id = 1
|
||||
func get_data_by_prop_name_and_data(prop_name : String, data_value : String) -> Array :
|
||||
var the_array = []
|
||||
|
||||
var prop_idx = -1
|
||||
for idx in range(0, m_props.size()):
|
||||
if(m_props[idx].get_prop_name() == prop_name):
|
||||
prop_idx = idx
|
||||
break
|
||||
|
||||
for idx in range(0, m_rows_count):
|
||||
var row_data = get_data_at_row_idx(idx)
|
||||
# print("Comparing row: " + row_data[0].get_data() + ", " + row_data[1].get_data() + ", " + row_data[2].get_data() + ", " + row_data[3].get_data() + ", " + row_data[4].get_data())
|
||||
if(row_data[prop_idx].get_data() == data_value):
|
||||
var dict = get_dictionary_at_row_idx(idx)
|
||||
the_array.push_back(row_data)
|
||||
|
||||
return the_array
|
||||
|
||||
# returns a dictionary of data by a property name and a data value
|
||||
# similar to: select * from users where user_id = 1
|
||||
func get_dictionary_by_prop_name_and_data(prop_name : String, data_value : String) -> Array :
|
||||
var the_array = []
|
||||
|
||||
var prop_idx = -1
|
||||
for idx in range(0, m_props.size()):
|
||||
if(m_props[idx].get_prop_name() == prop_name):
|
||||
prop_idx = idx
|
||||
break
|
||||
|
||||
for idx in range(0, m_rows_count):
|
||||
var row_data = get_data_at_row_idx(idx)
|
||||
# print("Comparing row: " + row_data[0].get_data() + ", " + row_data[1].get_data() + ", " + row_data[2].get_data() + ", " + row_data[3].get_data() + ", " + row_data[4].get_data())
|
||||
if(row_data[prop_idx].get_data() == data_value):
|
||||
var dict = get_dictionary_at_row_idx(idx)
|
||||
the_array.push_back(get_dictionary_at_row_idx(idx))
|
||||
|
||||
return the_array
|
||||
|
||||
# clears the table's structure and data
|
||||
func clear() -> void :
|
||||
# clear data
|
||||
clear_data()
|
||||
|
||||
# clear properties
|
||||
for idx in range(0, m_props.size()):
|
||||
m_props[idx].free()
|
||||
m_props.clear()
|
||||
|
||||
# clears the table's data
|
||||
func clear_data() -> void :
|
||||
for idx in range(0, m_data.size()):
|
||||
m_data[idx].free()
|
||||
m_data.clear()
|
||||
m_rows_count = 0
|
||||
|
||||
# dumps the table
|
||||
func dump() -> String :
|
||||
var dump_text = "Table dump. id: " + str(m_table_id) + ", name: " + m_table_name + ", props_count: " + str(m_props.size()) + ", rows_count: " + str(m_rows_count)
|
||||
dump_text += "\n------------------------------------------------------------------------------------\nProperties:"
|
||||
|
||||
for idx in range(0, m_props.size()):
|
||||
dump_text += "\n" + m_props[idx].dump()
|
||||
|
||||
dump_text += "\n------------------------------------------------------------------------------------\nData:\n"
|
||||
|
||||
for idx in range(0, m_rows_count):
|
||||
var tmp_text = "row_idx: " + "%" + str(gddb_globals.get_digits_count(m_rows_count)) + "d"
|
||||
dump_text += tmp_text % idx
|
||||
var row = get_data_at_row_idx(idx)
|
||||
for jdx in range(0, row.size()):
|
||||
dump_text += " | " + row[jdx].get_data()
|
||||
dump_text += "\n"
|
||||
|
||||
return dump_text
|
||||
@@ -1,59 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBDataLabel
|
||||
"""
|
||||
|
||||
class_name GDDBDataLabel
|
||||
|
||||
extends Label
|
||||
|
||||
signal resize_property
|
||||
|
||||
var m_prop_id : int = gddb_constants.c_invalid_id
|
||||
var m_prop_type : int = gddb_constants.c_invalid_id
|
||||
|
||||
var m_mouse_pos_pressed : Vector2 = Vector2()
|
||||
var m_mouse_pressed : bool = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
set_custom_minimum_size(Vector2(150.0, 24.0))
|
||||
|
||||
# called when the node gets an input
|
||||
func _input(event : InputEvent) -> void :
|
||||
if(!gddb_globals.is_interface_active()):
|
||||
return
|
||||
|
||||
var evLocal = $resize_ctrl.make_input_local(event)
|
||||
|
||||
if event is InputEventMouseButton :
|
||||
if(event.button_index == MOUSE_BUTTON_LEFT):
|
||||
if(event.pressed):
|
||||
var rect = Rect2(Vector2(0, 0), $resize_ctrl.get_size())
|
||||
var inside = rect.has_point(evLocal.position)
|
||||
if(inside):
|
||||
m_mouse_pressed = true
|
||||
m_mouse_pos_pressed = evLocal.position
|
||||
else:
|
||||
m_mouse_pressed = false
|
||||
|
||||
elif event is InputEventMouseMotion :
|
||||
if(m_mouse_pressed):
|
||||
var diff_x = evLocal.position.x - m_mouse_pos_pressed.x
|
||||
emit_signal("resize_property", m_prop_id, diff_x)
|
||||
|
||||
# sets property id
|
||||
func set_prop_id(id : int) -> void:
|
||||
m_prop_id = id
|
||||
|
||||
# returns property id
|
||||
func get_prop_id() -> int:
|
||||
return m_prop_id
|
||||
|
||||
# sets property type
|
||||
func set_prop_type(prop_type : int) -> void :
|
||||
m_prop_type = prop_type
|
||||
|
||||
# returns property type
|
||||
func get_prop_type() -> int :
|
||||
return m_prop_type
|
||||
@@ -1,44 +0,0 @@
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/data_label.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_18.tres" type="FontFile" id=2]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/tex/gui.png" type="Texture2D" id=3]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/tex/debug.png" type="Texture2D" id=4]
|
||||
|
||||
[node name="lbl" type="Label"]
|
||||
anchor_right = 0.167
|
||||
offset_right = -0.300018
|
||||
offset_bottom = 11.52
|
||||
custom_minimum_size = Vector2( 150, 32 )
|
||||
mouse_filter = 0
|
||||
theme_override_fonts/font = ExtResource( 2 )
|
||||
text = "ID"
|
||||
valign = 1
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_horizontal_guides_": [ 24.0 ],
|
||||
"_edit_use_anchors_": true
|
||||
}
|
||||
|
||||
[node name="dbg" type="NinePatchRect" parent="."]
|
||||
visible = false
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
texture = ExtResource( 4 )
|
||||
region_rect = Rect2( 86, 26, 10, 10 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="resize_ctrl" type="NinePatchRect" parent="."]
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -3.0
|
||||
mouse_filter = 0
|
||||
mouse_default_cursor_shape = 10
|
||||
texture = ExtResource( 3 )
|
||||
region_rect = Rect2( 80, 12, 24, 24 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBEditor
|
||||
"""
|
||||
|
||||
class_name GDDBEditor
|
||||
|
||||
extends TabBar
|
||||
|
||||
var m_name = ""
|
||||
var m_database = null
|
||||
|
||||
var m_filepath = ""
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void :
|
||||
set_tab_alignment(TabBar.ALIGN_LEFT)
|
||||
set_tab_close_display_policy(TabBar.CLOSE_BUTTON_SHOW_ALWAYS)
|
||||
|
||||
$tables_list.connect("resize_tables_list", Callable(self, "on_resize_the_table_list"))
|
||||
$tables_list.connect("add_table", Callable(self, "on_add_table"))
|
||||
$tables_list.connect("edit_table_name", Callable(self, "on_edit_table"))
|
||||
$tables_list.connect("delete_table", Callable(self, "on_delete_table"))
|
||||
$tables_list.connect("select_table", Callable(self, "on_select_table"))
|
||||
|
||||
$table_editor.connect("set_dirty", Callable(self, "on_set_dirty"))
|
||||
|
||||
$delete_table_dlg.connect("delete_table", Callable(self, "on_confirm_delete_table"))
|
||||
|
||||
$new_table_dlg.connect("cancel_dialog", Callable(self, "on_close_new_table_dlg"))
|
||||
$new_table_dlg.get_close_button().connect("pressed", Callable(self, "on_close_new_table_dlg"))
|
||||
|
||||
$error_dlg.connect("confirmed", Callable(self, "on_retry_create_table"))
|
||||
|
||||
# resizing the tables list
|
||||
func on_resize_the_table_list(diff_x : float) -> void :
|
||||
var size = $tables_list.get_size()
|
||||
var min_size = $tables_list.get_custom_minimum_size()
|
||||
size.x += diff_x
|
||||
|
||||
if(size.x < min_size.x):
|
||||
return
|
||||
|
||||
if(size.x > gddb_constants.c_max_tables_list_width):
|
||||
return
|
||||
|
||||
$tables_list.resize_content(size)
|
||||
|
||||
var pos = $table_editor.get_position()
|
||||
size = $table_editor.get_size()
|
||||
pos.x += diff_x
|
||||
size.x -= diff_x
|
||||
$table_editor.set_position(pos)
|
||||
$table_editor.set_size(size)
|
||||
|
||||
# overrides the member from base class
|
||||
func set_name(ctrl_name) -> void :
|
||||
m_name = ctrl_name
|
||||
super.set_name(ctrl_name)
|
||||
|
||||
# sets the database; for easy access
|
||||
func set_database(db) -> void :
|
||||
# print("GDDBEditor::set_database(" + db.get_db_name() + ") to " + get_name())
|
||||
m_database = db
|
||||
set_dirty(true)
|
||||
|
||||
var tables_count = db.get_tables_count()
|
||||
|
||||
$table_editor.hide()
|
||||
|
||||
for idx in range(0, tables_count):
|
||||
var table = db.get_table_at(idx)
|
||||
$tables_list.create_table(table, idx == 0)
|
||||
if(idx == 0):
|
||||
$table_editor.set_table(table)
|
||||
$table_editor.link_props()
|
||||
$table_editor.show()
|
||||
|
||||
# returns the database id
|
||||
func get_db_id() -> int :
|
||||
if(null == m_database):
|
||||
return gddb_constants.c_invalid_id
|
||||
return m_database.get_db_id()
|
||||
|
||||
# returns the database name
|
||||
func get_db_name() -> String :
|
||||
if(null == m_database):
|
||||
return ""
|
||||
return m_database.get_db_name()
|
||||
|
||||
# sets the database to be dirty; should be saved
|
||||
func set_dirty(dirty) -> void :
|
||||
if(dirty):
|
||||
var title = m_name + "*"
|
||||
super.set_name(title)
|
||||
else:
|
||||
super.set_name(m_name)
|
||||
|
||||
# called when the user presses the "add_table" button from the "tables_list/tables_header"
|
||||
func on_add_table() -> void :
|
||||
# print("GDDBEditor::on_add_table()")
|
||||
$new_table_dlg.set_dld_type(gddb_types.e_new_dlg_type_new)
|
||||
$new_table_dlg.set_table_id(gddb_constants.c_invalid_id)
|
||||
$new_table_dlg.set_init_name("")
|
||||
$new_table_dlg.connect("create_new_table", Callable(self, "on_create_table"))
|
||||
$new_table_dlg.popup_centered()
|
||||
|
||||
# called when the user accepts the name of the table in the "new_table_dlg"
|
||||
func on_create_table(table_name : String) -> void :
|
||||
# print("GDDBEditor::on_create_table(" + table_name + ")")
|
||||
$new_table_dlg.disconnect("create_new_table", Callable(self, "on_create_table"))
|
||||
var table_id = m_database.add_table(table_name)
|
||||
if(table_id == gddb_constants.c_invalid_id):
|
||||
$error_dlg.set_text("Table with the name \"" + table_name + "\" already exists" )
|
||||
$error_dlg.popup_centered()
|
||||
return
|
||||
var table = m_database.get_table_by_id(table_id)
|
||||
$tables_list.create_table(table)
|
||||
$table_editor.set_table(table)
|
||||
$table_editor.show()
|
||||
m_database.set_dirty(true)
|
||||
set_dirty(true)
|
||||
|
||||
# called when the user retryes to create a table (changed the name)
|
||||
func on_retry_create_table() -> void :
|
||||
$new_table_dlg.set_init_name("")
|
||||
$new_table_dlg.popup_centered()
|
||||
|
||||
# called when the user presses the "edit_table_name" from the "tables/list/table"
|
||||
func on_edit_table(table_id : int, table_name : String) -> void :
|
||||
# print("GDDBEditor::on_edit_table(" + str(table_id) + ", " + table_name + ")")
|
||||
$new_table_dlg.set_dld_type(gddb_types.e_new_dlg_type_edit)
|
||||
$new_table_dlg.set_table_id(table_id)
|
||||
$new_table_dlg.set_init_name(table_name)
|
||||
$new_table_dlg.connect("create_new_table", Callable(self, "on_table_name_edited"))
|
||||
$new_table_dlg.popup_centered()
|
||||
|
||||
# gets called when canceling the new_table_dlg
|
||||
func on_close_new_table_dlg() -> void :
|
||||
# print("GDDBEditor::on_close_new_table_dlg()")
|
||||
var dlg_type = $new_table_dlg.get_dlg_type()
|
||||
if(dlg_type == gddb_types.e_new_dlg_type_new):
|
||||
$new_table_dlg.disconnect("create_new_table", Callable(self, "on_create_table"))
|
||||
elif(dlg_type == gddb_types.e_new_dlg_type_edit):
|
||||
$new_table_dlg.disconnect("create_new_table", Callable(self, "on_table_name_edited"))
|
||||
|
||||
# called when the user presses the "delete_table" from the "tables/list/table"
|
||||
func on_delete_table(table_id : int) -> void :
|
||||
# print("GDDBEditor::on_delete_table(" + str(table_id) + ")")
|
||||
var table = m_database.get_table_by_id(table_id)
|
||||
$delete_table_dlg.set_table_id(table_id)
|
||||
$delete_table_dlg.set_table_name(table.get_table_name())
|
||||
$delete_table_dlg.popup_centered()
|
||||
|
||||
# called when the user accepts the name of the table in the "new_table_dlg"
|
||||
func on_table_name_edited(table_name : String) -> void :
|
||||
# print("GDDBEditor::on_table_name_edited(" + table_name + ")")
|
||||
$new_table_dlg.disconnect("create_new_table", Callable(self, "on_table_name_edited"))
|
||||
var table_id = $new_table_dlg.get_table_id()
|
||||
if(!m_database.edit_table_name(table_name, table_id)):
|
||||
$error_dlg.set_text("Table with the name \"" + table_name + "\" already exists" )
|
||||
$error_dlg.popup_centered()
|
||||
return
|
||||
# print("GDDBEditor::on_table_name_edited(" + str(table_id) + ", " + table_name + ")")
|
||||
$tables_list.edit_table_name(table_id, table_name)
|
||||
m_database.set_dirty(true)
|
||||
set_dirty(true)
|
||||
|
||||
# called when the user confirms to delete a table
|
||||
func on_confirm_delete_table() -> void :
|
||||
# print("GDDBEditor::on_confirm_delete_table()")
|
||||
var table_id = $delete_table_dlg.get_table_id()
|
||||
var selected_table = $tables_list.get_selected_item()
|
||||
if(null == selected_table):
|
||||
return
|
||||
var selected_table_id = selected_table.get_table_id()
|
||||
m_database.delete_table_by_id(table_id)
|
||||
$tables_list.delete_table(table_id)
|
||||
if(selected_table_id == table_id):
|
||||
$tables_list.select_item_at(0)
|
||||
var table = m_database.get_table_at(0)
|
||||
$table_editor.set_table(table)
|
||||
|
||||
m_database.set_dirty(true)
|
||||
set_dirty(true)
|
||||
|
||||
# called when the user selects a table from the table_list
|
||||
func on_select_table(table_id : int) -> void :
|
||||
var table = m_database.get_table_by_id(table_id)
|
||||
if(null != table):
|
||||
$table_editor.set_table(table)
|
||||
$table_editor.link_props()
|
||||
|
||||
# saves current database
|
||||
func save_database() -> void:
|
||||
m_database.save_db()
|
||||
set_dirty(false)
|
||||
|
||||
# returns true if the database can be saved, otherwise false
|
||||
func can_save_database() -> bool:
|
||||
return !m_database.get_db_filepath().is_empty()
|
||||
|
||||
# sets the database's path
|
||||
func set_database_filepath(filepath : String) -> void:
|
||||
m_database.set_db_filepath(filepath)
|
||||
|
||||
# called when a table is modified
|
||||
func on_set_dirty() -> void:
|
||||
m_database.set_dirty(true)
|
||||
set_dirty(true)
|
||||
@@ -1,40 +0,0 @@
|
||||
[gd_scene load_steps=8 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/db_editor.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/tables_list.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/new_table_dlg.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://addons/godot_db_manager/table_editor.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/error_dlg.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/delete_table_dlg.tscn" type="PackedScene" id=6]
|
||||
[ext_resource path="res://addons/godot_db_manager/debug/dbg.tscn" type="PackedScene" id=7]
|
||||
|
||||
[node name="db_editor" type="TabBar"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
tab_alignment = 0
|
||||
tab_close_display_policy = 2
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": true,
|
||||
"_edit_vertical_guides_": [ 170.0, 900.0 ]
|
||||
}
|
||||
|
||||
[node name="tables_list" parent="." instance=ExtResource( 2 )]
|
||||
anchor_right = 0.0
|
||||
offset_right = 170.0
|
||||
custom_minimum_size = Vector2( 180, 30 )
|
||||
|
||||
[node name="table_editor" parent="." instance=ExtResource( 4 )]
|
||||
offset_left = 181.0
|
||||
|
||||
[node name="dbg" parent="." instance=ExtResource( 7 )]
|
||||
visible = false
|
||||
|
||||
[node name="new_table_dlg" parent="." instance=ExtResource( 3 )]
|
||||
visible = false
|
||||
|
||||
[node name="delete_table_dlg" parent="." instance=ExtResource( 6 )]
|
||||
visible = false
|
||||
|
||||
[node name="error_dlg" parent="." instance=ExtResource( 5 )]
|
||||
visible = false
|
||||
@@ -1,155 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBInterface
|
||||
"""
|
||||
|
||||
class_name GDDBInterface
|
||||
|
||||
extends Control
|
||||
|
||||
var m_db_manager = null
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
# init db_manager
|
||||
m_db_manager = load(gddb_constants.c_addon_main_path + "core/db_man.gd").new()
|
||||
|
||||
# menu connections
|
||||
$dlg/menu.connect("new_database", Callable(self, "on_menu_new_database"))
|
||||
$dlg/menu.connect("load_database", Callable(self, "on_menu_load_database"))
|
||||
$dlg/menu.connect("save_database", Callable(self, "on_menu_save_database"))
|
||||
$dlg/menu.connect("save_database_as", Callable(self, "on_menu_save_database_as"))
|
||||
|
||||
# dialod notifications
|
||||
$dlg.connect("about_to_popup", Callable(self, "on_about_to_show"))
|
||||
$dlg.get_close_button().connect("pressed", Callable(self, "on_close"))
|
||||
|
||||
# new database connections
|
||||
$dlg/new_db_dlg.connect("create_new_db", Callable(self, "on_new_database"))
|
||||
|
||||
# save / load connections
|
||||
$dlg/load_db_dlg.connect("file_selected", Callable(self, "on_file_selected"))
|
||||
|
||||
# Called when the node is about to be shown.
|
||||
func on_about_to_show() -> void :
|
||||
gddb_globals.set_interface_active(true)
|
||||
|
||||
func on_close() -> void :
|
||||
gddb_globals.set_interface_active(false)
|
||||
|
||||
# called when creating a new database from the menu
|
||||
func on_menu_new_database() -> void:
|
||||
$dlg/new_db_dlg/v_layout/db_info/db_edt.set_text("")
|
||||
$dlg/new_db_dlg.popup_centered()
|
||||
|
||||
# called when loading a database from the menu
|
||||
func on_menu_load_database() -> void:
|
||||
$dlg/load_db_dlg.set_mode(FileDialog.FILE_MODE_OPEN_FILE)
|
||||
$dlg/load_db_dlg.set_title("Load Database ...")
|
||||
$dlg/load_db_dlg.set_current_file("")
|
||||
$dlg/load_db_dlg.popup_centered()
|
||||
|
||||
# called when saving a database from the menu
|
||||
func on_menu_save_database() -> void:
|
||||
# print("on_menu_save_database")
|
||||
var currnet_tab = $dlg/databases.get_current_tab_control()
|
||||
if(currnet_tab.can_save_database()):
|
||||
currnet_tab.save_database()
|
||||
else:
|
||||
on_menu_save_database_as()
|
||||
|
||||
# called when saving a database as another from the menu
|
||||
func on_menu_save_database_as():
|
||||
# print("on_menu_save_database_as")
|
||||
$dlg/load_db_dlg.set_mode(FileDialog.FILE_MODE_SAVE_FILE)
|
||||
$dlg/load_db_dlg.set_title("Save Database As ...")
|
||||
|
||||
var currnet_tab = $dlg/databases.get_current_tab_control()
|
||||
|
||||
$dlg/load_db_dlg.set_current_file(currnet_tab.get_db_name())
|
||||
$dlg/load_db_dlg.popup_centered()
|
||||
|
||||
# called when adding a new database
|
||||
func on_new_database(db_name : String) -> void:
|
||||
var tmp_name = db_name.to_lower()
|
||||
var db_id = m_db_manager.add_database(db_name)
|
||||
if(db_id == gddb_constants.c_invalid_id):
|
||||
$dlg/error_dlg.set_text("Database with name \"" + db_name + "\" already exists")
|
||||
$dlg/error_dlg.popup_centered()
|
||||
return
|
||||
|
||||
var db = m_db_manager.get_db_by_id(db_id)
|
||||
# print("new DB added: " + str(db))
|
||||
|
||||
var db_editor = load(gddb_constants.c_addon_main_path + "db_editor.tscn").instantiate()
|
||||
$dlg/databases.add_child(db_editor)
|
||||
db_editor.set_name(db_name)
|
||||
db.set_dirty(true)
|
||||
db_editor.set_database(db)
|
||||
|
||||
$dlg/menu.enable_file_save(true)
|
||||
$dlg/menu.enable_file_save_as(true)
|
||||
|
||||
$dlg/new_db_dlg.hide()
|
||||
|
||||
# called when selecting a file from save / load dialog
|
||||
func on_file_selected(filepath : String) -> void:
|
||||
# print("GDDBInterface::on_file_selected(" + filepath + ")")
|
||||
|
||||
if($dlg/load_db_dlg.get_mode() == FileDialog.FILE_MODE_SAVE_FILE):
|
||||
var filepath_low = filepath.to_lower()
|
||||
|
||||
# check for the file extension
|
||||
if(!filepath_low.ends_with(".json")):
|
||||
$dlg/error_dlg.set_text("The extension of the file must be \".json\"")
|
||||
$dlg/error_dlg.popup_centered()
|
||||
return
|
||||
|
||||
var current_filename = $dlg/load_db_dlg.get_current_file().to_lower()
|
||||
var filename_dot = current_filename.length() - 5
|
||||
current_filename.erase(filename_dot, 5)
|
||||
|
||||
# check the filename
|
||||
if(!gddb_globals.check_db_name(current_filename)):
|
||||
$dlg/error_dlg.set_text("Invalid characters in the database filename.\n\nThe filename cannot contain any of these characters: " + gddb_constants.c_invalid_characters)
|
||||
$dlg/error_dlg.popup_centered()
|
||||
return
|
||||
|
||||
save_database_as(filepath)
|
||||
|
||||
elif($dlg/load_db_dlg.get_mode() == FileDialog.FILE_MODE_OPEN_FILE):
|
||||
load_database(filepath)
|
||||
|
||||
# saves a database to a given file path
|
||||
func save_database_as(filepath : String) -> void:
|
||||
# print("GDDBInterface::save_database_as(" + filepath + ")")
|
||||
var currnet_tab = $dlg/databases.get_current_tab_control()
|
||||
currnet_tab.set_database_filepath(filepath)
|
||||
currnet_tab.save_database()
|
||||
|
||||
func load_database(filepath : String) -> void:
|
||||
var db_id = m_db_manager.load_database(filepath)
|
||||
|
||||
if(db_id == gddb_types.e_db_invalid_file):
|
||||
$dlg/error_dlg.set_text("Invalid database")
|
||||
$dlg/error_dlg.popup_centered()
|
||||
return
|
||||
|
||||
if(db_id == gddb_types.e_db_invalid_ver):
|
||||
$dlg/error_dlg.set_text("Wrong database version. Currently is: " + gddb_constants.c_gddb_ver)
|
||||
$dlg/error_dlg.popup_centered()
|
||||
return
|
||||
|
||||
var db = m_db_manager.get_db_by_id(db_id)
|
||||
db.set_dirty(false)
|
||||
# print("new DB added: " + str(db))
|
||||
|
||||
var db_editor = load(gddb_constants.c_addon_main_path + "db_editor.tscn").instantiate()
|
||||
$dlg/databases.add_child(db_editor)
|
||||
db_editor.set_name(db.get_db_name())
|
||||
db_editor.set_database(db)
|
||||
|
||||
$dlg/menu.enable_file_save(true)
|
||||
$dlg/menu.enable_file_save_as(true)
|
||||
|
||||
db_editor.set_dirty(false)
|
||||
@@ -1,65 +0,0 @@
|
||||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/debug/dbg.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_18.tres" type="FontFile" id=2]
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/error_dlg.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://addons/godot_db_manager/db_interface.gd" type="Script" id=4]
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/new_db_dlg.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://addons/godot_db_manager/menu.tscn" type="PackedScene" id=7]
|
||||
|
||||
[node name="db_interface" type="Control"]
|
||||
script = ExtResource( 4 )
|
||||
__meta__ = {
|
||||
"_edit_horizontal_guides_": [ 30.0, 674.0 ],
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="dlg" type="Window" parent="."]
|
||||
visible = true
|
||||
offset_right = 1147.0
|
||||
offset_bottom = 768.0
|
||||
exclusive = true
|
||||
window_title = "Godot Database Manager"
|
||||
resizable = true
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="menu" parent="dlg" instance=ExtResource( 7 )]
|
||||
|
||||
[node name="databases" type="TabContainer" parent="dlg"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 30.0
|
||||
theme_override_fonts/font = ExtResource( 2 )
|
||||
tab_alignment = 0
|
||||
drag_to_rearrange_enabled = true
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="new_db_dlg" parent="dlg" instance=ExtResource( 5 )]
|
||||
visible = false
|
||||
offset_right = 3.832
|
||||
|
||||
[node name="error_dlg" parent="dlg" instance=ExtResource( 3 )]
|
||||
visible = false
|
||||
anchor_right = 0.187
|
||||
anchor_bottom = 0.136
|
||||
offset_right = 0.469986
|
||||
offset_bottom = -0.0800018
|
||||
|
||||
[node name="load_db_dlg" type="FileDialog" parent="dlg"]
|
||||
anchor_right = 0.349
|
||||
anchor_bottom = 0.418
|
||||
offset_right = -0.309998
|
||||
offset_bottom = 0.209991
|
||||
window_title = "Open a File"
|
||||
mode = 0
|
||||
filters = PackedStringArray( "*.json" )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="dbg" parent="dlg" instance=ExtResource( 1 )]
|
||||
visible = false
|
||||
@@ -1,33 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBManager
|
||||
"""
|
||||
|
||||
class_name GDDBManager
|
||||
|
||||
extends EditorPlugin
|
||||
|
||||
var DBInterface = preload("./db_interface.tscn")
|
||||
var db_interface : Node
|
||||
|
||||
func _enter_tree():
|
||||
add_autoload_singleton("gddb_constants", "res://addons/godot_db_manager/core/GDDBConstants.gd")
|
||||
add_autoload_singleton("gddb_types", "res://addons/godot_db_manager/core/GDDBTypes.gd")
|
||||
add_autoload_singleton("gddb_globals", "res://addons/godot_db_manager/core/GDDBGlobals.gd")
|
||||
|
||||
# Initialization of the plugin goes here
|
||||
db_interface = DBInterface.instantiate()
|
||||
|
||||
get_editor_interface().get_base_control().add_child(db_interface)
|
||||
add_tool_menu_item("Godot Database Manager", self, "open_config")
|
||||
|
||||
func _exit_tree():
|
||||
# Clean-up of the plugin goes here
|
||||
remove_tool_menu_item("Godot Database Manager")
|
||||
if(db_interface):
|
||||
db_interface.queue_free()
|
||||
|
||||
func open_config(UD):
|
||||
var window = db_interface.get_node("dlg") as Window
|
||||
if(window):
|
||||
window.popup_centered()
|
||||
@@ -1,79 +0,0 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/tex/debug.png" type="Texture2D" id=1]
|
||||
|
||||
[node name="dbg" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
mouse_filter = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="1" type="Control" parent="."]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
mouse_filter = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="1"]
|
||||
scale = Vector2( 4, 4 )
|
||||
texture = ExtResource( 1 )
|
||||
centered = false
|
||||
region_enabled = true
|
||||
region_rect = Rect2( 2, 50, 10, 10 )
|
||||
|
||||
[node name="2" type="Control" parent="."]
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -40.0
|
||||
offset_bottom = 40.0
|
||||
mouse_filter = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="2"]
|
||||
scale = Vector2( 4, 4 )
|
||||
texture = ExtResource( 1 )
|
||||
centered = false
|
||||
region_enabled = true
|
||||
region_rect = Rect2( 2, 50, 10, 10 )
|
||||
|
||||
[node name="3" type="Control" parent="."]
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = -40.0
|
||||
offset_right = 40.0
|
||||
mouse_filter = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="3"]
|
||||
scale = Vector2( 4, 4 )
|
||||
texture = ExtResource( 1 )
|
||||
centered = false
|
||||
region_enabled = true
|
||||
region_rect = Rect2( 2, 50, 10, 10 )
|
||||
|
||||
[node name="4" type="Control" parent="."]
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -40.0
|
||||
offset_top = -40.0
|
||||
mouse_filter = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="4"]
|
||||
scale = Vector2( 4, 4 )
|
||||
texture = ExtResource( 1 )
|
||||
centered = false
|
||||
region_enabled = true
|
||||
region_rect = Rect2( 2, 50, 10, 10 )
|
||||
@@ -1,61 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBDataPanel
|
||||
"""
|
||||
|
||||
class_name GDDBDataPanel
|
||||
|
||||
extends PopupPanel
|
||||
|
||||
signal select_data
|
||||
|
||||
var m_prop_id = gddb_constants.c_invalid_id
|
||||
var m_row_idx = gddb_constants.c_invalid_id
|
||||
|
||||
var m_table = null
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
connect("about_to_popup", Callable(self, "on_about_to_show"))
|
||||
$ItemList.connect("item_selected", Callable(self, "on_item_selected"))
|
||||
|
||||
# sets property id
|
||||
func set_prop_id(prop_id : int) -> void :
|
||||
m_prop_id = prop_id
|
||||
|
||||
# returns property id
|
||||
func get_prop_id() -> int :
|
||||
return m_prop_id
|
||||
|
||||
# sets row index
|
||||
func set_row_idx(row_idx : int) -> void :
|
||||
m_row_idx = row_idx
|
||||
|
||||
# returns row index
|
||||
func get_row_idx() -> int :
|
||||
return m_row_idx
|
||||
|
||||
# sets the table from the database
|
||||
func set_table(table) -> void:
|
||||
m_table = table
|
||||
|
||||
# returns the table from the database
|
||||
func get_table() -> Object:
|
||||
return m_table
|
||||
|
||||
# called when the popup is about to show
|
||||
func on_about_to_show() -> void :
|
||||
$ItemList.clear()
|
||||
$ItemList.add_item("None")
|
||||
for idx in range(0, m_table.get_rows_count()):
|
||||
var option = gddb_globals.get_json_from_row(m_table, idx)
|
||||
$ItemList.add_item(option)
|
||||
|
||||
# called when an item is selected
|
||||
func on_item_selected(idx : int) -> void:
|
||||
# the first index is ""
|
||||
if(idx == 0):
|
||||
emit_signal("select_data", m_prop_id, m_row_idx, -1, "{}" )
|
||||
else:
|
||||
emit_signal("select_data", m_prop_id, m_row_idx, idx-1, $ItemList.get_item_text(idx) )
|
||||
hide()
|
||||
@@ -1,25 +0,0 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/data_dlg.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_12.tres" type="FontFile" id=2]
|
||||
|
||||
[node name="data_dlg" type="PopupPanel"]
|
||||
anchor_right = 0.285625
|
||||
anchor_bottom = 0.351111
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ItemList" type="ItemList" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 4.0
|
||||
offset_top = 4.0
|
||||
offset_right = -4.0
|
||||
offset_bottom = -4.0
|
||||
theme_override_fonts/font = ExtResource( 2 )
|
||||
items = [ "ababab", null, false, "cdcdcd", null, false, "efefef", null, false ]
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBDeletePropDlg
|
||||
"""
|
||||
|
||||
class_name GDDBDeletePropDlg
|
||||
|
||||
extends Window
|
||||
|
||||
signal delete_prop
|
||||
|
||||
var m_prop_id = gddb_constants.c_invalid_id
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void :
|
||||
$v_layout/buttons/ok_btn.connect("pressed", Callable(self, "on_ok_btn_pressed"))
|
||||
$v_layout/buttons/cancel_btn.connect("pressed", Callable(self, "on_cancel_btn_pressed"))
|
||||
|
||||
# sets the property id
|
||||
func set_prop_id(prop_id : int) -> void :
|
||||
m_prop_id = prop_id
|
||||
|
||||
# returns the property id
|
||||
func get_prop_id() -> int :
|
||||
return m_prop_id
|
||||
|
||||
func set_prop_name(prop_name : String) -> void:
|
||||
var text = "Delete property with name \"" + prop_name + "\" ?"
|
||||
$v_layout/prop_info/prop_lbl.set_text(text)
|
||||
|
||||
# returns the table id
|
||||
func get_table_id() -> int :
|
||||
return m_prop_id
|
||||
|
||||
# called when the OK button is pressed
|
||||
func on_ok_btn_pressed() -> void :
|
||||
emit_signal("delete_prop")
|
||||
hide()
|
||||
|
||||
func on_cancel_btn_pressed() -> void:
|
||||
hide()
|
||||
@@ -1,66 +0,0 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/delete_prop_dlg.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_14.tres" type="FontFile" id=2]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_12.tres" type="FontFile" id=3]
|
||||
|
||||
[node name="delete_prop_dlg" type="Window"]
|
||||
visible = true
|
||||
anchor_right = 0.257
|
||||
anchor_bottom = 0.084
|
||||
offset_right = 0.799988
|
||||
offset_bottom = 0.399994
|
||||
focus_next = NodePath("v_layout/buttons/ok_btn")
|
||||
focus_mode = 1
|
||||
theme_override_fonts/title_font = ExtResource( 2 )
|
||||
exclusive = true
|
||||
window_title = "Delete property"
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="v_layout" type="VBoxContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
theme_override_constants/separation = 10
|
||||
alignment = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="prop_info" type="HBoxContainer" parent="v_layout"]
|
||||
offset_top = 13.0
|
||||
offset_right = 412.0
|
||||
offset_bottom = 30.0
|
||||
alignment = 1
|
||||
|
||||
[node name="prop_lbl" type="Label" parent="v_layout/prop_info"]
|
||||
offset_left = 152.0
|
||||
offset_right = 259.0
|
||||
offset_bottom = 17.0
|
||||
theme_override_fonts/font = ExtResource( 2 )
|
||||
text = "Property name: "
|
||||
|
||||
[node name="buttons" type="HBoxContainer" parent="v_layout"]
|
||||
offset_top = 40.0
|
||||
offset_right = 412.0
|
||||
offset_bottom = 61.0
|
||||
theme_override_constants/separation = 50
|
||||
alignment = 1
|
||||
|
||||
[node name="ok_btn" type="Button" parent="v_layout/buttons"]
|
||||
offset_left = 81.0
|
||||
offset_right = 181.0
|
||||
offset_bottom = 21.0
|
||||
custom_minimum_size = Vector2( 100, 0 )
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
text = "OK"
|
||||
|
||||
[node name="cancel_btn" type="Button" parent="v_layout/buttons"]
|
||||
offset_left = 231.0
|
||||
offset_right = 331.0
|
||||
offset_bottom = 21.0
|
||||
custom_minimum_size = Vector2( 100, 0 )
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
text = "Cancel"
|
||||
@@ -1,37 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBDeleteTableDlg
|
||||
"""
|
||||
|
||||
class_name GDDBDeleteTableDlg
|
||||
|
||||
extends Window
|
||||
|
||||
signal delete_table
|
||||
|
||||
var m_table_id = gddb_constants.c_invalid_id
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
$v_layout/buttons/ok_btn.connect("pressed", Callable(self, "on_ok_btn_pressed"))
|
||||
$v_layout/buttons/cancel_btn.connect("pressed", Callable(self, "on_cancel_btn_pressed"))
|
||||
|
||||
# sets the table id
|
||||
func set_table_id(table_id : int) -> void:
|
||||
m_table_id = table_id
|
||||
|
||||
func set_table_name(table_name : String) -> void:
|
||||
var text = "Delete table with name \"" + table_name + "\" ?"
|
||||
$v_layout/table_info/table_lbl.set_text(text)
|
||||
|
||||
# returns the table id
|
||||
func get_table_id() -> int:
|
||||
return m_table_id
|
||||
|
||||
# called when the OK button is pressed
|
||||
func on_ok_btn_pressed() -> void:
|
||||
emit_signal("delete_table")
|
||||
hide()
|
||||
|
||||
func on_cancel_btn_pressed() -> void:
|
||||
hide()
|
||||
@@ -1,66 +0,0 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/delete_table_dlg.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_14.tres" type="FontFile" id=2]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_12.tres" type="FontFile" id=3]
|
||||
|
||||
[node name="delete_table_dlg" type="Window"]
|
||||
visible = true
|
||||
anchor_right = 0.257
|
||||
anchor_bottom = 0.084
|
||||
offset_right = 0.799988
|
||||
offset_bottom = 0.399994
|
||||
focus_next = NodePath("v_layout/buttons/ok_btn")
|
||||
focus_mode = 1
|
||||
theme_override_fonts/title_font = ExtResource( 2 )
|
||||
exclusive = true
|
||||
window_title = "Delete table"
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="v_layout" type="VBoxContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
theme_override_constants/separation = 10
|
||||
alignment = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="table_info" type="HBoxContainer" parent="v_layout"]
|
||||
offset_top = 13.0
|
||||
offset_right = 412.0
|
||||
offset_bottom = 30.0
|
||||
alignment = 1
|
||||
|
||||
[node name="table_lbl" type="Label" parent="v_layout/table_info"]
|
||||
offset_left = 162.0
|
||||
offset_right = 249.0
|
||||
offset_bottom = 17.0
|
||||
theme_override_fonts/font = ExtResource( 2 )
|
||||
text = "Table name: "
|
||||
|
||||
[node name="buttons" type="HBoxContainer" parent="v_layout"]
|
||||
offset_top = 40.0
|
||||
offset_right = 412.0
|
||||
offset_bottom = 61.0
|
||||
theme_override_constants/separation = 50
|
||||
alignment = 1
|
||||
|
||||
[node name="ok_btn" type="Button" parent="v_layout/buttons"]
|
||||
offset_left = 81.0
|
||||
offset_right = 181.0
|
||||
offset_bottom = 21.0
|
||||
custom_minimum_size = Vector2( 100, 0 )
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
text = "OK"
|
||||
|
||||
[node name="cancel_btn" type="Button" parent="v_layout/buttons"]
|
||||
offset_left = 231.0
|
||||
offset_right = 331.0
|
||||
offset_bottom = 21.0
|
||||
custom_minimum_size = Vector2( 100, 0 )
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
text = "Cancel"
|
||||
@@ -1,59 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBEditStringDlg
|
||||
"""
|
||||
|
||||
class_name GDDBEditStringDlg
|
||||
|
||||
extends Window
|
||||
|
||||
signal string_edited
|
||||
|
||||
var m_prop_id = gddb_constants.c_invalid_id
|
||||
var m_row_idx = gddb_constants.c_invalid_id
|
||||
var m_data_text = ""
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
$v_layout/btns/ok_btn.connect("pressed", Callable(self, "on_ok_btn_pressed"))
|
||||
$v_layout/btns/cancel_btn.connect("pressed", Callable(self, "on_cancel_btn_pressed"))
|
||||
|
||||
$v_layout/text.connect("text_changed", Callable(self, "on_text_changed"))
|
||||
|
||||
# sets property id
|
||||
func set_prop_id(prop_id : int) -> void:
|
||||
m_prop_id = prop_id
|
||||
|
||||
# returns property id
|
||||
func get_prop_id() -> int :
|
||||
return m_prop_id
|
||||
|
||||
# sets row index
|
||||
func set_row_idx(row_idx : int) -> void :
|
||||
m_row_idx = row_idx
|
||||
|
||||
# returns row index
|
||||
func get_row_idx() -> int :
|
||||
return m_row_idx
|
||||
|
||||
# sets data text
|
||||
func set_data_text(text : String) -> void :
|
||||
m_data_text = text
|
||||
$v_layout/text.set_text(text)
|
||||
|
||||
# returns data text
|
||||
func get_data_text() -> String :
|
||||
return m_data_text
|
||||
|
||||
# Called when the OK button is pressed
|
||||
func on_ok_btn_pressed() -> void :
|
||||
emit_signal("string_edited")
|
||||
hide()
|
||||
|
||||
# Called when the Cancel button is pressed
|
||||
func on_cancel_btn_pressed() -> void :
|
||||
hide()
|
||||
|
||||
# Called when text is changed
|
||||
func on_text_changed() -> void:
|
||||
m_data_text = $v_layout/text.get_text()
|
||||
@@ -1,60 +0,0 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/edit_string_dlg.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_14.tres" type="FontFile" id=2]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_12.tres" type="FontFile" id=3]
|
||||
|
||||
[node name="edit_string_dlg" type="Window"]
|
||||
anchor_right = 0.430625
|
||||
anchor_bottom = 0.423333
|
||||
focus_next = NodePath("v_layout/text")
|
||||
theme_override_fonts/title_font = ExtResource( 3 )
|
||||
window_title = "Edit string"
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": true
|
||||
}
|
||||
|
||||
[node name="v_layout" type="VBoxContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="edit_text_btns" type="HBoxContainer" parent="v_layout"]
|
||||
offset_right = 689.0
|
||||
offset_bottom = 30.0
|
||||
custom_minimum_size = Vector2( 0, 30 )
|
||||
|
||||
[node name="text" type="TextEdit" parent="v_layout"]
|
||||
offset_top = 34.0
|
||||
offset_right = 689.0
|
||||
offset_bottom = 334.0
|
||||
custom_minimum_size = Vector2( 0, 300 )
|
||||
theme_override_fonts/font = ExtResource( 2 )
|
||||
caret_blink = true
|
||||
|
||||
[node name="btns" type="HBoxContainer" parent="v_layout"]
|
||||
offset_top = 338.0
|
||||
offset_right = 689.0
|
||||
offset_bottom = 368.0
|
||||
custom_minimum_size = Vector2( 0, 30 )
|
||||
theme_override_constants/separation = 200
|
||||
alignment = 1
|
||||
|
||||
[node name="ok_btn" type="Button" parent="v_layout/btns"]
|
||||
offset_left = 144.0
|
||||
offset_right = 244.0
|
||||
offset_bottom = 30.0
|
||||
custom_minimum_size = Vector2( 100, 0 )
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
text = "OK"
|
||||
|
||||
[node name="cancel_btn" type="Button" parent="v_layout/btns"]
|
||||
offset_left = 444.0
|
||||
offset_right = 544.0
|
||||
offset_bottom = 30.0
|
||||
custom_minimum_size = Vector2( 100, 0 )
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
text = "Cancel"
|
||||
@@ -1,11 +0,0 @@
|
||||
[gd_scene format=2]
|
||||
|
||||
[node name="error_dlg" type="AcceptDialog"]
|
||||
visible = true
|
||||
anchor_right = 0.139
|
||||
anchor_bottom = 0.099
|
||||
offset_right = 0.599976
|
||||
offset_bottom = -0.100006
|
||||
exclusive = true
|
||||
window_title = "Error"
|
||||
dialog_autowrap = true
|
||||
@@ -1,76 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBLoadResourcePathDlg
|
||||
"""
|
||||
|
||||
class_name GDDBLoadResourcePathDlg
|
||||
|
||||
extends FileDialog
|
||||
|
||||
# TODO: put this list in a config file
|
||||
const file_filters = [
|
||||
# Godot resource file types
|
||||
"*.res, *.tres ; Godot resource file types",
|
||||
|
||||
# Godot scene files
|
||||
"*.scn, *.tscn, *escn ; Godot scene file types",
|
||||
|
||||
# Code file types
|
||||
"*.gd, *.cs, *.h, *.c, *.hpp, *.cpp ; Code file types",
|
||||
|
||||
# Shader file types
|
||||
"*.shader ; Shader file types",
|
||||
|
||||
# material file types
|
||||
"*.mat ; Material file types",
|
||||
|
||||
# mesh file types
|
||||
"*.dae, *.gltf, *.obj, *.fbx ; Mesh file types",
|
||||
|
||||
# animation file types
|
||||
"*.anim ; Animation file types",
|
||||
|
||||
# font file types
|
||||
"*.ttf, *.otf ; Font file types",
|
||||
|
||||
# image file types
|
||||
"*.png, *.jpg, *.jpeg, *.tiff, *.tga, *.bmp, *.webp, *.gif, *.hdr ; Images file types",
|
||||
|
||||
# soung file types
|
||||
"*.snd, *.wav, *.ogg, *.mp3 ; Sound file types",
|
||||
|
||||
# video file types
|
||||
"*.ogg, *.mpg, *.mpeg, *.avi, *.mov, *.mp4, *.webm ; Video file types",
|
||||
|
||||
# text file types
|
||||
"*.txt, *.csv, *.json, *.xml, *.cfg, *.ini ; Text file types",
|
||||
|
||||
# document file types
|
||||
"*.doc, *.docx, *.xls, *.xlsx, *.odt, *.ods, *.pdf ; Doc file types",
|
||||
|
||||
# binary data file types
|
||||
"*.dat, *.raw ; Binary data file types"
|
||||
]
|
||||
|
||||
var m_prop_id = gddb_constants.c_invalid_id
|
||||
var m_row_idx = gddb_constants.c_invalid_id
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
set_filters(PackedStringArray(file_filters))
|
||||
|
||||
# sets the property id
|
||||
func set_prop_id(prop_id : int) -> void :
|
||||
m_prop_id = prop_id
|
||||
|
||||
# returns the property id
|
||||
func get_prop_id() -> int :
|
||||
return m_prop_id
|
||||
|
||||
# sets the row index
|
||||
func set_row_idx(row_idx : int) -> void :
|
||||
m_row_idx = row_idx
|
||||
|
||||
# returns the row index
|
||||
func get_row_idx() -> int :
|
||||
return m_row_idx
|
||||
@@ -1,16 +0,0 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/load_res_path_dlg.gd" type="Script" id=1]
|
||||
|
||||
[node name="load_res_path_dlg" type="FileDialog"]
|
||||
anchor_right = 0.404
|
||||
anchor_bottom = 0.431
|
||||
offset_right = -0.400024
|
||||
offset_bottom = 0.0999756
|
||||
window_title = "Open a File"
|
||||
resizable = true
|
||||
mode = 0
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBNewDBDlg
|
||||
"""
|
||||
|
||||
class_name GDDBNewDBDlg
|
||||
|
||||
extends Window
|
||||
|
||||
signal create_new_db
|
||||
|
||||
var m_current_db_name = ""
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void :
|
||||
$v_layout/buttons/ok_btn.connect("pressed", Callable(self, "on_ok_btn_pressed"))
|
||||
$v_layout/buttons/cancel_btn.connect("pressed", Callable(self, "on_cancel_btn_pressed"))
|
||||
connect("about_to_popup", Callable(self, "on_about_to_show"))
|
||||
$v_layout/db_info/db_edt.connect("text_changed", Callable(self, "on_text_changed"))
|
||||
$v_layout/db_info/db_edt.connect("text_submitted", Callable(self, "on_text_confirmed"))
|
||||
|
||||
# Called when the node is about to be shown.
|
||||
func on_about_to_show() -> void :
|
||||
m_current_db_name = ""
|
||||
$v_layout/db_info/db_edt.set_text(m_current_db_name)
|
||||
|
||||
# called everytime the text is changed
|
||||
func on_text_changed(new_text: String) -> void :
|
||||
var change_text = true
|
||||
if(!gddb_globals.check_db_name(new_text)):
|
||||
change_text = false
|
||||
else:
|
||||
if(new_text.length() > gddb_constants.c_max_db_name_len):
|
||||
change_text = false
|
||||
else:
|
||||
change_text = true
|
||||
|
||||
if(change_text):
|
||||
m_current_db_name = $v_layout/db_info/db_edt.get_text()
|
||||
else:
|
||||
$v_layout/db_info/db_edt.set_text(m_current_db_name)
|
||||
$v_layout/db_info/db_edt.set_caret_column(m_current_db_name.length())
|
||||
|
||||
# called when the user presses the ENTER key
|
||||
func on_text_confirmed(text : String) -> void :
|
||||
# print("GDDBNewDBDlg::on_text_confirmed(" + text + ")")
|
||||
if(m_current_db_name.is_empty()):
|
||||
return
|
||||
handle_db_name()
|
||||
hide()
|
||||
|
||||
# called when the OK button is pressed
|
||||
func on_ok_btn_pressed() -> void :
|
||||
if(!m_current_db_name.is_empty()):
|
||||
handle_db_name()
|
||||
|
||||
# called when the Cancel button is pressed
|
||||
func on_cancel_btn_pressed() -> void :
|
||||
hide()
|
||||
|
||||
# handles the name of the database
|
||||
func handle_db_name() -> void :
|
||||
emit_signal("create_new_db", m_current_db_name)
|
||||
@@ -1,82 +0,0 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_14.tres" type="FontFile" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/new_db_dlg.gd" type="Script" id=2]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_12.tres" type="FontFile" id=3]
|
||||
|
||||
[node name="new_db_dlg" type="Window"]
|
||||
visible = true
|
||||
anchor_right = 0.257
|
||||
anchor_bottom = 0.1
|
||||
offset_right = 0.799988
|
||||
focus_next = NodePath("v_layout/db_info/db_edt")
|
||||
focus_mode = 2
|
||||
theme_override_fonts/title_font = ExtResource( 1 )
|
||||
exclusive = true
|
||||
window_title = "New database (max 16 characters)"
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_horizontal_guides_": [ 90.0781 ],
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="v_layout" type="VBoxContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
theme_override_constants/separation = 20
|
||||
alignment = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="db_info" type="HBoxContainer" parent="v_layout"]
|
||||
offset_top = 11.0
|
||||
offset_right = 412.0
|
||||
offset_bottom = 38.0
|
||||
alignment = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="db_lbl" type="Label" parent="v_layout/db_info"]
|
||||
offset_left = 18.0
|
||||
offset_top = 5.0
|
||||
offset_right = 89.0
|
||||
offset_bottom = 22.0
|
||||
theme_override_fonts/font = ExtResource( 1 )
|
||||
text = "DB name: "
|
||||
|
||||
[node name="db_edt" type="LineEdit" parent="v_layout/db_info"]
|
||||
offset_left = 93.0
|
||||
offset_right = 393.0
|
||||
offset_bottom = 27.0
|
||||
custom_minimum_size = Vector2( 300, 20 )
|
||||
theme_override_fonts/font = ExtResource( 1 )
|
||||
caret_blink = true
|
||||
caret_blink_interval = 0.5
|
||||
|
||||
[node name="buttons" type="HBoxContainer" parent="v_layout"]
|
||||
offset_top = 58.0
|
||||
offset_right = 412.0
|
||||
offset_bottom = 79.0
|
||||
theme_override_constants/separation = 80
|
||||
alignment = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ok_btn" type="Button" parent="v_layout/buttons"]
|
||||
offset_left = 66.0
|
||||
offset_right = 166.0
|
||||
offset_bottom = 21.0
|
||||
custom_minimum_size = Vector2( 100, 0 )
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
text = "OK"
|
||||
|
||||
[node name="cancel_btn" type="Button" parent="v_layout/buttons"]
|
||||
offset_left = 246.0
|
||||
offset_right = 346.0
|
||||
offset_bottom = 21.0
|
||||
custom_minimum_size = Vector2( 100, 0 )
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
text = "Cancel"
|
||||
@@ -1,83 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBNewDBDlg
|
||||
"""
|
||||
|
||||
class_name GDDBNewTableDlg
|
||||
|
||||
extends Window
|
||||
|
||||
signal create_new_table
|
||||
signal cancel_dialog
|
||||
|
||||
var m_dlg_type : int = gddb_types.e_new_dlg_type_new
|
||||
var m_table_id = gddb_constants.c_invalid_id
|
||||
var m_current_table_name = ""
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
$v_layout/buttons/ok_btn.connect("pressed", Callable(self, "on_ok_btn_pressed"))
|
||||
$v_layout/buttons/cancel_btn.connect("pressed", Callable(self, "on_cancel_btn_pressed"))
|
||||
$v_layout/table_info/table_edt.connect("text_changed", Callable(self, "on_text_changed"))
|
||||
$v_layout/table_info/table_edt.connect("text_submitted", Callable(self, "on_text_confirmed"))
|
||||
m_current_table_name = ""
|
||||
|
||||
# sets the type of the dialog
|
||||
func set_dld_type(dlg_type : int) -> void :
|
||||
m_dlg_type = dlg_type
|
||||
|
||||
# returns the dialog type
|
||||
func get_dlg_type() -> int :
|
||||
return m_dlg_type
|
||||
|
||||
# sets the table id
|
||||
func set_table_id(table_id : int) -> void:
|
||||
m_table_id = table_id
|
||||
|
||||
# returns the table id
|
||||
func get_table_id() -> int:
|
||||
return m_table_id
|
||||
|
||||
# sets the table name
|
||||
func set_init_name(table_name : String) -> void:
|
||||
# print("cNewTableDlg::set_init_name(" + name + ")")
|
||||
m_current_table_name = table_name
|
||||
$v_layout/table_info/table_edt.set_text(m_current_table_name)
|
||||
|
||||
func on_text_changed(new_text: String) -> void:
|
||||
var change_text = true
|
||||
if(!gddb_globals.check_db_name(new_text)):
|
||||
change_text = false
|
||||
else:
|
||||
if(new_text.length() > gddb_constants.c_max_db_name_len):
|
||||
change_text = false
|
||||
else:
|
||||
change_text = true
|
||||
|
||||
if(change_text):
|
||||
m_current_table_name = $v_layout/table_info/table_edt.get_text()
|
||||
else:
|
||||
$v_layout/table_info/table_edt.set_text(m_current_table_name)
|
||||
$v_layout/table_info/table_edt.set_caret_column(m_current_table_name.length())
|
||||
|
||||
# called when the user presses the ENTER key
|
||||
func on_text_confirmed(text : String) -> void:
|
||||
if(m_current_table_name.is_empty()):
|
||||
return
|
||||
handle_table_name()
|
||||
hide()
|
||||
|
||||
# called when the OK button is pressed
|
||||
func on_ok_btn_pressed() -> void:
|
||||
if(!m_current_table_name.is_empty()):
|
||||
handle_table_name()
|
||||
hide()
|
||||
|
||||
# called when the Cancel button is pressed
|
||||
func on_cancel_btn_pressed() -> void :
|
||||
hide()
|
||||
emit_signal("cancel_dialog")
|
||||
|
||||
# handles the text in the EditLine
|
||||
func handle_table_name() -> void:
|
||||
emit_signal("create_new_table", m_current_table_name)
|
||||
@@ -1,73 +0,0 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_12.tres" type="FontFile" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/new_table_dlg.gd" type="Script" id=2]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_14.tres" type="FontFile" id=3]
|
||||
|
||||
[node name="new_table_dlg" type="Window"]
|
||||
visible = true
|
||||
anchor_right = 0.257
|
||||
anchor_bottom = 0.084
|
||||
offset_right = 0.799988
|
||||
offset_bottom = 0.399994
|
||||
focus_next = NodePath("v_layout/table_info/table_edt")
|
||||
focus_mode = 1
|
||||
theme_override_fonts/title_font = ExtResource( 3 )
|
||||
exclusive = true
|
||||
window_title = "New table (max 16 characters)"
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="v_layout" type="VBoxContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
theme_override_constants/separation = 10
|
||||
alignment = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="table_info" type="HBoxContainer" parent="v_layout"]
|
||||
offset_top = 8.0
|
||||
offset_right = 412.0
|
||||
offset_bottom = 35.0
|
||||
alignment = 1
|
||||
|
||||
[node name="table_lbl" type="Label" parent="v_layout/table_info"]
|
||||
offset_left = 10.0
|
||||
offset_top = 5.0
|
||||
offset_right = 97.0
|
||||
offset_bottom = 22.0
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
text = "Table name: "
|
||||
|
||||
[node name="table_edt" type="LineEdit" parent="v_layout/table_info"]
|
||||
offset_left = 101.0
|
||||
offset_right = 401.0
|
||||
offset_bottom = 27.0
|
||||
custom_minimum_size = Vector2( 300, 20 )
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
caret_blink = true
|
||||
caret_blink_interval = 0.5
|
||||
|
||||
[node name="buttons" type="HBoxContainer" parent="v_layout"]
|
||||
offset_top = 45.0
|
||||
offset_right = 412.0
|
||||
offset_bottom = 66.0
|
||||
theme_override_constants/separation = 80
|
||||
alignment = 1
|
||||
|
||||
[node name="ok_btn" type="Button" parent="v_layout/buttons"]
|
||||
offset_left = 66.0
|
||||
offset_right = 166.0
|
||||
offset_bottom = 21.0
|
||||
custom_minimum_size = Vector2( 100, 0 )
|
||||
theme_override_fonts/font = ExtResource( 1 )
|
||||
text = "OK"
|
||||
|
||||
[node name="cancel_btn" type="Button" parent="v_layout/buttons"]
|
||||
offset_left = 246.0
|
||||
offset_right = 346.0
|
||||
offset_bottom = 21.0
|
||||
custom_minimum_size = Vector2( 100, 0 )
|
||||
theme_override_fonts/font = ExtResource( 1 )
|
||||
text = "Cancel"
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.7 KiB |
@@ -1,34 +0,0 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/icon.png-8476557a42180e1e377aacb0cfda943e.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/godot_db_manager/icon/icon.png"
|
||||
dest_files=[ "res://.import/icon.png-8476557a42180e1e377aacb0cfda943e.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
Binary file not shown.
@@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Radu Bolovan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,101 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBMenu
|
||||
"""
|
||||
|
||||
class_name GDDBMenu
|
||||
|
||||
extends Control
|
||||
|
||||
signal new_database
|
||||
signal load_database
|
||||
signal save_database
|
||||
signal save_database_as
|
||||
|
||||
enum {
|
||||
e_file_new_id = 0,
|
||||
e_file_load_id = 1
|
||||
e_file_save_id = 2,
|
||||
e_file_save_as_id = 3,
|
||||
|
||||
e_option_autosave_on_close_id = 4
|
||||
}
|
||||
|
||||
var m_enable_new_db = true
|
||||
var m_enable_load_db = true
|
||||
var m_enable_save_db = false
|
||||
var m_enable_save_as_db = false
|
||||
|
||||
var m_check_autosave_on_load = false
|
||||
|
||||
func _ready() -> void:
|
||||
$layout/File.connect("about_to_popup", Callable(self, "on_about_to_show_file_menu"))
|
||||
$layout/File.get_popup().clear()
|
||||
$layout/File.get_popup().add_item("New DB", e_file_new_id)
|
||||
$layout/File.get_popup().add_item("Load DB", e_file_load_id)
|
||||
$layout/File.get_popup().add_item("Save DB", e_file_save_id)
|
||||
$layout/File.get_popup().add_item("Save DB As ...", e_file_save_as_id)
|
||||
$layout/File.get_popup().connect("id_pressed", Callable(self, "on_file_id_pressed"))
|
||||
|
||||
$layout/Options.connect("about_to_popup", Callable(self, "on_about_to_show_options_menu"))
|
||||
$layout/Options.get_popup().clear()
|
||||
$layout/Options.get_popup().add_check_item("Autosave on close", e_option_autosave_on_close_id)
|
||||
$layout/Options.get_popup().connect("id_pressed", Callable(self, "on_options_id_pressed"))
|
||||
|
||||
# called before showing the file menu
|
||||
func on_about_to_show_file_menu() -> void:
|
||||
for idx in range(0, $layout/File.get_popup().get_item_count()):
|
||||
var item_id = $layout/File.get_popup().get_item_id(idx)
|
||||
if(item_id == e_file_new_id):
|
||||
$layout/File.get_popup().set_item_disabled(idx, !m_enable_new_db)
|
||||
elif(item_id == e_file_load_id):
|
||||
$layout/File.get_popup().set_item_disabled(idx, !m_enable_load_db)
|
||||
elif(item_id == e_file_save_id):
|
||||
$layout/File.get_popup().set_item_disabled(idx, !m_enable_save_db)
|
||||
elif(item_id == e_file_save_as_id):
|
||||
$layout/File.get_popup().set_item_disabled(idx, !m_enable_save_as_db)
|
||||
raise()
|
||||
|
||||
# enables / disables the possibility to create a new databbase
|
||||
func enable_file_new(enable) -> void:
|
||||
m_enable_new_db = enable
|
||||
|
||||
# enables / disables the possibility to load a databbase
|
||||
func enable_file_load(enable) -> void:
|
||||
m_enable_load_db = enable
|
||||
|
||||
# enables / disables the possibility to save a databbase
|
||||
func enable_file_save(enable) -> void:
|
||||
m_enable_save_db = enable
|
||||
|
||||
# enables / disables the possibility to save a databbase as another
|
||||
func enable_file_save_as(enable) -> void:
|
||||
m_enable_save_as_db = enable
|
||||
|
||||
# called when the user clicks on a file menu item
|
||||
func on_file_id_pressed(id : int) -> void:
|
||||
if(id == e_file_new_id):
|
||||
emit_signal("new_database")
|
||||
elif(id == e_file_load_id):
|
||||
emit_signal("load_database")
|
||||
elif(id == e_file_save_id):
|
||||
emit_signal("save_database")
|
||||
elif(id == e_file_save_as_id):
|
||||
emit_signal("save_database_as")
|
||||
|
||||
# called before showing the option menu
|
||||
func on_about_to_show_options_menu() -> void:
|
||||
for idx in range(0, $layout/Options.get_popup().get_item_count()):
|
||||
var item_id = $layout/Options.get_popup().get_item_id(idx)
|
||||
if(item_id == e_option_autosave_on_close_id):
|
||||
$layout/Options.get_popup().set_item_checked(idx, m_check_autosave_on_load)
|
||||
raise()
|
||||
|
||||
# enables / disables the possibility to autosave all databases on close
|
||||
func enable_autosave_on_close(enable) -> void:
|
||||
m_check_autosave_on_load = enable
|
||||
|
||||
# called when the user clicks on a options menu item
|
||||
func on_options_id_pressed(id : int) -> void:
|
||||
if(id == e_option_autosave_on_close_id):
|
||||
enable_autosave_on_close(!m_check_autosave_on_load)
|
||||
@@ -1,36 +0,0 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/menu.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_18.tres" type="FontFile" id=2]
|
||||
|
||||
[node name="menu" type="Control"]
|
||||
anchor_right = 1.0
|
||||
custom_minimum_size = Vector2( 0, 30 )
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_horizontal_guides_": [ 30.0 ],
|
||||
"_edit_use_anchors_": false,
|
||||
"_edit_vertical_guides_": [ 1024.0 ]
|
||||
}
|
||||
|
||||
[node name="layout" type="HBoxContainer" parent="."]
|
||||
offset_right = 1024.0
|
||||
offset_bottom = 30.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="File" type="MenuButton" parent="layout"]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 30.0
|
||||
theme_override_fonts/font = ExtResource( 2 )
|
||||
text = "File"
|
||||
items = [ "New DB", null, 0, false, false, 0, 0, null, "", false, "Load DB", null, 0, false, false, 1, 0, null, "", false, "Save DB", null, 0, false, false, 2, 0, null, "", false, "Save DB As ...", null, 0, false, false, 3, 0, null, "", false ]
|
||||
|
||||
[node name="Options" type="MenuButton" parent="layout"]
|
||||
offset_left = 44.0
|
||||
offset_right = 117.0
|
||||
offset_bottom = 30.0
|
||||
theme_override_fonts/font = ExtResource( 2 )
|
||||
text = "Options"
|
||||
items = [ "Autosave on close", null, 1, false, false, 4, 0, null, "", false ]
|
||||
@@ -1,7 +0,0 @@
|
||||
[plugin]
|
||||
|
||||
name="Godot Database Manager"
|
||||
description="A database manager plugin for Google Engine."
|
||||
author="Radu Bolovan"
|
||||
version="2.1.a"
|
||||
script="db_manager.gd"
|
||||
@@ -1,221 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBTableCell
|
||||
"""
|
||||
|
||||
class_name GDDBTableCell
|
||||
|
||||
extends Control
|
||||
|
||||
signal edit_data
|
||||
signal choose_resource
|
||||
signal choose_data
|
||||
signal edit_string
|
||||
|
||||
const c_cell_min_width = 150
|
||||
|
||||
var m_prop_id : int = -1
|
||||
var m_prop_type : int = gddb_constants.c_invalid_id
|
||||
var m_row_idx : int = -1
|
||||
var m_text : String = ""
|
||||
|
||||
func _ready() -> void :
|
||||
$LineEdit.connect("text_changed", Callable(self, "on_text_changed"))
|
||||
$LineEdit/edit_btn.connect("pressed", Callable(self, "on_edit_string"))
|
||||
|
||||
$Button.connect("pressed", Callable(self, "on_button_pressed"))
|
||||
$Button.set_clip_text(true)
|
||||
|
||||
$CheckBox.connect("toggled", Callable(self, "on_toggle_button"))
|
||||
|
||||
func _exit_tree() -> void :
|
||||
$LineEdit.disconnect("text_changed", Callable(self, "on_text_changed"))
|
||||
|
||||
# sets the property id
|
||||
func set_prop_id(id : int) -> void :
|
||||
m_prop_id = id
|
||||
|
||||
# returns the property id
|
||||
func get_prop_id() -> int :
|
||||
return m_prop_id
|
||||
|
||||
# sets property type
|
||||
func set_prop_type(data_type : int) -> void :
|
||||
# print("GDDBTableCell::set_prop_type(" + str(data_type) + ")")
|
||||
|
||||
var data_type_changed = false
|
||||
|
||||
if(m_prop_type != data_type):
|
||||
m_prop_type = data_type
|
||||
data_type_changed = true
|
||||
|
||||
if(!data_type_changed):
|
||||
return
|
||||
|
||||
if(m_prop_type == gddb_types.e_prop_type_bool):
|
||||
$LineEdit.hide()
|
||||
$Button.hide()
|
||||
$CheckBox.show()
|
||||
set_text("")
|
||||
elif(m_prop_type == gddb_types.e_prop_type_int):
|
||||
$LineEdit.show()
|
||||
$LineEdit/edit_btn.hide()
|
||||
$Button.hide()
|
||||
$CheckBox.hide()
|
||||
set_text("0")
|
||||
elif(m_prop_type == gddb_types.e_prop_type_float):
|
||||
$LineEdit.show()
|
||||
$LineEdit/edit_btn.hide()
|
||||
$Button.hide()
|
||||
$CheckBox.hide()
|
||||
set_text("0.0")
|
||||
elif(m_prop_type == gddb_types.e_prop_type_string):
|
||||
$LineEdit.show()
|
||||
$LineEdit/edit_btn.show()
|
||||
$Button.hide()
|
||||
$CheckBox.hide()
|
||||
set_text("")
|
||||
elif(m_prop_type == gddb_types.e_prop_type_resource):
|
||||
$LineEdit.hide()
|
||||
$Button.show()
|
||||
$CheckBox.hide()
|
||||
set_text("res://")
|
||||
elif(m_prop_type >= gddb_types.e_prop_types_count):
|
||||
$LineEdit.hide()
|
||||
$Button.show()
|
||||
$CheckBox.hide()
|
||||
set_text("{}")
|
||||
|
||||
func get_prop_type() -> int :
|
||||
return m_prop_type
|
||||
|
||||
# sets the row index
|
||||
func set_row_idx(idx : int) -> void :
|
||||
m_row_idx = idx
|
||||
|
||||
# returns the property index
|
||||
func get_row_idx() -> int :
|
||||
return m_row_idx
|
||||
|
||||
# sets the text
|
||||
func set_text(text : String) -> void :
|
||||
# print("GDDBTableCell::set_text(" + text + ")")
|
||||
m_text = text
|
||||
$LineEdit.set_text(m_text)
|
||||
$Button.set_text(m_text)
|
||||
if(m_prop_type == gddb_types.e_prop_type_bool):
|
||||
$CheckBox.set_pressed((text == "1"))
|
||||
|
||||
# sets autoincrement
|
||||
func enable_autoincrement(enable : bool) -> void :
|
||||
$LineEdit.set_editable(!enable)
|
||||
|
||||
# refreshes the width by the property name
|
||||
func refresh_width(prop_name : String) -> void :
|
||||
var size = get_custom_minimum_size()
|
||||
size.x = max(c_cell_min_width, get_font("normal_font").get_string_size(prop_name).x + 10)
|
||||
set_custom_minimum_size(size)
|
||||
|
||||
# called when the checkbox is toggled/untoggled
|
||||
func on_toggle_button(enable : bool) -> void :
|
||||
var data = "0"
|
||||
if(enable):
|
||||
data = "1"
|
||||
emit_signal("edit_data", m_prop_id, m_row_idx, data)
|
||||
|
||||
# called when the button is pressed
|
||||
func on_button_pressed() -> void :
|
||||
if(m_prop_type == gddb_types.e_prop_type_resource):
|
||||
# print("GDDBTableCell::on_button_pressed()")
|
||||
emit_signal("choose_resource", m_prop_id, m_row_idx)
|
||||
elif(m_prop_type >= gddb_types.e_prop_types_count):
|
||||
emit_signal("choose_data", m_prop_id, m_row_idx, m_prop_type)
|
||||
|
||||
# called when the edit string button is pressed
|
||||
func on_edit_string() -> void :
|
||||
emit_signal("edit_string", m_prop_id, m_row_idx, m_text)
|
||||
|
||||
# called when edit the data
|
||||
func on_text_changed(new_text : String) -> void :
|
||||
if(new_text.is_empty()):
|
||||
m_text = ""
|
||||
$LineEdit.set_text(m_text)
|
||||
$LineEdit.set_caret_column(0)
|
||||
return
|
||||
|
||||
if(m_prop_type == gddb_types.e_prop_type_int):
|
||||
if(!check_integer(new_text)):
|
||||
return
|
||||
|
||||
if(m_prop_type == gddb_types.e_prop_type_float):
|
||||
if(!check_float(new_text)):
|
||||
return
|
||||
|
||||
emit_signal("edit_data", m_prop_id, m_row_idx, new_text)
|
||||
|
||||
# checks if the text is integer
|
||||
func check_integer(text : String) -> bool :
|
||||
var is_negative = false
|
||||
|
||||
# check if the string is probably a number, but starts with "-"
|
||||
if(text.begins_with("-")):
|
||||
text.erase(0, 1)
|
||||
is_negative = true
|
||||
|
||||
# check if the current string is only "-"
|
||||
if(text.is_empty()):
|
||||
m_text = "-"
|
||||
$LineEdit.set_text(m_text)
|
||||
$LineEdit.set_caret_column(m_text.length())
|
||||
return true
|
||||
|
||||
if(text.is_valid_int()):
|
||||
if(text.begins_with("0")):
|
||||
# a negative integer cannot start with "0"
|
||||
if(is_negative):
|
||||
m_text = "-"
|
||||
$LineEdit.set_text(m_text)
|
||||
$LineEdit.set_caret_column(1)
|
||||
return true
|
||||
|
||||
# a positive number starting with "0" can be only "0"
|
||||
m_text = "0"
|
||||
$LineEdit.set_text(m_text)
|
||||
$LineEdit.set_caret_column(1)
|
||||
return true
|
||||
|
||||
# don't add more "-" in front of the number
|
||||
if(text.begins_with("-")):
|
||||
text.erase(0, 1)
|
||||
|
||||
# add back the "-"
|
||||
if(is_negative):
|
||||
m_text = "-" + text
|
||||
else:
|
||||
m_text = text
|
||||
|
||||
$LineEdit.set_text(m_text)
|
||||
$LineEdit.set_caret_column(m_text.length())
|
||||
return true
|
||||
|
||||
$LineEdit.set_text(m_text)
|
||||
$LineEdit.set_caret_column(m_text.length())
|
||||
return false
|
||||
|
||||
func check_float(text : String) -> bool :
|
||||
if(text.is_valid_float()):
|
||||
if(text.begins_with("00") || text.begins_with("01") || text.begins_with("02")
|
||||
|| text.begins_with("03") || text.begins_with("04") || text.begins_with("05")
|
||||
|| text.begins_with("06") || text.begins_with("07") || text.begins_with("08")
|
||||
|| text.begins_with("09")):
|
||||
m_text = "0"
|
||||
$LineEdit.set_text(m_text)
|
||||
$LineEdit.set_caret_column(1)
|
||||
return true
|
||||
|
||||
m_text = text
|
||||
return true
|
||||
|
||||
$LineEdit.set_text(m_text)
|
||||
$LineEdit.set_caret_column(m_text.length())
|
||||
return false
|
||||
@@ -1,72 +0,0 @@
|
||||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/tex/gui.png" type="Texture2D" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/table_cell.gd" type="Script" id=2]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_18.tres" type="FontFile" id=3]
|
||||
|
||||
[sub_resource type="AtlasTexture" id=1]
|
||||
atlas = ExtResource( 1 )
|
||||
region = Rect2( 28, 1.86734, 24, 24.1327 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=2]
|
||||
atlas = ExtResource( 1 )
|
||||
region = Rect2( 28, 54, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=3]
|
||||
atlas = ExtResource( 1 )
|
||||
region = Rect2( 28, 28, 24, 24 )
|
||||
|
||||
[node name="table_cell" type="Control"]
|
||||
anchor_right = 1.0
|
||||
offset_bottom = 15.36
|
||||
custom_minimum_size = Vector2( 150, 32 )
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_horizontal_guides_": [ 32.0 ],
|
||||
"_edit_use_anchors_": true
|
||||
}
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 0.914286
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
text = "TESTING WWW"
|
||||
caret_blink = true
|
||||
caret_blink_interval = 0.5
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": true
|
||||
}
|
||||
|
||||
[node name="edit_btn" type="TextureButton" parent="LineEdit"]
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -29.0
|
||||
offset_top = 4.0
|
||||
offset_right = -5.0
|
||||
offset_bottom = -4.0
|
||||
texture_normal = SubResource( 1 )
|
||||
texture_pressed = SubResource( 2 )
|
||||
texture_hover = SubResource( 3 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": true
|
||||
}
|
||||
|
||||
[node name="Button" type="Button" parent="."]
|
||||
visible = false
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
clip_text = true
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="CheckBox" type="CheckBox" parent="."]
|
||||
visible = false
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
@@ -1,433 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBTableEditor
|
||||
"""
|
||||
|
||||
class_name GDDBTableEditor
|
||||
|
||||
extends Control
|
||||
|
||||
signal set_dirty
|
||||
|
||||
var m_parent_table = null
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
$tabs/structure/header/new_property_btn.connect("pressed", Callable(self, "on_new_property_btn_pressed"))
|
||||
$tabs/data/add_data_btn.connect("pressed", Callable(self, "on_add_row_data_btn_pressed"))
|
||||
$tabs/data/add_data_btn.set_disabled(true)
|
||||
|
||||
$load_res_path_dlg.connect("file_selected", Callable(self, "on_select_res_path"))
|
||||
|
||||
$data_dlg.connect("select_data", Callable(self, "on_select_data"))
|
||||
|
||||
$edit_string_dlg.connect("string_edited", Callable(self, "on_text_edited"))
|
||||
|
||||
$delete_prop_dlg.connect("delete_prop", Callable(self, "on_confirm_delete_property"))
|
||||
|
||||
# called when resizing a property
|
||||
func on_resize_property(prop_id : int, diff_x : float) -> void :
|
||||
var current_prop = null
|
||||
for idx in range(0, $tabs/data/scroll/data_holder/data_header.get_child_count()):
|
||||
var prop = $tabs/data/scroll/data_holder/data_header.get_child(idx)
|
||||
if(prop.get_prop_id() == prop_id):
|
||||
current_prop = prop
|
||||
break
|
||||
|
||||
var prop_size : Vector2 = current_prop.get_child(0).get_size()
|
||||
|
||||
# print("diff_x: " + str(diff_x))
|
||||
prop_size.x += diff_x
|
||||
|
||||
if(prop_size.x < gddb_constants.c_min_cell_width):
|
||||
return
|
||||
if(prop_size.x > gddb_constants.c_max_cell_width):
|
||||
return
|
||||
|
||||
# print("prop_size.x = " + str(prop_size.x))
|
||||
|
||||
var prop_idx = -1
|
||||
|
||||
var data_size = $tabs/data/scroll.get_size()
|
||||
data_size.x += diff_x
|
||||
$tabs/data/scroll/data_holder/data_header.set_size(data_size)
|
||||
|
||||
for idx in range(0, $tabs/data/scroll/data_holder/data_header.get_child_count()):
|
||||
var prop = $tabs/data/scroll/data_holder/data_header.get_child(idx)
|
||||
if(prop.get_prop_id() == prop_id):
|
||||
var current_prop_size = prop.get_custom_minimum_size()
|
||||
current_prop_size.x += diff_x
|
||||
prop.set_custom_minimum_size(current_prop_size)
|
||||
prop_idx = idx
|
||||
|
||||
if(prop_idx != -1 && idx > prop_idx):
|
||||
var pos = prop.get_position()
|
||||
pos.x += diff_x
|
||||
prop.set_position(pos)
|
||||
|
||||
for idx in range(0, $tabs/data/scroll/data_holder/data_container.get_child_count()):
|
||||
var row = $tabs/data/scroll/data_holder/data_container.get_child(idx)
|
||||
for jdx in range(0, row.get_child_count()):
|
||||
var cell = row.get_child(jdx)
|
||||
if(cell.get_prop_id() == prop_id):
|
||||
cell.set_custom_minimum_size(prop_size)
|
||||
if(jdx > prop_idx):
|
||||
var pos = cell.get_position()
|
||||
pos.x += diff_x
|
||||
cell.set_position(pos)
|
||||
|
||||
# called when the new_property button is pressed
|
||||
func on_new_property_btn_pressed() -> void:
|
||||
# print("GDDBTableEditor::on_new_property_btn_pressed()")
|
||||
if(null == m_parent_table):
|
||||
print("ERROR: GDDBTableEditor::on_new_property_btn_pressed() - m_parent_table is null")
|
||||
return
|
||||
var prop_idx = m_parent_table.get_props_count()
|
||||
var prop_type = gddb_types.e_prop_type_bool
|
||||
var prop_name = "Property_" + str(prop_idx+1)
|
||||
var prop_id = m_parent_table.add_prop(prop_type, prop_name)
|
||||
add_prop_to_structure(prop_id, prop_type, prop_name)
|
||||
add_prop_to_data(prop_id, prop_type, prop_name, false)
|
||||
|
||||
# enable add data btn
|
||||
$tabs/data/add_data_btn.set_disabled(false)
|
||||
|
||||
emit_signal("set_dirty")
|
||||
|
||||
# adds a property to structure tab
|
||||
func add_prop_to_structure(prop_id : int, prop_type : int, prop_name : String) -> void:
|
||||
# print("GDDBTableEditor::add_prop_to_structure(" + str(prop_id) + ", " + str(prop_type) + ", " + prop_name + ")")
|
||||
var prop = load(gddb_constants.c_addon_main_path + "table_property.tscn").instantiate()
|
||||
$tabs/structure/scroll/properties.add_child(prop)
|
||||
prop.set_parent_table(m_parent_table)
|
||||
prop.setup(prop_id, prop_type, prop_name)
|
||||
prop.connect("edit_property", Callable(self, "on_edit_property"))
|
||||
prop.connect("delete_property", Callable(self, "on_delete_property"))
|
||||
prop.connect("enable_autoincrement", Callable(self, "on_enable_prop_autoincrement"))
|
||||
|
||||
# adds a property to data tab
|
||||
func add_prop_to_data(prop_id : int, prop_type : int, prop_name : String, has_autoincrement : bool) -> void:
|
||||
var prop = load(gddb_constants.c_addon_main_path + "data_label.tscn").instantiate()
|
||||
$tabs/data/scroll/data_holder/data_header.add_child(prop)
|
||||
prop.set_prop_id(prop_id)
|
||||
prop.set_text(prop_name)
|
||||
prop.connect("resize_property", Callable(self, "on_resize_property"))
|
||||
|
||||
# add property to the existing rows
|
||||
for idx in range(0, $tabs/data/scroll/data_holder/data_container.get_child_count()):
|
||||
var row = $tabs/data/scroll/data_holder/data_container.get_child(idx)
|
||||
var cell = load(gddb_constants.c_addon_main_path + "table_cell.tscn").instantiate()
|
||||
row.add_child(cell)
|
||||
cell.set_prop_id(prop_id)
|
||||
cell.set_row_idx(idx)
|
||||
cell.set_prop_type(prop_type)
|
||||
cell.set_text("")
|
||||
cell.enable_autoincrement(has_autoincrement)
|
||||
cell.connect("edit_data", Callable(self, "on_edit_data"))
|
||||
cell.connect("choose_resource", Callable(self, "on_choose_resource"))
|
||||
cell.connect("choose_data", Callable(self, "on_choose_data"))
|
||||
cell.connect("edit_string", Callable(self, "on_edit_string"))
|
||||
|
||||
# called when the add data button is pressed
|
||||
func on_add_row_data_btn_pressed() -> void:
|
||||
# print("GDDBTableEditor::on_add_row_data_btn_pressed")
|
||||
# add blank row in the table
|
||||
var row_idx = m_parent_table.get_rows_count()
|
||||
m_parent_table.add_blank_row()
|
||||
|
||||
# add row in the interface
|
||||
var row = HBoxContainer.new()
|
||||
$tabs/data/scroll/data_holder/data_container.add_child(row)
|
||||
for idx in range(0, $tabs/structure/scroll/properties.get_child_count()):
|
||||
var cell = load(gddb_constants.c_addon_main_path + "table_cell.tscn").instantiate()
|
||||
var prop = $tabs/structure/scroll/properties.get_child(idx)
|
||||
var db_prop = m_parent_table.get_prop_by_id(idx)
|
||||
row.add_child(cell)
|
||||
cell.set_prop_id(idx)
|
||||
cell.set_row_idx(row_idx)
|
||||
cell.set_prop_type(prop.get_prop_type())
|
||||
var autoincrement = db_prop.has_autoincrement()
|
||||
cell.enable_autoincrement(db_prop.has_autoincrement())
|
||||
if(autoincrement):
|
||||
cell.set_text(str(row_idx+1))
|
||||
cell.connect("edit_data", Callable(self, "on_edit_data"))
|
||||
cell.connect("choose_resource", Callable(self, "on_choose_resource"))
|
||||
cell.connect("choose_data", Callable(self, "on_choose_data"))
|
||||
cell.connect("edit_string", Callable(self, "on_edit_string"))
|
||||
|
||||
emit_signal("set_dirty")
|
||||
|
||||
# sets the table from database
|
||||
func set_table(table : Object) -> void:
|
||||
# print("GDDBTableEditor::set_table(" + table.get_table_name() + ")")
|
||||
clear_current_layout()
|
||||
|
||||
m_parent_table = table
|
||||
fill_properties()
|
||||
fill_data()
|
||||
|
||||
# fills the interface with current table's properties
|
||||
func fill_properties() -> void:
|
||||
# print("GDDBTableEditor::fill_properties()")
|
||||
var props_count = m_parent_table.get_props_count()
|
||||
for idx in range(0, props_count):
|
||||
var db_prop = m_parent_table.get_prop_at(idx)
|
||||
add_prop_to_structure(db_prop.get_prop_id(), db_prop.get_prop_type(), db_prop.get_prop_name())
|
||||
var prop = load(gddb_constants.c_addon_main_path + "data_label.tscn").instantiate()
|
||||
$tabs/data/scroll/data_holder/data_header.add_child(prop)
|
||||
prop.set_prop_id(db_prop.get_prop_id())
|
||||
prop.set_prop_type(db_prop.get_prop_type())
|
||||
prop.set_text(db_prop.get_prop_name())
|
||||
prop.connect("resize_property", Callable(self, "on_resize_property"))
|
||||
if(props_count > 0):
|
||||
$tabs/data/add_data_btn.set_disabled(false)
|
||||
|
||||
# fills the interface with current table's data
|
||||
func fill_data() -> void:
|
||||
#print("GDDBTableEditor::fill_data()")
|
||||
var rows_count = m_parent_table.get_rows_count()
|
||||
#print("Table name: " + m_parent_table.get_table_name())
|
||||
#print("rows_count: " + str(rows_count))
|
||||
for idx in range(0, rows_count):
|
||||
var row = HBoxContainer.new()
|
||||
$tabs/data/scroll/data_holder/data_container.add_child(row)
|
||||
var data_row = m_parent_table.get_data_at_row_idx(idx)
|
||||
for jdx in range(0, data_row.size()):
|
||||
var db_prop = m_parent_table.get_prop_at(jdx)
|
||||
#print("Prop id: " + str(db_prop.get_prop_id()))
|
||||
#print("Prop type: " + str(db_prop.get_prop_type()))
|
||||
#print("Prop name: " + str(db_prop.get_prop_name()))
|
||||
|
||||
var cell = load(gddb_constants.c_addon_main_path + "table_cell.tscn").instantiate()
|
||||
var cell_data = data_row[jdx].get_data()
|
||||
|
||||
var prop_type = db_prop.get_prop_type()
|
||||
if(prop_type >= gddb_types.e_prop_types_count):
|
||||
var db = m_parent_table.get_parent_database()
|
||||
var table = db.get_table_by_id(prop_type - gddb_types.e_prop_types_count)
|
||||
var data_row_idx = cell_data.to_int()
|
||||
cell_data = gddb_globals.get_json_from_row(table, data_row_idx)
|
||||
|
||||
row.add_child(cell)
|
||||
|
||||
cell.set_prop_id(data_row[jdx].get_prop_id())
|
||||
cell.set_row_idx(idx)
|
||||
cell.set_prop_type(prop_type)
|
||||
cell.set_text(cell_data)
|
||||
cell.enable_autoincrement(db_prop.has_autoincrement())
|
||||
cell.connect("edit_data", Callable(self, "on_edit_data"))
|
||||
cell.connect("choose_resource", Callable(self, "on_choose_resource"))
|
||||
cell.connect("choose_data", Callable(self, "on_choose_data"))
|
||||
cell.connect("edit_string", Callable(self, "on_edit_string"))
|
||||
|
||||
# links properties
|
||||
func link_props() -> void :
|
||||
# print("GDDBTableEditor::link_props() for table with name: " + m_parent_table.get_table_name())
|
||||
for idx in range(0, $tabs/structure/scroll/properties.get_child_count()):
|
||||
var prop = $tabs/structure/scroll/properties.get_child(idx)
|
||||
prop.link()
|
||||
|
||||
# refreshes autoincrement props
|
||||
func refresh_autoincrement_props(prop_id, enable) -> void:
|
||||
for idx in range(0, $tabs/data/scroll/data_holder/data_container.get_child_count()):
|
||||
var row = $tabs/data/scroll/data_holder/data_container.get_child(idx)
|
||||
for jdx in range(0, row.get_child_count()):
|
||||
var cell = row.get_child(jdx)
|
||||
if(cell.get_prop_id() == prop_id):
|
||||
cell.enable_autoincrement(enable)
|
||||
|
||||
# cleares current layout
|
||||
func clear_current_layout() -> void:
|
||||
# clear structure tab
|
||||
for idx in range(0, $tabs/structure/scroll/properties.get_child_count()):
|
||||
$tabs/structure/scroll/properties.get_child(idx).queue_free()
|
||||
|
||||
# clear data from data tab
|
||||
for idx in range(0, $tabs/data/scroll/data_holder/data_container.get_child_count()):
|
||||
var row = $tabs/data/scroll/data_holder/data_container.get_child(idx)
|
||||
for jdx in range(0, row.get_child_count()):
|
||||
row.get_child(jdx).queue_free()
|
||||
row.queue_free()
|
||||
|
||||
# clear properties from data tab
|
||||
for idx in range(0, $tabs/data/scroll/data_holder/data_header.get_child_count()):
|
||||
$tabs/data/scroll/data_holder/data_header.get_child(idx).queue_free()
|
||||
|
||||
$tabs/data/add_data_btn.set_disabled(true)
|
||||
|
||||
# called when a property is edited
|
||||
func on_edit_property(prop_id : int, prop_type : int, prop_name : String) -> void:
|
||||
"""
|
||||
print("GDDBTableEditor::on_edit_property(" + str(prop_id) + ", " + str(prop_type) + ", " + prop_name + ")")
|
||||
if(prop_type >= gddb_types.e_prop_types_count):
|
||||
var db = m_parent_table.get_parent_database()
|
||||
var selected_table = db.get_table_by_id(gddb_types.e_prop_types_count - prop_type)
|
||||
print("GDDBTableEditor::on_edit_property(" + str(prop_id) + ", " + selected_table.get_table_name() + ", " + prop_name + ")")
|
||||
else:
|
||||
print("GDDBTableEditor::on_edit_property(" + str(prop_id) + ", " + gddb_globals.get_data_name(prop_type) + ", " + prop_name + ")")
|
||||
#"""
|
||||
# edit prop in the table
|
||||
m_parent_table.edit_prop(prop_id, prop_type, prop_name)
|
||||
|
||||
# refresh the prop name in data tab
|
||||
for idx in range(0, $tabs/data/scroll/data_holder/data_header.get_child_count()):
|
||||
var prop = $tabs/data/scroll/data_holder/data_header.get_child(idx)
|
||||
if(prop.get_prop_id() == prop_id):
|
||||
prop.set_text(prop_name)
|
||||
|
||||
# update data type
|
||||
for idx in range(0, $tabs/data/scroll/data_holder/data_container.get_child_count()):
|
||||
var row = $tabs/data/scroll/data_holder/data_container.get_child(idx)
|
||||
for jdx in range(0, row.get_child_count()):
|
||||
var cell = row.get_child(jdx)
|
||||
if(cell.get_prop_id() == prop_id):
|
||||
"""
|
||||
if(prop_type < gddb_types.e_prop_types_count):
|
||||
print("Prop type: " + gddb_globals.get_data_name(prop_type))
|
||||
else:
|
||||
print("Prop type: custom")
|
||||
"""
|
||||
cell.set_prop_type(prop_type)
|
||||
|
||||
emit_signal("set_dirty")
|
||||
|
||||
# called when a property is deleted
|
||||
func on_delete_property(prop_id : int) -> void:
|
||||
# print("GDDBTableEditor::on_delete_property(" + str(prop_id) + ")")
|
||||
var prop = m_parent_table.get_prop_by_id(prop_id)
|
||||
$delete_prop_dlg.set_prop_id(prop_id)
|
||||
$delete_prop_dlg.set_prop_name(prop.get_prop_name())
|
||||
$delete_prop_dlg.popup_centered()
|
||||
|
||||
# called when a property is deleted
|
||||
func on_confirm_delete_property() -> void:
|
||||
var prop_id = $delete_prop_dlg.get_prop_id()
|
||||
|
||||
# deletes a property from table; also all data by this property
|
||||
m_parent_table.delete_prop(prop_id)
|
||||
|
||||
# delete cells from data tab
|
||||
for idx in range(0, $tabs/data/scroll/data_holder/data_container.get_child_count()):
|
||||
var row = $tabs/data/scroll/data_holder/data_container.get_child(idx)
|
||||
for jdx in range(0, row.get_child_count()):
|
||||
var cell = row.get_child(jdx)
|
||||
if(cell.get_prop_id() == prop_id):
|
||||
cell.disconnect("edit_data", Callable(self, "on_edit_data"))
|
||||
cell.queue_free()
|
||||
break
|
||||
|
||||
# delete property from data tab
|
||||
for idx in range(0, $tabs/data/scroll/data_holder/data_header.get_child_count()):
|
||||
var prop = $tabs/data/scroll/data_holder/data_header.get_child(idx)
|
||||
if(prop.get_prop_id() == prop_id):
|
||||
prop.queue_free()
|
||||
break
|
||||
|
||||
# delete prop from structure
|
||||
for idx in range(0, $tabs/structure/scroll/properties.get_child_count()):
|
||||
var prop = $tabs/structure/scroll/properties.get_child(idx)
|
||||
if(prop.get_prop_id() == prop_id):
|
||||
prop.queue_free()
|
||||
break
|
||||
|
||||
# refresh the add data button
|
||||
var props_count = m_parent_table.get_props_count()
|
||||
if(props_count == 0):
|
||||
$tabs/data/add_data_btn.set_disabled(true)
|
||||
|
||||
emit_signal("set_dirty")
|
||||
|
||||
# called when the property has autoincrement or not
|
||||
func on_enable_prop_autoincrement(prop_id : int, enable : bool) -> void :
|
||||
m_parent_table.enable_prop_autoincrement(prop_id, enable)
|
||||
emit_signal("set_dirty")
|
||||
refresh_autoincrement_props(prop_id, enable)
|
||||
|
||||
# reindex all data
|
||||
if(enable):
|
||||
for idx in range(0, $tabs/data/scroll/data_holder/data_container.get_child_count()):
|
||||
var row = $tabs/data/scroll/data_holder/data_container.get_child(idx)
|
||||
for jdx in range(0, row.get_child_count()):
|
||||
var cell = row.get_child(jdx)
|
||||
if(cell.get_prop_id() == prop_id):
|
||||
cell.set_text(str(idx + 1))
|
||||
|
||||
# called when edit data
|
||||
func on_edit_data(prop_id : int, row_idx : int, data : String) -> void:
|
||||
m_parent_table.edit_data(prop_id, row_idx, data)
|
||||
emit_signal("set_dirty")
|
||||
|
||||
# called when choosing a resource
|
||||
func on_choose_resource(prop_id : int, row_idx : int) -> void:
|
||||
# print("GDDBTableEditor::on_choose_resource(" + str(prop_id) + ", " + str(row_idx) + ")")
|
||||
$load_res_path_dlg.set_prop_id(prop_id)
|
||||
$load_res_path_dlg.set_row_idx(row_idx)
|
||||
$load_res_path_dlg.popup_centered()
|
||||
|
||||
# called when choosing a data
|
||||
func on_choose_data(prop_id : int, row_idx : int, prop_type : int) -> void:
|
||||
# print("GDDBTableEditor::on_choose_data(" + str(prop_id) + ", " + str(row_idx) + ", " + str(prop_type) + ")")
|
||||
$data_dlg.set_prop_id(prop_id)
|
||||
$data_dlg.set_row_idx(row_idx)
|
||||
var table_id = prop_type - gddb_types.e_prop_types_count
|
||||
var db = m_parent_table.get_parent_database()
|
||||
var tbl = db.get_table_by_id(table_id)
|
||||
$data_dlg.set_table(tbl)
|
||||
$data_dlg.popup_centered()
|
||||
|
||||
# called when choosing to edit string
|
||||
func on_edit_string(prop_id : int, row_idx : int, text : String) -> void:
|
||||
$edit_string_dlg.set_prop_id(prop_id)
|
||||
$edit_string_dlg.set_row_idx(row_idx)
|
||||
$edit_string_dlg.set_data_text(text)
|
||||
$edit_string_dlg.popup_centered()
|
||||
|
||||
# called when selecting a resource filepath
|
||||
func on_select_res_path(filepath : String) -> void:
|
||||
# print("GDDBTableEditor::on_select_res_path(" + filepath + ")")
|
||||
var prop_id = $load_res_path_dlg.get_prop_id()
|
||||
var row_idx = $load_res_path_dlg.get_row_idx()
|
||||
m_parent_table.edit_data(prop_id, row_idx, filepath)
|
||||
var row = $tabs/data/scroll/data_holder/data_container.get_child(row_idx)
|
||||
for idx in range(0, row.get_child_count()):
|
||||
var cell = row.get_child(idx)
|
||||
if(cell.get_prop_id() == prop_id):
|
||||
cell.set_text(filepath)
|
||||
|
||||
emit_signal("set_dirty")
|
||||
|
||||
# called when data from a table is choosen
|
||||
func on_select_data(prop_id : int, row_idx : int, data_row_idx : int, data : String) -> void:
|
||||
# set the data in the databes / table
|
||||
m_parent_table.edit_data(prop_id, row_idx, str(data_row_idx))
|
||||
|
||||
# fill in the interface cell with data
|
||||
var row = $tabs/data/scroll/data_holder/data_container.get_child(row_idx)
|
||||
for idx in range(0, row.get_child_count()):
|
||||
var cell = row.get_child(idx)
|
||||
if(cell.get_prop_id() == prop_id):
|
||||
cell.set_text(data)
|
||||
break
|
||||
|
||||
emit_signal("set_dirty")
|
||||
|
||||
# called when the text is edited
|
||||
func on_text_edited():
|
||||
var prop_id = $edit_string_dlg.get_prop_id()
|
||||
var row_idx = $edit_string_dlg.get_row_idx()
|
||||
var text_data = $edit_string_dlg.get_data_text()
|
||||
|
||||
var data = gddb_globals.handle_string(text_data)
|
||||
|
||||
# print("GDDBTableEditor::on_text_edited() - prop_id: " + str(prop_id) + ", row_idx: " + str(row_idx) + ", data: " + text_data)
|
||||
|
||||
m_parent_table.edit_data(prop_id, row_idx, data)
|
||||
|
||||
var row = $tabs/data/scroll/data_holder/data_container.get_child(row_idx)
|
||||
for idx in range(0, row.get_child_count()):
|
||||
var cell = row.get_child(idx)
|
||||
if(cell.get_prop_id() == prop_id):
|
||||
cell.set_text(text_data)
|
||||
break
|
||||
|
||||
emit_signal("set_dirty")
|
||||
@@ -1,161 +0,0 @@
|
||||
[gd_scene load_steps=16 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/error_dlg.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/load_res_path_dlg.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://addons/godot_db_manager/table_editor.gd" type="Script" id=3]
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/data_dlg.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/edit_string_dlg.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://addons/godot_db_manager/dlgs/delete_prop_dlg.tscn" type="PackedScene" id=6]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_18.tres" type="FontFile" id=7]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/tex/gui.png" type="Texture2D" id=8]
|
||||
|
||||
[sub_resource type="AtlasTexture" id=1]
|
||||
atlas = ExtResource( 8 )
|
||||
region = Rect2( 2, 2, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=2]
|
||||
atlas = ExtResource( 8 )
|
||||
region = Rect2( 2, 54, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=3]
|
||||
atlas = ExtResource( 8 )
|
||||
region = Rect2( 2, 28, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=4]
|
||||
atlas = ExtResource( 8 )
|
||||
region = Rect2( 2, 2, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=5]
|
||||
atlas = ExtResource( 8 )
|
||||
region = Rect2( 2, 54, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=6]
|
||||
atlas = ExtResource( 8 )
|
||||
region = Rect2( 2, 28, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=7]
|
||||
atlas = ExtResource( 8 )
|
||||
region = Rect2( 132, 2, 24, 24 )
|
||||
|
||||
[node name="table" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource( 3 )
|
||||
__meta__ = {
|
||||
"_edit_horizontal_guides_": [ 584.0, 64.0, 70.0 ],
|
||||
"_edit_use_anchors_": false,
|
||||
"_edit_vertical_guides_": [ 1000.47 ]
|
||||
}
|
||||
|
||||
[node name="tabs" type="TabContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
theme_override_fonts/font = ExtResource( 7 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="structure" type="TabBar" parent="tabs"]
|
||||
visible = false
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 4.0
|
||||
offset_top = 40.0
|
||||
offset_right = -4.0
|
||||
offset_bottom = -4.0
|
||||
tab_close_display_policy = 2
|
||||
|
||||
[node name="header" type="HBoxContainer" parent="tabs/structure"]
|
||||
offset_right = 892.0
|
||||
offset_bottom = 24.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="new_property_btn" type="TextureButton" parent="tabs/structure/header"]
|
||||
offset_right = 24.0
|
||||
offset_bottom = 24.0
|
||||
texture_normal = SubResource( 1 )
|
||||
texture_pressed = SubResource( 2 )
|
||||
texture_hover = SubResource( 3 )
|
||||
|
||||
[node name="props_lbl" type="Label" parent="tabs/structure/header"]
|
||||
offset_left = 28.0
|
||||
offset_top = 1.0
|
||||
offset_right = 114.0
|
||||
offset_bottom = 23.0
|
||||
theme_override_fonts/font = ExtResource( 7 )
|
||||
text = "Properties:"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="scroll" type="ScrollContainer" parent="tabs/structure"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 30.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="properties" type="VBoxContainer" parent="tabs/structure/scroll"]
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="data" type="TabBar" parent="tabs"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 4.0
|
||||
offset_top = 40.0
|
||||
offset_right = -4.0
|
||||
offset_bottom = -4.0
|
||||
tab_close_display_policy = 2
|
||||
|
||||
[node name="add_data_btn" type="TextureButton" parent="tabs/data"]
|
||||
offset_right = 24.0
|
||||
offset_bottom = 24.0
|
||||
disabled = true
|
||||
texture_normal = SubResource( 4 )
|
||||
texture_pressed = SubResource( 5 )
|
||||
texture_hover = SubResource( 6 )
|
||||
texture_disabled = SubResource( 7 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="scroll" type="ScrollContainer" parent="tabs/data"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 38.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="data_holder" type="VBoxContainer" parent="tabs/data/scroll"]
|
||||
offset_bottom = 36.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="data_header" type="HBoxContainer" parent="tabs/data/scroll/data_holder"]
|
||||
offset_bottom = 32.0
|
||||
custom_minimum_size = Vector2( 0, 32 )
|
||||
clip_contents = true
|
||||
|
||||
[node name="data_container" type="VBoxContainer" parent="tabs/data/scroll/data_holder"]
|
||||
offset_top = 36.0
|
||||
offset_bottom = 36.0
|
||||
|
||||
[node name="error_dlg" parent="." instance=ExtResource( 1 )]
|
||||
visible = false
|
||||
|
||||
[node name="load_res_path_dlg" parent="." instance=ExtResource( 2 )]
|
||||
filters = PackedStringArray( "*.res, *.tres ; Godot resource file types", "*.scn, *.tscn, *escn ; Godot scene file types", "*.gd, *.cs, *.h, *.c, *.hpp, *.cpp ; Code file types", "*.shader ; Shader file types", "*.mat ; Material file types", "*.dae, *.gltf, *.obj, *.fbx ; Mesh file types", "*.anim ; Animation file types", "*.ttf, *.otf ; Font file types", "*.png, *.jpg, *.jpeg, *.tiff, *.tga, *.bmp, *.webp, *.gif, *.hdr ; Images file types", "*.snd, *.wav, *.ogg, *.mp3 ; Sound file types", "*.ogg, *.mpg, *.mpeg, *.avi, *.mov, *.mp4, *.webm ; Video file types", "*.txt, *.csv, *.json, *.xml, *.cfg, *.ini ; Text file types", "*.doc, *.docx, *.xls, *.xlsx, *.odt, *.ods, *.pdf ; Doc file types", "*.dat, *.raw ; Binary data file types" )
|
||||
|
||||
[node name="data_dlg" parent="." instance=ExtResource( 4 )]
|
||||
|
||||
[node name="edit_string_dlg" parent="." instance=ExtResource( 5 )]
|
||||
|
||||
[node name="delete_prop_dlg" parent="." instance=ExtResource( 6 )]
|
||||
visible = false
|
||||
@@ -1,67 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBTableItem
|
||||
"""
|
||||
|
||||
class_name GDDBTableItem
|
||||
|
||||
extends Control
|
||||
|
||||
signal select_item
|
||||
signal edit_table
|
||||
signal delete_table
|
||||
|
||||
var m_table_id = gddb_constants.c_invalid_id
|
||||
var m_table_name = ""
|
||||
|
||||
var m_is_selected = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
$select_btn.connect("pressed", Callable(self, "on_select_btn_pressed"))
|
||||
$edit_table_btn.connect("pressed", Callable(self, "on_edit_table_btn_pressed"))
|
||||
$delete_table_btn.connect("pressed", Callable(self, "on_delete_table_btn_pressed"))
|
||||
$select.hide()
|
||||
|
||||
# sets the table id
|
||||
func set_table_id(id : int) -> void:
|
||||
m_table_id = id
|
||||
|
||||
# returns the table id
|
||||
func get_table_id() -> int:
|
||||
return m_table_id
|
||||
|
||||
func set_selected(select : bool) -> void :
|
||||
m_is_selected = select
|
||||
if(m_is_selected):
|
||||
$select.show()
|
||||
else:
|
||||
$select.hide()
|
||||
|
||||
func is_selected():
|
||||
return m_is_selected
|
||||
|
||||
# sets the table name
|
||||
func set_table_name(name : String) -> void:
|
||||
# print("GDDBTableItem::set_table_name(" + name + ")")
|
||||
m_table_name = name
|
||||
$table_name.set_text(m_table_name)
|
||||
|
||||
# returns the table name
|
||||
func get_table_name() -> String:
|
||||
return m_table_name
|
||||
|
||||
# called when the user presses the edit_table button
|
||||
func on_edit_table_btn_pressed():
|
||||
# print("GDDBTableItem::on_edit_table_btn_pressed")
|
||||
emit_signal("edit_table", m_table_id, m_table_name)
|
||||
|
||||
# called when the user presses the delete_table button
|
||||
func on_delete_table_btn_pressed():
|
||||
# print("GDDBTableItem::on_delete_table_btn_pressed")
|
||||
emit_signal("delete_table", m_table_id)
|
||||
|
||||
# called when select_btn is pressed
|
||||
func on_select_btn_pressed() -> void:
|
||||
# print("GDDBTableItem::on_select_btn_pressed()")
|
||||
emit_signal("select_item", m_table_id)
|
||||
@@ -1,109 +0,0 @@
|
||||
[gd_scene load_steps=11 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_18.tres" type="FontFile" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/tex/gui.png" type="Texture2D" id=2]
|
||||
[ext_resource path="res://addons/godot_db_manager/table_item.gd" type="Script" id=3]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/tex/debug.png" type="Texture2D" id=4]
|
||||
|
||||
[sub_resource type="AtlasTexture" id=1]
|
||||
atlas = ExtResource( 2 )
|
||||
region = Rect2( 28, 2, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=2]
|
||||
atlas = ExtResource( 2 )
|
||||
region = Rect2( 28, 54, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=3]
|
||||
atlas = ExtResource( 2 )
|
||||
region = Rect2( 28, 28, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=4]
|
||||
atlas = ExtResource( 2 )
|
||||
region = Rect2( 54, 2, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=5]
|
||||
atlas = ExtResource( 2 )
|
||||
region = Rect2( 54, 54, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=6]
|
||||
atlas = ExtResource( 2 )
|
||||
region = Rect2( 54, 28, 24, 24 )
|
||||
|
||||
[node name="table_item" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 0.021
|
||||
offset_bottom = 0.399998
|
||||
custom_minimum_size = Vector2( 180, 34 )
|
||||
script = ExtResource( 3 )
|
||||
__meta__ = {
|
||||
"_edit_horizontal_guides_": [ 34.0 ],
|
||||
"_edit_use_anchors_": false,
|
||||
"_edit_vertical_guides_": [ 170.0 ]
|
||||
}
|
||||
|
||||
[node name="dbg" type="NinePatchRect" parent="."]
|
||||
visible = false
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
texture = ExtResource( 4 )
|
||||
region_rect = Rect2( 38, 38, 10, 10 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="select" type="NinePatchRect" parent="."]
|
||||
visible = false
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
texture = ExtResource( 2 )
|
||||
region_rect = Rect2( 80, 6, 24, 4 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="table_name" type="Label" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_right = -6.10352e-05
|
||||
offset_bottom = -4.0
|
||||
custom_minimum_size = Vector2( 100, 0 )
|
||||
theme_override_fonts/font = ExtResource( 1 )
|
||||
text = "Table_999"
|
||||
valign = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="select_btn" type="TextureButton" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="edit_table_btn" type="TextureButton" parent="."]
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -56.0
|
||||
offset_top = 5.0
|
||||
offset_right = -32.0
|
||||
offset_bottom = -5.0
|
||||
texture_normal = SubResource( 1 )
|
||||
texture_pressed = SubResource( 2 )
|
||||
texture_hover = SubResource( 3 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="delete_table_btn" type="TextureButton" parent="."]
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -28.0
|
||||
offset_top = 5.0
|
||||
offset_right = -4.0
|
||||
offset_bottom = -5.0
|
||||
texture_normal = SubResource( 4 )
|
||||
texture_pressed = SubResource( 5 )
|
||||
texture_hover = SubResource( 6 )
|
||||
@@ -1,195 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBTableProperty
|
||||
"""
|
||||
|
||||
class_name GDDBTableProperty
|
||||
|
||||
extends Control
|
||||
|
||||
signal delete_property
|
||||
signal edit_property
|
||||
signal enable_autoincrement
|
||||
|
||||
var m_prop_id : int = -1
|
||||
var m_prop_type : int = 0
|
||||
var m_prop_name : String = ""
|
||||
|
||||
var m_parent_table = null
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
$prop_name.connect("text_changed", Callable(self, "on_name_changed"))
|
||||
|
||||
$prop_type.clear()
|
||||
for idx in range(0, gddb_types.e_prop_types_count):
|
||||
$prop_type.add_item(gddb_globals.get_data_name(idx), gddb_types.e_prop_type_bool + idx)
|
||||
$prop_type.select(0)
|
||||
|
||||
$prop_type.get_popup().connect("about_to_popup", Callable(self, "on_about_to_show"))
|
||||
$prop_type.connect("item_selected", Callable(self, "on_type_changed"))
|
||||
|
||||
$delete_button.connect("pressed", Callable(self, "on_delete_button_pressed"))
|
||||
|
||||
$autoincrement_btn.hide()
|
||||
$autoincrement_btn.connect("toggled", Callable(self, "on_set_autoincrement"))
|
||||
|
||||
# setup property
|
||||
func setup(prop_id : int, prop_type : int, prop_name : String) -> void:
|
||||
"""
|
||||
if(prop_type < gddb_types.e_prop_types_count):
|
||||
print("GDDBTableProperty::setup(" + str(prop_id) + ", " + gddb_globals.get_data_name(prop_type) + ", " + prop_name + ")")
|
||||
else:
|
||||
var db = m_parent_table.get_parent_database()
|
||||
var table = db.get_table_by_id(prop_type - gddb_types.e_prop_types_count)
|
||||
print("GDDBTableProperty::setup(" + str(prop_id) + ", " + table.get_table_name() + ", " + prop_name + ")")
|
||||
#"""
|
||||
set_prop_id(prop_id)
|
||||
set_prop_type(prop_type)
|
||||
set_prop_name(prop_name)
|
||||
|
||||
# sets parent table
|
||||
func set_parent_table(table):
|
||||
#print("GDDBTableProperty::set_parent_table(" + str(table) + ")")
|
||||
m_parent_table = table
|
||||
var db = m_parent_table.get_parent_database()
|
||||
for idx in range(0, db.get_tables_count()):
|
||||
var tbl = db.get_table_at(idx)
|
||||
if(tbl == m_parent_table):
|
||||
continue
|
||||
$prop_type.add_item(tbl.get_table_name(), gddb_types.e_prop_types_count + tbl.get_table_id())
|
||||
|
||||
# sets proprty id
|
||||
func set_prop_id(prop_id : int) -> void:
|
||||
# print("GDDBTableProperty::set_prop_id(" + str(prop_id) + ")")
|
||||
m_prop_id = prop_id
|
||||
|
||||
# returns property id
|
||||
func get_prop_id() -> int:
|
||||
return m_prop_id
|
||||
|
||||
# sets property type
|
||||
func set_prop_type(prop_type : int) -> void:
|
||||
"""
|
||||
print("GDDBTableProperty::set_prop_type(" + str(prop_type) + ")")
|
||||
if(prop_type < gddb_types.e_prop_types_count):
|
||||
print("GDDBTableProperty::set_prop_type(" + gddb_globals.get_data_name(prop_type) + ")")
|
||||
else:
|
||||
var db = m_parent_table.get_parent_database()
|
||||
var table = db.get_table_by_id(prop_type - gddb_types.e_prop_types_count)
|
||||
print("GDDBTableProperty::set_prop_type(" + table.get_table_name() + ")")
|
||||
#"""
|
||||
#if(prop_type >= gddb_types.e_prop_types_count):
|
||||
# print("GDDBTableProperty::set_prop_type(" + str(prop_type) + ")")
|
||||
m_prop_type = prop_type
|
||||
select_current_prop()
|
||||
|
||||
if(m_prop_type == gddb_types.e_prop_type_int):
|
||||
$autoincrement_btn.show()
|
||||
var prop = m_parent_table.get_prop_by_id(m_prop_id)
|
||||
if(prop.has_autoincrement()):
|
||||
$autoincrement_btn.set_pressed(true)
|
||||
else:
|
||||
$autoincrement_btn.hide()
|
||||
|
||||
# selects current property
|
||||
func select_current_prop() -> void:
|
||||
if(m_prop_type < gddb_types.e_prop_types_count):
|
||||
$prop_type.select(m_prop_type)
|
||||
|
||||
# links property type to other tables
|
||||
func link():
|
||||
# print("GDDBTableProperty::link()")
|
||||
refill_list()
|
||||
if(m_prop_type >= gddb_types.e_prop_types_count):
|
||||
"""
|
||||
print("m_prop_id : " + str(m_prop_id))
|
||||
print("m_prop_type : " + str(m_prop_type))
|
||||
print("m_prop_name : " + m_prop_name)
|
||||
"""
|
||||
set_selection_by_id(m_prop_type)
|
||||
else:
|
||||
$prop_type.select(m_prop_type)
|
||||
|
||||
# returns property type
|
||||
func get_prop_type() -> int:
|
||||
return m_prop_type
|
||||
|
||||
# sets property name
|
||||
func set_prop_name(prop_name : String) -> void:
|
||||
# print("GDDBTableProperty::set_prop_name(" + prop_name + ")")
|
||||
m_prop_name = prop_name
|
||||
$prop_name.set_text(m_prop_name)
|
||||
|
||||
# returns property name
|
||||
func get_prop_name() -> String:
|
||||
return m_prop_name
|
||||
|
||||
# called everytime the name of the property is changed
|
||||
func on_name_changed(new_text : String) -> void:
|
||||
m_prop_name = new_text
|
||||
emit_signal("edit_property", m_prop_id, m_prop_type, m_prop_name)
|
||||
|
||||
# called when the popup from option button is about to be shown
|
||||
func on_about_to_show():
|
||||
var selected_id = $prop_type.get_selected_id()
|
||||
# print("GDDBTableProperty::on_about_to_show() - " + str(selected_id))
|
||||
|
||||
refill_list()
|
||||
set_selection_by_id(selected_id)
|
||||
|
||||
# refills the list
|
||||
func refill_list() -> void :
|
||||
$prop_type.clear()
|
||||
for idx in range(0, gddb_types.e_prop_types_count):
|
||||
$prop_type.add_item(gddb_globals.get_data_name(idx), gddb_types.e_prop_type_bool + idx)
|
||||
|
||||
if(null != m_parent_table):
|
||||
var db = m_parent_table.get_parent_database()
|
||||
for idx in range(0, db.get_tables_count()):
|
||||
var table = db.get_table_at(idx)
|
||||
if(table == m_parent_table):
|
||||
continue
|
||||
"""
|
||||
print("GDDBTableProperty::refill_list - Add:")
|
||||
print("table id: " + str(table.get_table_id()))
|
||||
print("table name: " + table.get_table_name())
|
||||
#"""
|
||||
# print("GDDBTableProperty::prop_type.add_item(" + table.get_table_name() + ", " + str(gddb_types.e_prop_types_count + table.get_table_id()) + ")" )
|
||||
$prop_type.add_item(table.get_table_name(), gddb_types.e_prop_types_count + table.get_table_id())
|
||||
# $prop_type.select(selected_idx)
|
||||
|
||||
# sets selection
|
||||
func set_selection_by_id(selected_id : int) -> void :
|
||||
# print("GDDBTableProperty::set_selection_by_id(" + str(selected_id) + ")")
|
||||
for idx in range(0, $prop_type.get_item_count()):
|
||||
if($prop_type.get_item_id(idx) == selected_id):
|
||||
$prop_type.select(idx)
|
||||
break
|
||||
|
||||
func on_set_autoincrement(enable : bool) -> void:
|
||||
# print("GDDBTableProperty::on_set_autoincrement(" + str(enable) + ") - " + str(m_prop_id))
|
||||
emit_signal("enable_autoincrement", m_prop_id, enable)
|
||||
|
||||
# called everytime the type of the property is changed
|
||||
func on_type_changed(option_idx : int) -> void:
|
||||
var option_id = $prop_type.get_item_id(option_idx)
|
||||
"""
|
||||
print("GDDBTableProperty::on_type_changed(" + str(option_idx) + ")")
|
||||
print("option_id = " + str(option_id))
|
||||
if(option_id >= gddb_types.e_prop_types_count):
|
||||
print("GDDBTableProperty::on_type_changed(" + str(option_id) + ")")
|
||||
else:
|
||||
print("GDDBTableProperty::on_type_changed(" + gddb_globals.get_data_name(option_id) + ")")
|
||||
#"""
|
||||
m_prop_type = option_id
|
||||
$autoincrement_btn.set_pressed(false)
|
||||
if(m_prop_type == gddb_types.e_prop_type_int):
|
||||
$autoincrement_btn.show()
|
||||
else:
|
||||
$autoincrement_btn.hide()
|
||||
emit_signal("edit_property", m_prop_id, m_prop_type, m_prop_name)
|
||||
|
||||
# called when the delete property button is pressed
|
||||
func on_delete_button_pressed() -> void:
|
||||
emit_signal("delete_property", m_prop_id)
|
||||
@@ -1,89 +0,0 @@
|
||||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/tex/gui.png" type="Texture2D" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/table_property.gd" type="Script" id=2]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_18.tres" type="FontFile" id=3]
|
||||
|
||||
[sub_resource type="AtlasTexture" id=1]
|
||||
atlas = ExtResource( 1 )
|
||||
region = Rect2( 54, 2, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=2]
|
||||
atlas = ExtResource( 1 )
|
||||
region = Rect2( 54, 54, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=3]
|
||||
atlas = ExtResource( 1 )
|
||||
region = Rect2( 54, 28, 24, 24 )
|
||||
|
||||
[node name="table_property" type="Control"]
|
||||
anchor_right = 1.0
|
||||
offset_bottom = 15.36
|
||||
custom_minimum_size = Vector2( 900, 32 )
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_horizontal_guides_": [ 32.0 ],
|
||||
"_edit_use_anchors_": true
|
||||
}
|
||||
|
||||
[node name="delete_button" type="TextureButton" parent="."]
|
||||
offset_left = 3.0
|
||||
offset_top = 4.0
|
||||
offset_right = 27.0
|
||||
offset_bottom = 28.0
|
||||
texture_normal = SubResource( 1 )
|
||||
texture_pressed = SubResource( 2 )
|
||||
texture_hover = SubResource( 3 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="prop_name_label" type="Label" parent="."]
|
||||
offset_left = 28.0
|
||||
offset_top = 2.0
|
||||
offset_right = 97.0
|
||||
offset_bottom = 24.0
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
text = " Name:"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="prop_name" type="LineEdit" parent="."]
|
||||
offset_left = 109.0
|
||||
offset_right = 409.0
|
||||
offset_bottom = 32.0
|
||||
custom_minimum_size = Vector2( 300, 0 )
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="type_label" type="Label" parent="."]
|
||||
offset_left = 413.0
|
||||
offset_top = 2.0
|
||||
offset_right = 473.0
|
||||
offset_bottom = 24.0
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
text = " Type:"
|
||||
|
||||
[node name="prop_type" type="OptionButton" parent="."]
|
||||
offset_left = 485.0
|
||||
offset_right = 735.0
|
||||
offset_bottom = 32.0
|
||||
custom_minimum_size = Vector2( 250, 0 )
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
text = "Bool"
|
||||
items = [ "Bool", null, false, 0, null, "Integer", null, false, 1, null, "Float", null, false, 2, null, "String", null, false, 3, null, "Resource", null, false, 4, null ]
|
||||
selected = 0
|
||||
|
||||
[node name="autoincrement_btn" type="CheckBox" parent="."]
|
||||
visible = false
|
||||
offset_left = 740.0
|
||||
offset_right = 891.0
|
||||
offset_bottom = 32.0
|
||||
theme_override_fonts/font = ExtResource( 3 )
|
||||
text = "Auto increment"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBTablesHeader
|
||||
"""
|
||||
|
||||
class_name GDDBTablesHeader
|
||||
|
||||
extends Control
|
||||
|
||||
signal add_table
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
$add_table_btn.connect("pressed", Callable(self, "on_add_table_btn_pressed"))
|
||||
|
||||
func on_add_table_btn_pressed():
|
||||
emit_signal("add_table")
|
||||
@@ -1,65 +0,0 @@
|
||||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/fnt/roboto_20.tres" type="FontFile" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/tables_header.gd" type="Script" id=2]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/tex/gui.png" type="Texture2D" id=3]
|
||||
|
||||
[sub_resource type="AtlasTexture" id=1]
|
||||
atlas = ExtResource( 3 )
|
||||
region = Rect2( 2, 2, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=2]
|
||||
atlas = ExtResource( 3 )
|
||||
region = Rect2( 2, 54, 24, 24 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=3]
|
||||
atlas = ExtResource( 3 )
|
||||
region = Rect2( 2, 28, 24, 24 )
|
||||
|
||||
[node name="tables_header" type="Control"]
|
||||
anchor_right = 0.188889
|
||||
anchor_bottom = 0.019
|
||||
offset_right = 6.10352e-05
|
||||
offset_bottom = -0.4
|
||||
custom_minimum_size = Vector2( 170, 30 )
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": true,
|
||||
"_edit_vertical_guides_": [ 170.0 ]
|
||||
}
|
||||
|
||||
[node name="add_table_btn" type="TextureButton" parent="."]
|
||||
offset_left = 2.0
|
||||
offset_top = 2.0
|
||||
offset_right = 26.0
|
||||
offset_bottom = 26.0
|
||||
texture_normal = SubResource( 1 )
|
||||
texture_pressed = SubResource( 2 )
|
||||
texture_hover = SubResource( 3 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="tables_lbl" type="Label" parent="."]
|
||||
anchor_left = 0.165
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 0.8
|
||||
offset_left = -0.0500259
|
||||
offset_right = -0.000152588
|
||||
theme_override_fonts/font = ExtResource( 1 )
|
||||
text = "Tables "
|
||||
align = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="line" type="NinePatchRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 29.0
|
||||
offset_right = -0.000152588
|
||||
texture = ExtResource( 3 )
|
||||
region_rect = Rect2( 80, 2, 24, 2 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
@tool
|
||||
"""
|
||||
class GDDBTablesList
|
||||
"""
|
||||
|
||||
class_name GDDBTablesList
|
||||
|
||||
extends Control
|
||||
|
||||
signal resize_tables_list
|
||||
|
||||
signal add_table
|
||||
signal edit_table_name
|
||||
signal delete_table
|
||||
signal select_table
|
||||
|
||||
var m_tables = []
|
||||
|
||||
var m_mouse_pos_pressed : Vector2 = Vector2()
|
||||
var m_mouse_pressed : bool = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
m_mouse_pos_pressed = Vector2()
|
||||
m_mouse_pressed = false
|
||||
|
||||
$tables_header.connect("add_table", Callable(self, "on_add_table"))
|
||||
|
||||
# called when the node gets an input
|
||||
func _input(event : InputEvent) -> void :
|
||||
if(!gddb_globals.is_interface_active()):
|
||||
return
|
||||
|
||||
var evLocal = $resize_ctrl.make_input_local(event)
|
||||
|
||||
if event is InputEventMouseButton :
|
||||
if(event.button_index == MOUSE_BUTTON_LEFT):
|
||||
if(event.pressed):
|
||||
var rect = Rect2(Vector2(0, 0), $resize_ctrl.get_size())
|
||||
var inside = rect.has_point(evLocal.position)
|
||||
if(inside):
|
||||
m_mouse_pressed = true
|
||||
m_mouse_pos_pressed = evLocal.position
|
||||
else:
|
||||
m_mouse_pressed = false
|
||||
|
||||
elif event is InputEventMouseMotion :
|
||||
if(m_mouse_pressed):
|
||||
var diff_x = evLocal.position.x - m_mouse_pos_pressed.x
|
||||
emit_signal("resize_tables_list", diff_x)
|
||||
|
||||
# custom resizing the tables list
|
||||
func resize_content(size : Vector2) -> void :
|
||||
set_size(size)
|
||||
|
||||
# I have no idea why I need to do this; this should be done automatically
|
||||
var content_size = $tables_container/tables.get_size()
|
||||
content_size.x = size.x
|
||||
$tables_container/tables.set_custom_minimum_size(content_size)
|
||||
|
||||
# Called when the user presses the "add_table" button from the tables_list/header
|
||||
func on_add_table() -> void :
|
||||
# print("GDDBTablesList::on_add_table()")
|
||||
emit_signal("add_table")
|
||||
|
||||
# creates a table
|
||||
func create_table(db_table : Object, select_table : bool = true) -> void:
|
||||
# print("GDDBTablesList::create_table(" + str(db_table) + ")")
|
||||
var table = load(gddb_constants.c_addon_main_path + "table_item.tscn").instantiate()
|
||||
var table_id = db_table.get_table_id()
|
||||
table.set_table_id(table_id)
|
||||
table.set_table_name(db_table.get_table_name())
|
||||
table.connect("select_item", Callable(self, "on_select_item"))
|
||||
table.connect("edit_table", Callable(self, "on_edit_table_name"))
|
||||
table.connect("delete_table", Callable(self, "on_delete_table"))
|
||||
m_tables.push_back(table)
|
||||
$tables_container/tables.add_child(table)
|
||||
if(select_table):
|
||||
select_item_by_id(table_id)
|
||||
|
||||
# Called when the user presses the "edit_table" button from the tables_list/table
|
||||
func on_edit_table_name(table_id : int, table_name : String) -> void:
|
||||
# print("GDDBTablesList::on_edit_table_name(" + str(table_id) + ", " + table_name + ")")
|
||||
emit_signal("edit_table_name", table_id, table_name)
|
||||
|
||||
# Called when the user presses the "delete_table" button from the tables_list/table
|
||||
func on_delete_table(table_id : int) -> void:
|
||||
# print("GDDBTablesList::on_delete_table(" + str(table_id) + ")")
|
||||
emit_signal("delete_table", table_id)
|
||||
|
||||
# edits the table name
|
||||
func edit_table_name(table_id: int, table_name : String) -> void:
|
||||
for idx in range(0, m_tables.size()):
|
||||
if(m_tables[idx].get_table_id() == table_id):
|
||||
m_tables[idx].set_table_name(table_name)
|
||||
break
|
||||
|
||||
# deletes a table from the list
|
||||
func delete_table(table_id : int) -> void:
|
||||
for idx in range(0, m_tables.size()):
|
||||
if(m_tables[idx].get_table_id() == table_id):
|
||||
$tables_container/tables.remove_child(m_tables[idx])
|
||||
m_tables.remove(idx)
|
||||
break
|
||||
|
||||
# called when the user presses an item
|
||||
func on_select_item(table_id : int) -> void:
|
||||
# print("GDDBTablesList::on_select_item(" + str(table_id) + ")")
|
||||
select_item_by_id(table_id)
|
||||
emit_signal("select_table", table_id)
|
||||
|
||||
# select an item by index
|
||||
func select_item_at(table_idx : int) -> void:
|
||||
for idx in range(0, m_tables.size()):
|
||||
m_tables[idx].set_selected(idx == table_idx)
|
||||
|
||||
# select an item by id
|
||||
func select_item_by_id(table_id : int) -> void:
|
||||
# print("GDDBTablesList::select_item_by_id(" + str(table_id) + ")")
|
||||
for idx in range(0, m_tables.size()):
|
||||
m_tables[idx].set_selected(m_tables[idx].get_table_id() == table_id)
|
||||
|
||||
# returns the selected element
|
||||
func get_selected_item():
|
||||
for idx in range(0, m_tables.size()):
|
||||
if(m_tables[idx].is_selected()):
|
||||
return m_tables[idx]
|
||||
print("ERROR: GDDBTablesList::get_selected_item() - there is no selected element")
|
||||
return null
|
||||
@@ -1,60 +0,0 @@
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_db_manager/tables_list.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/godot_db_manager/tables_header.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://addons/godot_db_manager/debug/dbg.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://addons/godot_db_manager/assets/tex/gui.png" type="Texture2D" id=4]
|
||||
|
||||
[node name="tables_list" type="Control"]
|
||||
anchor_right = 0.2
|
||||
anchor_bottom = 1.0
|
||||
offset_right = -9.99991
|
||||
custom_minimum_size = Vector2( 180, 225 )
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_horizontal_guides_": [ 29.9686, 584.0 ],
|
||||
"_edit_use_anchors_": false,
|
||||
"_edit_vertical_guides_": [ 180.0 ]
|
||||
}
|
||||
|
||||
[node name="tables_header" parent="." instance=ExtResource( 2 )]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 0.0
|
||||
offset_right = -9.15527e-05
|
||||
offset_bottom = 30.0
|
||||
custom_minimum_size = Vector2( 180, 30 )
|
||||
|
||||
[node name="tables_container" type="ScrollContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 32.0
|
||||
custom_minimum_size = Vector2( 180, 0 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="tables" type="VBoxContainer" parent="tables_container"]
|
||||
clip_contents = true
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="resize_ctrl" type="NinePatchRect" parent="."]
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -3.0
|
||||
mouse_filter = 0
|
||||
mouse_default_cursor_shape = 15
|
||||
texture = ExtResource( 4 )
|
||||
region_rect = Rect2( 80, 12, 24, 24 )
|
||||
patch_margin_left = 1
|
||||
patch_margin_top = 1
|
||||
patch_margin_right = 1
|
||||
patch_margin_bottom = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="dbg" parent="." instance=ExtResource( 3 )]
|
||||
visible = false
|
||||
@@ -1,7 +1,8 @@
|
||||
# Copyright © 2020 Hugo Locurcio and contributors - MIT License
|
||||
# See `LICENSE.md` included in the source distribution for details.
|
||||
@icon("res://addons/lod/lod_cpu_particles.svg")
|
||||
class_name LODCPUParticles
|
||||
extends CPUParticles3D
|
||||
class_name LODCPUParticles, "lod_cpu_particles.svg"
|
||||
|
||||
# If `false`, LOD won't update anymore. This can be used for performance comparison
|
||||
# purposes.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# Copyright © 2020 Hugo Locurcio and contributors - MIT License
|
||||
# See `LICENSE.md` included in the source distribution for details.
|
||||
@icon("res://addons/lod/lod_omni_light.svg")
|
||||
class_name LODOmniLight
|
||||
extends OmniLight3D
|
||||
class_name LODOmniLight, "lod_omni_light.svg"
|
||||
|
||||
# If `false`, LOD won't update anymore. This can be used for performance comparison
|
||||
# purposes.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# Copyright © 2020 Hugo Locurcio and contributors - MIT License
|
||||
# See `LICENSE.md` included in the source distribution for details.
|
||||
extends Particles
|
||||
class_name LODParticles, "lod_particles.svg"
|
||||
@icon("res://addons/lod/lod_particles.svg")
|
||||
class_name LODParticles
|
||||
extends GPUParticles3D
|
||||
|
||||
# If `false`, LOD won't update anymore. This can be used for performance comparison
|
||||
# purposes.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# Copyright © 2020 Hugo Locurcio and contributors - MIT License
|
||||
# See `LICENSE.md` included in the source distribution for details.
|
||||
@icon("res://addons/lod/lod_spatial.svg")
|
||||
class_name LODSpatial
|
||||
extends Node3D
|
||||
class_name LODSpatial, "lod_spatial.svg"
|
||||
|
||||
# If `false`, LOD won't update anymore. This can be used for performance comparison
|
||||
# purposes.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# Copyright © 2020 Hugo Locurcio and contributors - MIT License
|
||||
# See `LICENSE.md` included in the source distribution for details.
|
||||
@icon("res://addons/lod/lod_spot_light.svg")
|
||||
class_name LODSpotLight
|
||||
extends SpotLight3D
|
||||
class_name LODSpotLight, "lod_spot_light.svg"
|
||||
|
||||
# If `false`, LOD won't update anymore. This can be used for performance comparison
|
||||
# purposes.
|
||||
|
||||
+3
-211
@@ -1,4 +1,3 @@
|
||||
; Project was converted by built-in tool to Godot 4
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
@@ -9,196 +8,6 @@
|
||||
|
||||
config_version=5
|
||||
|
||||
_global_script_classes=[ {
|
||||
"base": "Node",
|
||||
"class": "GDDBConstants",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/core/GDDBConstants.gd"
|
||||
}, {
|
||||
"base": "Object",
|
||||
"class": "GDDBData",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/core/db_data.gd"
|
||||
}, {
|
||||
"base": "Label",
|
||||
"class": "GDDBDataLabel",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/data_label.gd"
|
||||
}, {
|
||||
"base": "PopupPanel",
|
||||
"class": "GDDBDataPanel",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/dlgs/data_dlg.gd"
|
||||
}, {
|
||||
"base": "WindowDialog",
|
||||
"class": "GDDBDeletePropDlg",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/dlgs/delete_prop_dlg.gd"
|
||||
}, {
|
||||
"base": "WindowDialog",
|
||||
"class": "GDDBDeleteTableDlg",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/dlgs/delete_table_dlg.gd"
|
||||
}, {
|
||||
"base": "WindowDialog",
|
||||
"class": "GDDBEditStringDlg",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/dlgs/edit_string_dlg.gd"
|
||||
}, {
|
||||
"base": "Tabs",
|
||||
"class": "GDDBEditor",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/db_editor.gd"
|
||||
}, {
|
||||
"base": "Node",
|
||||
"class": "GDDBGlobals",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/core/GDDBGlobals.gd"
|
||||
}, {
|
||||
"base": "Control",
|
||||
"class": "GDDBInterface",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/db_interface.gd"
|
||||
}, {
|
||||
"base": "FileDialog",
|
||||
"class": "GDDBLoadResourcePathDlg",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/dlgs/load_res_path_dlg.gd"
|
||||
}, {
|
||||
"base": "Object",
|
||||
"class": "GDDBMan",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/core/db_man.gd"
|
||||
}, {
|
||||
"base": "EditorPlugin",
|
||||
"class": "GDDBManager",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/db_manager.gd"
|
||||
}, {
|
||||
"base": "Control",
|
||||
"class": "GDDBMenu",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/menu.gd"
|
||||
}, {
|
||||
"base": "WindowDialog",
|
||||
"class": "GDDBNewDBDlg",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/dlgs/new_db_dlg.gd"
|
||||
}, {
|
||||
"base": "WindowDialog",
|
||||
"class": "GDDBNewTableDlg",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/dlgs/new_table_dlg.gd"
|
||||
}, {
|
||||
"base": "Object",
|
||||
"class": "GDDBProperty",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/core/db_prop.gd"
|
||||
}, {
|
||||
"base": "Object",
|
||||
"class": "GDDBTable",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/core/db_table.gd"
|
||||
}, {
|
||||
"base": "Control",
|
||||
"class": "GDDBTableCell",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/table_cell.gd"
|
||||
}, {
|
||||
"base": "Control",
|
||||
"class": "GDDBTableEditor",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/table_editor.gd"
|
||||
}, {
|
||||
"base": "Control",
|
||||
"class": "GDDBTableItem",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/table_item.gd"
|
||||
}, {
|
||||
"base": "Control",
|
||||
"class": "GDDBTableProperty",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/table_property.gd"
|
||||
}, {
|
||||
"base": "Control",
|
||||
"class": "GDDBTablesHeader",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/tables_header.gd"
|
||||
}, {
|
||||
"base": "Control",
|
||||
"class": "GDDBTablesList",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/tables_list.gd"
|
||||
}, {
|
||||
"base": "Node",
|
||||
"class": "GDDBTypes",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/core/GDDBTypes.gd"
|
||||
}, {
|
||||
"base": "Object",
|
||||
"class": "GDDatabase",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/godot_db_manager/core/database.gd"
|
||||
}, {
|
||||
"base": "CPUParticles",
|
||||
"class": "LODCPUParticles",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/lod/lod_cpu_particles.gd"
|
||||
}, {
|
||||
"base": "OmniLight",
|
||||
"class": "LODOmniLight",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/lod/lod_omni_light.gd"
|
||||
}, {
|
||||
"base": "Particles",
|
||||
"class": "LODParticles",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/lod/lod_particles.gd"
|
||||
}, {
|
||||
"base": "Spatial",
|
||||
"class": "LODSpatial",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/lod/lod_spatial.gd"
|
||||
}, {
|
||||
"base": "SpotLight",
|
||||
"class": "LODSpotLight",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/lod/lod_spot_light.gd"
|
||||
} ]
|
||||
_global_script_class_icons={
|
||||
"GDDBConstants": "",
|
||||
"GDDBData": "",
|
||||
"GDDBDataLabel": "",
|
||||
"GDDBDataPanel": "",
|
||||
"GDDBDeletePropDlg": "",
|
||||
"GDDBDeleteTableDlg": "",
|
||||
"GDDBEditStringDlg": "",
|
||||
"GDDBEditor": "",
|
||||
"GDDBGlobals": "",
|
||||
"GDDBInterface": "",
|
||||
"GDDBLoadResourcePathDlg": "",
|
||||
"GDDBMan": "",
|
||||
"GDDBManager": "",
|
||||
"GDDBMenu": "",
|
||||
"GDDBNewDBDlg": "",
|
||||
"GDDBNewTableDlg": "",
|
||||
"GDDBProperty": "",
|
||||
"GDDBTable": "",
|
||||
"GDDBTableCell": "",
|
||||
"GDDBTableEditor": "",
|
||||
"GDDBTableItem": "",
|
||||
"GDDBTableProperty": "",
|
||||
"GDDBTablesHeader": "",
|
||||
"GDDBTablesList": "",
|
||||
"GDDBTypes": "",
|
||||
"GDDatabase": "",
|
||||
"LODCPUParticles": "res://addons/lod/lod_cpu_particles.svg",
|
||||
"LODOmniLight": "res://addons/lod/lod_omni_light.svg",
|
||||
"LODParticles": "res://addons/lod/lod_particles.svg",
|
||||
"LODSpatial": "res://addons/lod/lod_spatial.svg",
|
||||
"LODSpotLight": "res://addons/lod/lod_spot_light.svg"
|
||||
}
|
||||
|
||||
[application]
|
||||
|
||||
config/name="Puzzle Quest"
|
||||
@@ -215,9 +24,6 @@ config/quit_on_go_back=false
|
||||
|
||||
Loading="*res://scenes/UI/loading/Loading.tscn"
|
||||
Global="*res://scripts/Global.gd"
|
||||
gddb_constants="*res://addons/godot_db_manager/core/GDDBConstants.gd"
|
||||
gddb_types="*res://addons/godot_db_manager/core/GDDBTypes.gd"
|
||||
gddb_globals="*res://addons/godot_db_manager/core/GDDBGlobals.gd"
|
||||
Setting="*res://scripts/Setting.gd"
|
||||
Event="*res://scripts/Event.gd"
|
||||
GlobalAnimation="*res://scripts/Animation.gd"
|
||||
@@ -234,7 +40,7 @@ window/stretch/aspect="expand"
|
||||
|
||||
[editor_plugins]
|
||||
|
||||
enabled=PackedStringArray( "res://addons/godot_db_manager/plugin.cfg", "res://addons/lod/plugin.cfg" )
|
||||
enabled=PackedStringArray("res://addons/lod/plugin.cfg")
|
||||
|
||||
[importer_defaults]
|
||||
|
||||
@@ -252,27 +58,13 @@ scene={
|
||||
|
||||
ui_end={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"command":false,"pressed":false,"keycode":4194318,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"command":false,"pressed":false,"keycode":4194305,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194318,"physical_keycode":0,"unicode":0,"echo":false,"script":null), Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194305,"physical_keycode":0,"unicode":0,"echo":false,"script":null)]
|
||||
}
|
||||
|
||||
[locale]
|
||||
|
||||
translations=PackedStringArray( "res://locales/fr.po", "res://locales/en.po" )
|
||||
locale_filter=[ 1, [ "en_GB", "fr_FR" ] ]
|
||||
|
||||
[physics]
|
||||
|
||||
common/enable_pause_aware_picking=true
|
||||
translations=PackedStringArray("res://locales/fr.po", "res://locales/en.po")
|
||||
|
||||
[rendering]
|
||||
|
||||
quality/driver/fallback_to_gles2=true
|
||||
threads/thread_model=2
|
||||
vram_compression/import_etc=true
|
||||
shading/overrides/force_vertex_shading.mobile=false
|
||||
quality/lightmapping/use_bicubic_sampling.mobile=true
|
||||
quality/depth/hdr.mobile=true
|
||||
environment/defaults/default_environment="res://default_env.tres"
|
||||
quality/dynamic_fonts/use_oversampling=false
|
||||
|
||||
+135
-34
@@ -1,47 +1,148 @@
|
||||
extends Node
|
||||
|
||||
func initialize():
|
||||
var database_manager = load(gddb_constants.c_addon_main_path + "core/db_man.gd").new()
|
||||
var db_id = database_manager.load_database(save_database_in())
|
||||
|
||||
check_invalid_type(db_id)
|
||||
check_invalid_version(db_id)
|
||||
|
||||
return database_manager.get_db_by_id(db_id)
|
||||
# Lightweight replacement for the godot_db_manager plugin (incompatible with
|
||||
# Godot 4). Keeps the ahog.json format used by the rest of the project and
|
||||
# exposes the same surface API the M* model classes expect:
|
||||
#
|
||||
# Global.database.get_table_by_name(name) -> Table
|
||||
# Global.database.save_db()
|
||||
# table.get_data_at_row_idx(row_id) -> [Cell, Cell, ...]
|
||||
# table.edit_data(prop_id, row_id, value)
|
||||
# table.m_rows_count
|
||||
# table.get_data_by_prop_name_and_data(prop_name, value) -> Array
|
||||
# table.get_dictionary_by_prop_name_and_data(prop_name, value) -> Array[Dict]
|
||||
# cell.get_data() -> String
|
||||
|
||||
func check_invalid_type(db_id):
|
||||
if db_id == gddb_types.e_db_invalid_file:
|
||||
print("[Database#check_invalid_type] Error invalid database file !")
|
||||
OS.set_exit_code(1)
|
||||
class Cell:
|
||||
var _value
|
||||
func _init(value):
|
||||
_value = value
|
||||
func get_data():
|
||||
return _value
|
||||
|
||||
func check_invalid_version(db_id):
|
||||
if db_id == gddb_types.e_db_invalid_ver:
|
||||
print("[Database#check_invalid_version] Error invalid database version !")
|
||||
OS.set_exit_code(1)
|
||||
class Table:
|
||||
var name: String
|
||||
var props: Array
|
||||
var data: Array
|
||||
var m_rows_count: int
|
||||
|
||||
func save_database_in():
|
||||
func _init(table_dict: Dictionary):
|
||||
name = table_dict["table_name"]
|
||||
props = table_dict["props"]
|
||||
data = table_dict["data"]
|
||||
m_rows_count = data.size() / max(1, props.size())
|
||||
|
||||
func _col_count() -> int:
|
||||
return props.size()
|
||||
|
||||
func _find_prop_idx(prop_name: String) -> int:
|
||||
for i in range(props.size()):
|
||||
if props[i]["name"] == prop_name:
|
||||
return i
|
||||
return -1
|
||||
|
||||
func get_data_at_row_idx(row_idx: int) -> Array:
|
||||
var start = row_idx * _col_count()
|
||||
var cells = []
|
||||
for i in range(_col_count()):
|
||||
cells.append(Cell.new(data[start + i]))
|
||||
return cells
|
||||
|
||||
func edit_data(prop_id: int, row_id: int, value) -> void:
|
||||
data[row_id * _col_count() + prop_id] = str(value)
|
||||
|
||||
func get_data_by_prop_name_and_data(prop_name: String, value) -> Array:
|
||||
var prop_idx = _find_prop_idx(prop_name)
|
||||
var matches = []
|
||||
if prop_idx == -1:
|
||||
return matches
|
||||
for row in range(m_rows_count):
|
||||
if data[row * _col_count() + prop_idx] == str(value):
|
||||
matches.append(row)
|
||||
return matches
|
||||
|
||||
func get_dictionary_by_prop_name_and_data(prop_name: String, value) -> Array:
|
||||
var prop_idx = _find_prop_idx(prop_name)
|
||||
var results = []
|
||||
if prop_idx == -1:
|
||||
return results
|
||||
for row in range(m_rows_count):
|
||||
if data[row * _col_count() + prop_idx] == str(value):
|
||||
var d = {}
|
||||
for i in range(_col_count()):
|
||||
d[props[i]["name"]] = data[row * _col_count() + i]
|
||||
results.append(d)
|
||||
return results
|
||||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"table_name": name,
|
||||
"props": props,
|
||||
"data": data,
|
||||
}
|
||||
|
||||
class DB:
|
||||
var version: String
|
||||
var db_name: String
|
||||
var tables: Dictionary = {}
|
||||
var _path: String
|
||||
|
||||
func _init(path: String):
|
||||
_path = path
|
||||
var f = FileAccess.open(path, FileAccess.READ)
|
||||
if f == null:
|
||||
push_error("[Database] Cannot open " + path)
|
||||
return
|
||||
var raw = f.get_as_text()
|
||||
f.close()
|
||||
var doc = JSON.parse_string(raw)
|
||||
if doc == null:
|
||||
push_error("[Database] Invalid JSON in " + path)
|
||||
return
|
||||
version = doc.get("GDDB_ver", "")
|
||||
db_name = doc.get("db_name", "")
|
||||
for t in doc.get("tables", []):
|
||||
var table = Table.new(t)
|
||||
tables[table.name] = table
|
||||
|
||||
func get_table_by_name(name: String):
|
||||
return tables.get(name)
|
||||
|
||||
func save_db() -> void:
|
||||
var doc = {
|
||||
"GDDB_ver": version,
|
||||
"db_name": db_name,
|
||||
"tables": [],
|
||||
}
|
||||
for tname in tables:
|
||||
doc["tables"].append(tables[tname].to_dict())
|
||||
var f = FileAccess.open(_path, FileAccess.WRITE)
|
||||
if f == null:
|
||||
push_error("[Database] Cannot write " + _path)
|
||||
return
|
||||
f.store_string(JSON.stringify(doc))
|
||||
f.close()
|
||||
|
||||
func initialize() -> DB:
|
||||
return DB.new(save_database_in())
|
||||
|
||||
func save_database_in() -> String:
|
||||
if OS.get_name() == "Android":
|
||||
copy_database()
|
||||
return android_path()
|
||||
else:
|
||||
return normal_path()
|
||||
return normal_path()
|
||||
|
||||
func android_path():
|
||||
func android_path() -> String:
|
||||
return "user://database.json"
|
||||
|
||||
func normal_path():
|
||||
func normal_path() -> String:
|
||||
return "res://db/ahog.json"
|
||||
|
||||
func copy_database():
|
||||
var database_copy = File.new()
|
||||
|
||||
if !database_copy.file_exists(android_path()):
|
||||
var database_file = File.new()
|
||||
|
||||
database_file.open(normal_path(), File.READ)
|
||||
database_copy.open(android_path(), File.WRITE)
|
||||
database_copy.store_string(database_file.get_as_text())
|
||||
database_copy.close()
|
||||
|
||||
database_file.close()
|
||||
|
||||
func copy_database() -> void:
|
||||
if FileAccess.file_exists(android_path()):
|
||||
return
|
||||
var src = FileAccess.open(normal_path(), FileAccess.READ)
|
||||
var dst = FileAccess.open(android_path(), FileAccess.WRITE)
|
||||
dst.store_string(src.get_as_text())
|
||||
dst.close()
|
||||
src.close()
|
||||
|
||||
+30
-32
@@ -1,18 +1,17 @@
|
||||
extends Control
|
||||
|
||||
const TICKS_TIME_MAX = 100 # msec
|
||||
|
||||
@onready var current_scene = null
|
||||
@onready var current_scene_int = null
|
||||
@onready var loader = null
|
||||
@onready var wait_frames = 1
|
||||
@onready var database = null
|
||||
@onready var loaded = false
|
||||
@onready var animation = Loading.get_node("AnimLoading")
|
||||
|
||||
var _loading_path: String = ""
|
||||
|
||||
func _ready():
|
||||
database = load("res://scripts/Database.gd").new().initialize()
|
||||
|
||||
|
||||
_initialize_current_scene()
|
||||
_initialize_loading_scene()
|
||||
|
||||
@@ -21,60 +20,59 @@ func _initialize_loading_scene():
|
||||
animation.connect("animation_finished", Callable(Event, "_loading_is_finished"))
|
||||
|
||||
func goto_scene(path):
|
||||
print("[global#goto_scene] : load scene "+String(path))
|
||||
loader = ResourceLoader.load_threaded_request(path)
|
||||
if loader == null:
|
||||
print("[global#goto_scene] : load scene " + str(path))
|
||||
var err = ResourceLoader.load_threaded_request(path)
|
||||
if err != OK:
|
||||
print("Error loading ....")
|
||||
return
|
||||
|
||||
_loading_path = path
|
||||
Loading.show()
|
||||
animation.play("BorderAnim")
|
||||
|
||||
|
||||
set_process(true)
|
||||
current_scene.queue_free()
|
||||
wait_frames = 1
|
||||
Loading.get_node("LoadingBare/VBoxContainer/HBoxContainer/ProgressBar").set_max(loader.get_stage_count())
|
||||
Loading.get_node("LoadingBare/VBoxContainer/HBoxContainer/ProgressBar").set_max(1.0)
|
||||
|
||||
func _process(_delta):
|
||||
if loader == null:
|
||||
if _loading_path == "":
|
||||
set_process(false)
|
||||
return
|
||||
|
||||
|
||||
if wait_frames > 0:
|
||||
wait_frames -= 1
|
||||
|
||||
var tick = Time.get_ticks_msec()
|
||||
|
||||
# Use "TICKS_TIME_MAX" to control for how long we block this thread
|
||||
while Time.get_ticks_msec() < tick + TICKS_TIME_MAX:
|
||||
if loaded:
|
||||
var err = loader.poll()
|
||||
|
||||
if err == ERR_FILE_EOF: # Finished loading.
|
||||
_set_new_scene()
|
||||
break
|
||||
elif err == OK:
|
||||
_update_progress()
|
||||
else:
|
||||
loader = null
|
||||
break
|
||||
|
||||
if not loaded:
|
||||
return
|
||||
|
||||
var progress := []
|
||||
var status = ResourceLoader.load_threaded_get_status(_loading_path, progress)
|
||||
match status:
|
||||
ResourceLoader.THREAD_LOAD_IN_PROGRESS:
|
||||
_update_progress(progress[0] if progress.size() > 0 else 0.0)
|
||||
ResourceLoader.THREAD_LOAD_LOADED:
|
||||
_set_new_scene()
|
||||
ResourceLoader.THREAD_LOAD_FAILED, ResourceLoader.THREAD_LOAD_INVALID_RESOURCE:
|
||||
print("Error loading ....")
|
||||
_loading_path = ""
|
||||
|
||||
## PRIVATE
|
||||
func _initialize_current_scene():
|
||||
print("[global#_initialize_current_scene]")
|
||||
var root = get_tree().get_root()
|
||||
current_scene = root.get_child(root.get_child_count() - 1)
|
||||
|
||||
|
||||
if current_scene.name != "Main":
|
||||
get_node("/root/Loading").hide()
|
||||
|
||||
func _update_progress():
|
||||
func _update_progress(value: float):
|
||||
Loading.visible = true
|
||||
Loading.get_node("LoadingBare/VBoxContainer/HBoxContainer/ProgressBar").set_value(loader.get_stage())
|
||||
Loading.get_node("LoadingBare/VBoxContainer/HBoxContainer/ProgressBar").set_value(value)
|
||||
|
||||
func _set_new_scene():
|
||||
var resource = loader.get_resource()
|
||||
loader = null
|
||||
var resource = ResourceLoader.load_threaded_get(_loading_path)
|
||||
_loading_path = ""
|
||||
current_scene = resource.instantiate()
|
||||
get_node("/root").add_child(current_scene)
|
||||
Loading.hide()
|
||||
|
||||
Reference in New Issue
Block a user