hook_gen.gd 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. @tool
  2. class_name ModToolInterfaceHookGen
  3. extends Window
  4. signal hooks_exist_pressed
  5. @onready var mod_tool_store: ModToolStore = get_node_or_null("/root/ModToolStore")
  6. @onready var info_output: RichTextLabel = %InfoOutput
  7. @onready var restart: Window = %Restart
  8. @onready var button_gen_start: Button = %ButtonGenStart
  9. func generate_hooks() -> void:
  10. # Get all script not in addons or mods-unpacked
  11. var all_script_file_paths := ModToolUtils.get_flat_view_dict("res://", "", [&"gd"], false, false, [&"addons", &"mods-unpacked"])
  12. for script_file_path in all_script_file_paths:
  13. if mod_tool_store.hooked_scripts.has(script_file_path):
  14. info_output.add_text("Skipping - Hooks already exists for \"%s\" \n" % script_file_path)
  15. continue
  16. var error := ModToolHookGen.transform_one(script_file_path, mod_tool_store)
  17. if not error == OK:
  18. info_output.add_text("ERROR: Accessing file at path \"%s\" failed with error: %s \n" % [script_file_path, error_string(error)])
  19. else:
  20. info_output.add_text("Added Hooks for \"%s\" \n" % script_file_path)
  21. mod_tool_store.is_hook_generation_done = true
  22. info_output.add_text("Mod Hook generation completed successfully!\n")
  23. mod_tool_store.save_store()
  24. restart.show()
  25. func _on_button_pressed() -> void:
  26. button_gen_start.disabled = true
  27. generate_hooks()
  28. func _on_close_requested() -> void:
  29. hide()
  30. func _on_button_restart_now_pressed() -> void:
  31. await get_tree().create_timer(1.0).timeout
  32. EditorInterface.restart_editor()
  33. func _on_button_restart_later_pressed() -> void:
  34. restart.hide()
  35. hide()
  36. func _on_restart_close_requested() -> void:
  37. restart.hide()
  38. func _on_button_hooks_exist_pressed() -> void:
  39. mod_tool_store.is_hook_generation_done = true
  40. hooks_exist_pressed.emit()
  41. hide()