Skip to content

Commit

Permalink
update check
Browse files Browse the repository at this point in the history
  • Loading branch information
ArMM1998 committed Oct 20, 2023
1 parent c38a760 commit 00a5ea2
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
20 changes: 19 additions & 1 deletion main_scene.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=20 format=3 uid="uid://bnun2iv8b4jy2"]
[gd_scene load_steps=21 format=3 uid="uid://bnun2iv8b4jy2"]

[ext_resource type="Script" path="res://scripts/main.gd" id="1_k4y86"]
[ext_resource type="Script" path="res://scripts/Panels.gd" id="2"]
Expand All @@ -19,6 +19,7 @@
[ext_resource type="Texture2D" uid="uid://c60opsv5gwi3c" path="res://Graphics/del.png" id="11_2redu"]
[ext_resource type="Script" path="res://scripts/SpriteCropList.gd" id="11_oydw2"]
[ext_resource type="Script" path="res://scripts/kofi_btn.gd" id="11_tcy6v"]
[ext_resource type="Script" path="res://scripts/updateChecker.gd" id="20_r06tp"]

[node name="main" type="Node2D"]
script = ExtResource("1_k4y86")
Expand Down Expand Up @@ -371,8 +372,23 @@ offset_bottom = 32.0
texture_normal = ExtResource("10_iig2l")
script = ExtResource("11_tcy6v")

[node name="Update" type="AcceptDialog" parent="Layer3_Popups"]
title = "New version found."
position = Vector2i(380, 192)
size = Vector2i(300, 150)
exclusive = false
unresizable = true
min_size = Vector2i(144, 0)
ok_button_text = "Download"
dialog_text = "asdsd
"
dialog_autowrap = true

[node name="directory_watcher" type="Node" parent="."]

[node name="HTTPRequest" type="HTTPRequest" parent="."]
script = ExtResource("20_r06tp")

[connection signal="selected_element" from="Layer1_Canvas/CanvasViewport" to="." method="_on_canvas_viewport_selected_element"]
[connection signal="toggled" from="Layer2_Panels/toggle_panelLeft" to="Layer2_Panels" method="panelLeftToggle"]
[connection signal="toggled" from="Layer2_Panels/toggle_panelRight" to="Layer2_Panels" method="panelRightToggle"]
Expand All @@ -391,3 +407,5 @@ script = ExtResource("11_tcy6v")
[connection signal="mouse_exited" from="Layer3_Popups/About/Node2D/TextureButton" to="Layer3_Popups/About/Node2D/TextureButton" method="_on_mouse_exited"]
[connection signal="pressed" from="Layer3_Popups/About/Node2D/TextureButton" to="Layer3_Popups/About/Node2D/TextureButton" method="_on_pressed"]
[connection signal="visibility_changed" from="Layer3_Popups/About/Node2D/TextureButton" to="Layer3_Popups/About/Node2D/TextureButton" method="_on_visibility_changed"]
[connection signal="confirmed" from="Layer3_Popups/Update" to="." method="_on_update_confirmed"]
[connection signal="request_completed" from="HTTPRequest" to="HTTPRequest" method="_on_request_completed"]
1 change: 1 addition & 0 deletions scripts/PanelTop.gd
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func helpMenu(item_id):
owner.about.popup()
await owner.about.confirmed
if item_id == 1:

OS.shell_open("https://docs.google.com/document/d/1hvHQTxsCdjIkRdY6yn8P2_9U6CVT1cY_T7exJMBxgPw/view")
if item_id == 2:
OS.shell_open("https://ko-fi.com/armm1998")
Expand Down
12 changes: 12 additions & 0 deletions scripts/main.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
extends Node2D

var current_version = "0.5"


@onready var layer_2_panels = $Layer2_Panels
@onready var fileDialog = $Layer3_Popups/FileDialog
@onready var accept_dialog = $Layer3_Popups/AcceptDialog
Expand Down Expand Up @@ -1725,3 +1728,12 @@ func delAnimation(undo = true):
animation_idx-= 1
$Layer2_Panels/PanelBottom.updateAnimList()
$Layer2_Panels/PanelBottom/AnimationList.select(animation_idx)

func popupUpdate(version):
$Layer3_Popups/Update.dialog_text = "New version found: " + version
$Layer3_Popups/Update.popup()



func _on_update_confirmed():
OS.shell_open("https://github.com/ArMM1998/PuyoEdit/releases")
51 changes: 51 additions & 0 deletions scripts/updateChecker.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
extends HTTPRequest

func _ready():
var url = "https://github.com/ArMM1998/PuyoEdit/releases/latest"
request(url)


func _on_request_completed(result, response_code, headers, body):
if response_code == 200: # Success
body = str(body.get_string_from_ascii())

var version = (body.substr(body.find("/ArMM1998/PuyoEdit/releases/tag/"), 256).split("\"")[0].split("tag/")[1])

var out_of_date = checkVersion(version)
if out_of_date:
owner.popupUpdate(version)

else:
print("Request failed with response code: ", response_code)


func checkVersion(version):
var current_version = []
for digit in owner.current_version.split("."):
current_version.append(int(digit))

if current_version.size() == 2:
current_version.append(0)
var online_version = []
for digit in version.split("."):
online_version.append(int(digit))
if online_version.size() == 2:
online_version.append(0)

#check first digit
if current_version[0] < online_version[0]: #online version is newer
return(true)
elif current_version[0] > online_version[0]: #online version is older
return(false)
else: #first digit matches, so move on to the next
if current_version[1] < online_version[1]: #online version is newer
return(true)
elif current_version[1] > online_version[1]: #online version is older
return(false)
else: #second digit also matches. check if there is a third
if current_version[2] < online_version[2]: #online version is newer
return(true)
elif current_version[2] > online_version[2]: #online version is older
return(false)
else: #second digit also matches. check if there is a third
return(false)
Empty file added txt
Empty file.

0 comments on commit 00a5ea2

Please sign in to comment.