mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
Reload extension if the user is trying to add it and it already exists
Restarting Pixelorama to reload an extension should no longer be required
This commit is contained in:
parent
694c6c7509
commit
b5d268e7e1
|
@ -69,9 +69,40 @@ func install_extension(path: String) -> void:
|
||||||
_add_extension(file_name)
|
_add_extension(file_name)
|
||||||
|
|
||||||
|
|
||||||
|
func _uninstall_extension(file_name := "", remove_file := true, item := extension_selected) -> void:
|
||||||
|
if remove_file:
|
||||||
|
var dir := Directory.new()
|
||||||
|
var err := dir.remove(EXTENSIONS_PATH.plus_file(file_name))
|
||||||
|
if err != OK:
|
||||||
|
print(err)
|
||||||
|
return
|
||||||
|
|
||||||
|
var extension: Extension = extensions[file_name]
|
||||||
|
extension.enabled = false
|
||||||
|
_enable_extension(extension, false)
|
||||||
|
|
||||||
|
extensions.erase(file_name)
|
||||||
|
extension_list.remove_item(item)
|
||||||
|
extension_selected = -1
|
||||||
|
enable_button.disabled = true
|
||||||
|
uninstall_button.disabled = true
|
||||||
|
|
||||||
|
|
||||||
func _add_extension(file_name: String) -> void:
|
func _add_extension(file_name: String) -> void:
|
||||||
if extensions.has(file_name):
|
if extensions.has(file_name):
|
||||||
return
|
var item := -1
|
||||||
|
for i in extension_list.get_item_count():
|
||||||
|
if extension_list.get_item_metadata(i) == file_name:
|
||||||
|
item = i
|
||||||
|
break
|
||||||
|
if item == -1:
|
||||||
|
print("Failed to find %s" % file_name)
|
||||||
|
return
|
||||||
|
_uninstall_extension(file_name, false, item)
|
||||||
|
# Wait two frames so the previous nodes can get freed
|
||||||
|
yield(get_tree(), "idle_frame")
|
||||||
|
yield(get_tree(), "idle_frame")
|
||||||
|
|
||||||
var file_name_no_ext: String = file_name.get_basename()
|
var file_name_no_ext: String = file_name.get_basename()
|
||||||
var file_path: String = EXTENSIONS_PATH.plus_file(file_name)
|
var file_path: String = EXTENSIONS_PATH.plus_file(file_name)
|
||||||
var success := ProjectSettings.load_resource_pack(file_path)
|
var success := ProjectSettings.load_resource_pack(file_path)
|
||||||
|
@ -125,6 +156,8 @@ func _enable_extension(extension: Extension, save_to_config := true) -> void:
|
||||||
var extension_node: Node = extension_scene.instance()
|
var extension_node: Node = extension_scene.instance()
|
||||||
extension_parent.add_child(extension_node)
|
extension_parent.add_child(extension_node)
|
||||||
extension_node.add_to_group(id) # Keep track of what to remove later
|
extension_node.add_to_group(id) # Keep track of what to remove later
|
||||||
|
else:
|
||||||
|
print("Failed to load extension %s" % id)
|
||||||
else:
|
else:
|
||||||
for ext_node in extension_parent.get_children():
|
for ext_node in extension_parent.get_children():
|
||||||
if ext_node.is_in_group(id): # Node for extention found
|
if ext_node.is_in_group(id): # Node for extention found
|
||||||
|
@ -169,22 +202,7 @@ func _on_EnableButton_pressed() -> void:
|
||||||
|
|
||||||
|
|
||||||
func _on_UninstallButton_pressed() -> void:
|
func _on_UninstallButton_pressed() -> void:
|
||||||
var dir := Directory.new()
|
_uninstall_extension(extension_list.get_item_metadata(extension_selected))
|
||||||
var file_name: String = extension_list.get_item_metadata(extension_selected)
|
|
||||||
var err := dir.remove(EXTENSIONS_PATH.plus_file(file_name))
|
|
||||||
if err != OK:
|
|
||||||
print(err)
|
|
||||||
return
|
|
||||||
|
|
||||||
var extension: Extension = extensions[file_name]
|
|
||||||
extension.enabled = false
|
|
||||||
_enable_extension(extension, false)
|
|
||||||
|
|
||||||
extensions.erase(file_name)
|
|
||||||
extension_list.remove_item(extension_selected)
|
|
||||||
extension_selected = -1
|
|
||||||
enable_button.disabled = true
|
|
||||||
uninstall_button.disabled = true
|
|
||||||
|
|
||||||
|
|
||||||
func _on_OpenFolderButton_pressed() -> void:
|
func _on_OpenFolderButton_pressed() -> void:
|
||||||
|
|
Loading…
Reference in a new issue