-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgalatea_database_plugin.gd
156 lines (121 loc) · 5.25 KB
/
galatea_database_plugin.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
tool
extends EditorPlugin
const compiler_const = preload("compiler/compiler.gd")
const galatea_databases_const = preload("databases/galatea_databases.gd")
const database_popup_const = preload("editor/database_popup.tscn")
const database_list_const_popup = preload("editor/database_list.tscn")
const record_instance_node_const = preload("instances/record_instance_node.gd")
var editor_interface = null
var galatea_databases = null
var galatea_database_path = "res://assets/database"
var database_popup_button = null
var select_record_button = null
var selected_node = null
var database_popup_instance = null
var database_list_instance = null
func _init():
print("Setting up Galatea database plugin")
func save_external_data():
if galatea_databases:
print("Compiling databases...")
compiler_const.compile_location_data(galatea_databases)
func handles(p_object):
if p_object is record_instance_node_const:
return true
return false
func edit(p_object):
selected_node = p_object
func make_visible(p_visible):
if select_record_button:
if (p_visible):
select_record_button.show()
else:
select_record_button.hide()
func _enter_tree():
editor_interface = get_editor_interface()
galatea_databases = galatea_databases_const.new(galatea_database_path)
galatea_databases.load_all_databases()
database_popup_button = Button.new()
database_popup_button.set_text("Database Editor")
database_popup_button.set_tooltip("Open tool for editing Galatea's game databases.")
database_popup_button.connect("pressed", self, "_database_popup_requested")
add_control_to_container(CONTAINER_TOOLBAR, database_popup_button)
select_record_button = Button.new()
select_record_button.set_text("Select record...")
select_record_button.set_tooltip("Choose a database record for this instance node.")
select_record_button.connect("pressed", self, "_select_record_requested")
select_record_button.hide()
add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, select_record_button)
# Nodes
add_custom_type("ActorInstance", "Spatial", preload("instances/actor_instance_node.gd"), null)
add_custom_type("ItemInstance", "Spatial", preload("instances/item_instance_node.gd"), null)
func _exit_tree():
if database_popup_button:
database_popup_button.queue_free()
database_popup_button.get_parent().remove_child(database_popup_button)
if select_record_button:
select_record_button.queue_free()
select_record_button.get_parent().remove_child(database_popup_button)
editor_interface = null
galatea_databases = null
_database_destroy_popup()
# Nodes
remove_custom_type("ActorInstance")
remove_custom_type("ItemInstance")
func database_interface_assign_databases(p_control):
for child in p_control.get_children():
if(child.has_method("set_galatea_databases")):
child.call("set_galatea_databases", galatea_databases)
database_interface_assign_databases(child)
func database_interface_assign_editor_plugin(p_control):
for child in p_control.get_children():
if(child.has_method("set_editor_plugin")):
child.call("set_editor_plugin", self)
database_interface_assign_editor_plugin(child)
func _database_destroy_popup():
if(database_popup_instance):
if(database_popup_instance.is_connected("popup_hide", self, "database_popup_dismissed_callback")):
database_popup_instance.disconnect("popup_hide", self, "database_popup_dismissed_callback")
if(database_popup_instance.is_inside_tree()):
database_popup_instance.queue_free()
database_popup_instance = null
func database_popup_dismissed_callback():
if(galatea_databases.check_database_modified()):
print("The databases have been modified")
_database_destroy_popup()
else:
print("The databases have not been modified")
_database_destroy_popup()
func _database_popup_requested():
_database_destroy_popup()
database_popup_instance = database_popup_const.instance()
database_popup_instance.connect("popup_hide", self, "database_popup_dismissed_callback")
if(database_popup_instance):
editor_interface.get_base_control().add_child(database_popup_instance)
database_popup_instance.popup_centered()
database_interface_assign_databases(database_popup_instance)
database_interface_assign_editor_plugin(database_popup_instance)
else:
printerr("Could not load database editor scene")
return FAILED
return OK
func _select_record_requested():
selected_node.set_databases(galatea_databases)
var database = selected_node.get_valid_database()
database_list_instance = database_list_const_popup.instance()
editor_interface.get_base_control().add_child(database_list_instance)
database_list_instance.connect("popup_hide", self, "_select_record_dismissed")
database_list_instance.connect("record_selected", self, "_select_record_selected")
database_list_instance.populate_tree(database)
database_list_instance.popup_centered_ratio()
func _select_record_dismissed():
if database_list_instance:
if(database_list_instance.is_inside_tree()):
database_list_instance.queue_free()
database_list_instance = null
func _select_record_selected(p_record):
get_undo_redo().create_action("selected database_entry")
get_undo_redo().add_do_property(selected_node, "id", p_record.id)
get_undo_redo().add_undo_property(selected_node, "id", selected_node.id)
get_undo_redo().commit_action()
_select_record_dismissed()