From 9ec45eb3f882db981ff0d9e65f6bd1e7a1199bec Mon Sep 17 00:00:00 2001 From: Pat <27511950+ThePat02@users.noreply.github.com> Date: Thu, 9 Nov 2023 21:21:30 +0100 Subject: [PATCH 1/2] add: HTTP Request for checking newest version --- addons/behaviour_toolkit/ui/toolkit_ui.gd | 44 +++++++++++++++------ addons/behaviour_toolkit/ui/toolkit_ui.tscn | 13 +++++- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/addons/behaviour_toolkit/ui/toolkit_ui.gd b/addons/behaviour_toolkit/ui/toolkit_ui.gd index 5913f32..c6fa71f 100644 --- a/addons/behaviour_toolkit/ui/toolkit_ui.gd +++ b/addons/behaviour_toolkit/ui/toolkit_ui.gd @@ -2,25 +2,24 @@ extends Control +const CONFIG_URL = "https://raw.githubusercontent.com/ThePat02/BehaviourToolkit/main/addons/behaviour_toolkit/plugin.cfg" + + var current_selection: Node +var current_version +var newest_version: String + @onready var dialog_blackboard: FileDialog = $FileDialogNewBlackboard +@onready var http_request: HTTPRequest = $HTTPRequest func _ready(): - # Get current version of the plugin - var config = ConfigFile.new() - - # Load data from a file. - var err = config.load("res://addons/behaviour_toolkit/plugin.cfg") + update_current_version() + update_newest_version() - # If the file didn't load, ignore it. - if not err != OK: - var plugin_version = config.get_value("plugin", "version") - %Version.text = "BehaviourToolkit v" + str(plugin_version) - - config.clear() + %Version.text = "BehaviourToolkit v" + str(current_version) # Connect buttons %ButtonState.connect("pressed", _on_button_pressed.bind(FSMState, "FSMState")) @@ -53,6 +52,18 @@ func set_current_selection(new_selection): current_selection = new_selection +func update_newest_version(): + http_request.request(CONFIG_URL) + + +func update_current_version(): + var config = ConfigFile.new() + var err = config.load("res://addons/behaviour_toolkit/plugin.cfg") + + current_version = config.get_value("plugin", "version") + config.clear() + + func _on_button_pressed(type, name: String): var new_node: BehaviourToolkit = type.new() @@ -81,3 +92,14 @@ func _on_button_blackboard_pressed(): func _on_file_dialog_new_blackboard_file_selected(path:String): var new_blackboard := Blackboard.new() ResourceSaver.save(new_blackboard, path) + + +func _on_http_request_request_completed(result:int, response_code:int, headers:PackedStringArray, body:PackedByteArray): + var config = ConfigFile.new() + var err = config.parse(body.get_string_from_ascii()) + + newest_version = config.get_value("plugin", "version") + config.clear() + + if newest_version != current_version: + %LinkGithub.show() diff --git a/addons/behaviour_toolkit/ui/toolkit_ui.tscn b/addons/behaviour_toolkit/ui/toolkit_ui.tscn index d5cb251..2fd9970 100644 --- a/addons/behaviour_toolkit/ui/toolkit_ui.tscn +++ b/addons/behaviour_toolkit/ui/toolkit_ui.tscn @@ -31,6 +31,8 @@ grow_vertical = 2 script = ExtResource("1_51rvx") metadata/_edit_vertical_guides_ = [] +[node name="HTTPRequest" type="HTTPRequest" parent="."] + [node name="FileDialogNewBlackboard" type="FileDialog" parent="."] title = "Create a new Blackboard" size = Vector2i(800, 500) @@ -253,13 +255,22 @@ layout_mode = 2 text = "Repeat" icon = ExtResource("10_nvbp1") +[node name="LinkGithub" type="LinkButton" parent="ScrollContainer/MarginContainer/VBoxContainer"] +unique_name_in_owner = true +visible = false +layout_mode = 2 +theme_override_colors/font_color = Color(0.0823529, 0.756863, 0.32549, 1) +text = "New Version available on GitHub!" +uri = "https://github.com/ThePat02/BehaviourToolkit" + [node name="Footer" type="HBoxContainer" parent="ScrollContainer/MarginContainer/VBoxContainer"] layout_mode = 2 [node name="Version" type="Label" parent="ScrollContainer/MarginContainer/VBoxContainer/Footer"] unique_name_in_owner = true layout_mode = 2 -text = "BehaviourToolkit v0.9.4" +text = "BehaviourToolkit v1.0.0" +[connection signal="request_completed" from="HTTPRequest" to="." method="_on_http_request_request_completed"] [connection signal="file_selected" from="FileDialogNewBlackboard" to="." method="_on_file_dialog_new_blackboard_file_selected"] [connection signal="pressed" from="ScrollContainer/MarginContainer/VBoxContainer/Panel/ScrollContainer/Toolbox/Misc/ButtonBlackboard" to="." method="_on_button_blackboard_pressed"] From b867997c74bdaf09ad812c65b538f79bf824c94e Mon Sep 17 00:00:00 2001 From: Pat <27511950+ThePat02@users.noreply.github.com> Date: Thu, 9 Nov 2023 21:29:11 +0100 Subject: [PATCH 2/2] docs --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 93240ea..92cd66b 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ This plugin provides a set of tools to create custom and complex behaviour in th - [Templates](docs/documentation.md#using-script-templates) for easy extension and integration. - Example Scene +When a new version is available on GitHub, the plugin will display a notification in the Toolbox! + ## Usage