Skip to content

Commit

Permalink
feat: add link to the latest available version
Browse files Browse the repository at this point in the history
  • Loading branch information
florianvazelle committed Mar 23, 2024
1 parent 4604a5b commit b873d7f
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ data_*/
addons/*
!addons/gd-plug/
!addons/export-build-info/
!addons/gh-release-checker/

# Python-specific ignores
venv/
Expand Down
12 changes: 12 additions & 0 deletions .godot/global_script_class_cache.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down Expand Up @@ -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"
}])
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions addons/gh-release-checker/checker.gd
Original file line number Diff line number Diff line change
@@ -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"]
7 changes: 7 additions & 0 deletions addons/gh-release-checker/plugin.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[plugin]

name="release_checker"
description=""
author="florianvazelle"
version="0.0.0"
script="plugin.gd"
7 changes: 7 additions & 0 deletions addons/gh-release-checker/plugin.gd
Original file line number Diff line number Diff line change
@@ -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", "")
46 changes: 46 additions & 0 deletions addons/gh-release-checker/update_checker.gd
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 4 additions & 3 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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]

Expand All @@ -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]

Expand Down
18 changes: 17 additions & 1 deletion scenes/menu.tscn
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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"]
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit b873d7f

Please sign in to comment.