diff --git a/.gitignore b/.gitignore index a10632f..53f39ca 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ data_*/ addons/* !addons/gd-plug/ !addons/export-build-info/ +!addons/gh-release-checker/ # Python-specific ignores venv/ diff --git a/.godot/global_script_class_cache.cfg b/.godot/global_script_class_cache.cfg index 0642b0e..95ad75d 100644 --- a/.godot/global_script_class_cache.cfg +++ b/.godot/global_script_class_cache.cfg @@ -23,6 +23,12 @@ list=Array[Dictionary]([{ "language": &"GDScript", "path": "res://scripts/item/barrier.gd" }, { +"base": &"Control", +"class": &"BootsplashScene", +"icon": "", +"language": &"GDScript", +"path": "res://scripts/bootsplash.gd" +}, { "base": &"Receptacle", "class": &"Car", "icon": "", @@ -208,4 +214,10 @@ list=Array[Dictionary]([{ "icon": "", "language": &"GDScript", "path": "res://scripts/street_light.gd" +}, { +"base": &"Node", +"class": &"UpdateChecker", +"icon": "", +"language": &"GDScript", +"path": "res://addons/gh-release-checker/update_checker.gd" }]) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88978b9..3c74480 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] ### Added +- Add link to the latest available version ([#31](https://github.com/MechanicalFlower/HazyRoad/pull/31)) ### Changed - Use the SFX bus for foot step sounds ([#30](https://github.com/MechanicalFlower/HazyRoad/pull/30)) ### Deprecated diff --git a/addons/gh-release-checker/checker.gd b/addons/gh-release-checker/checker.gd new file mode 100644 index 0000000..73b4e84 --- /dev/null +++ b/addons/gh-release-checker/checker.gd @@ -0,0 +1,22 @@ +extends Control + +const UpdateChecker := preload("res://addons/gh-release-checker/update_checker.gd") + +@onready var link_btn: LinkButton = $LinkBtn +@onready var update_checker := UpdateChecker.new() + + +func _ready() -> void: + add_child(update_checker) + update_checker.get_latest_version() + update_checker.release_parsed.connect(on_released_parsed) + + +func on_released_parsed(release: Dictionary) -> void: + if release["new"]: + link_btn.show() + link_btn.text = "New version available: " + release["version"] + else: + link_btn.hide() + #link_btn.text = "You have the latest version: " + release["version"] + link_btn.uri = release["url"] diff --git a/addons/gh-release-checker/plugin.cfg b/addons/gh-release-checker/plugin.cfg new file mode 100644 index 0000000..94fb1bb --- /dev/null +++ b/addons/gh-release-checker/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="release_checker" +description="" +author="florianvazelle" +version="0.0.0" +script="plugin.gd" diff --git a/addons/gh-release-checker/plugin.gd b/addons/gh-release-checker/plugin.gd new file mode 100644 index 0000000..f5fcd2c --- /dev/null +++ b/addons/gh-release-checker/plugin.gd @@ -0,0 +1,7 @@ +@tool +extends EditorPlugin + + +func _enter_tree(): + if not ProjectSettings.has_setting("addons/release_checker/repo_url"): + ProjectSettings.set_setting("addons/release_checker/repo_url", "") diff --git a/addons/gh-release-checker/update_checker.gd b/addons/gh-release-checker/update_checker.gd new file mode 100644 index 0000000..8574d52 --- /dev/null +++ b/addons/gh-release-checker/update_checker.gd @@ -0,0 +1,46 @@ +class_name UpdateChecker extends Node + +signal release_parsed(latest_release) + +var latest_release: Dictionary + + +func get_latest_version() -> void: + var req: HTTPRequest = HTTPRequest.new() + add_child(req) + req.request_completed.connect(on_request_completed) + req.request(ProjectSettings.get_setting("addons/release_checker/repo_url")) + + +func new_version_available(project_version: String, latest_version: String) -> bool: + var project_numbers: Array = project_version.split(".") + var latest_numbers: Array = latest_version.split(".") + + # We assume versions will have the same amount of numbers, otherwise IT BREAKS + for i in range(project_numbers.size()): + if int(latest_numbers[i]) > int(project_numbers[i]): + return true + + return false + + +func on_request_completed(_result, _response_code, _headers, body) -> void: + var json = JSON.parse_string(body.get_string_from_utf8()) + + if json.has("message"): + print(json["message"]) + return + + # Remove the "v" for comparison + var release_version: String = json["tag_name"].replace("v", "") + + latest_release = { + "version": json["tag_name"], + "url": json["html_url"], + "new": + new_version_available( + ProjectSettings.get_setting("application/config/version"), release_version + ) + } + + release_parsed.emit(latest_release) diff --git a/project.godot b/project.godot index 2ce80d8..ab0a2cb 100644 --- a/project.godot +++ b/project.godot @@ -14,6 +14,7 @@ universal_fade/patterns_directory="res://addons/UniversalFade/Patterns" logger/log_message_format="{hour}:{minute}:{second} [{level}] {log_name} : {message}" logger/use_utc_time_format=true logger/break_on_error=false +release_checker/repo_url="https://api.github.com/repos/MechanicalFlower/HazyRoad/releases/latest" [application] @@ -40,8 +41,8 @@ Analytics="*res://addons/quiver_analytics/analytics.tscn" [custom_options] -build_info/commit="a340227663d7250445ca4ac8b0f59f41b64e9a03" -build_info/date="2024/03/22" +build_info/commit="4604a5bbe345d12362074f3aa7806711aeb5bdef" +build_info/date="2024/03/23" [display] @@ -54,7 +55,7 @@ export/convert_text_resources_to_binary=false [editor_plugins] -enabled=PackedStringArray("res://addons/debug_menu/plugin.cfg", "res://addons/dialogue_label/plugin.cfg", "res://addons/export-build-info/plugin.cfg", "res://addons/kanban_tasks/plugin.cfg", "res://addons/logger/plugin.cfg", "res://addons/proton_scatter/plugin.cfg", "res://addons/quiver_analytics/plugin.cfg") +enabled=PackedStringArray("res://addons/debug_menu/plugin.cfg", "res://addons/dialogue_label/plugin.cfg", "res://addons/export-build-info/plugin.cfg", "res://addons/gh-release-checker/plugin.cfg", "res://addons/kanban_tasks/plugin.cfg", "res://addons/logger/plugin.cfg", "res://addons/proton_scatter/plugin.cfg", "res://addons/quiver_analytics/plugin.cfg") [filesystem] diff --git a/scenes/menu.tscn b/scenes/menu.tscn index 6d069ea..807d245 100644 --- a/scenes/menu.tscn +++ b/scenes/menu.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=34 format=3 uid="uid://bel6wcaksdcjk"] +[gd_scene load_steps=35 format=3 uid="uid://bel6wcaksdcjk"] [ext_resource type="Script" path="res://scripts/menu.gd" id="1_qiuru"] [ext_resource type="Environment" uid="uid://dtgnbg8pmfbjy" path="res://resources/fog_env.tres" id="2_nkke1"] @@ -17,6 +17,7 @@ [ext_resource type="Script" path="res://addons/proton_scatter/src/modifiers/look_at.gd" id="17_o176y"] [ext_resource type="PackedScene" uid="uid://b65hjj0ndnrnb" path="res://addons/ez-sfx-and-music/scenes/MusicPlayer/music_player.tscn" id="17_tb5q3"] [ext_resource type="Script" path="res://addons/proton_scatter/src/cache/scatter_cache.gd" id="18_2gyad"] +[ext_resource type="Script" path="res://addons/gh-release-checker/checker.gd" id="18_g6nxs"] [ext_resource type="PackedScene" uid="uid://dq6tvhqcy2aps" path="res://addons/EasyMenus/Scenes/main_menu.tscn" id="18_qnpgs"] [sub_resource type="Resource" id="Resource_l4cum"] @@ -273,6 +274,21 @@ text = "v1.0.2 @ a9602d1" horizontal_alignment = 1 script = ExtResource("17_8hvvs") +[node name="CenterContainer" type="CenterContainer" parent="HUD/EasyMenu/Content" index="6"] +layout_mode = 2 + +[node name="Control" type="Control" parent="HUD/EasyMenu/Content/CenterContainer"] +layout_mode = 2 +script = ExtResource("18_g6nxs") + +[node name="LinkBtn" type="LinkButton" parent="HUD/EasyMenu/Content/CenterContainer/Control"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + [node name="MusicPlayer" parent="." instance=ExtResource("17_tb5q3")] unique_name_in_owner = true music_folder = "res://assets/music"