feat: prep the automation

This commit is contained in:
2026-04-24 00:40:40 +08:00
parent 7e4b707e84
commit 53f151af1d
32 changed files with 426 additions and 171 deletions
+56 -6
View File
@@ -29,6 +29,7 @@ var http_request: HTTPRequest
var download_request: HTTPRequest
var is_downloading: bool = false
var pending_pck_path: String = ""
var _timeout_timer: Timer
func _ready() -> void:
# Load embedded version
@@ -44,6 +45,14 @@ func _ready() -> void:
download_request.name = "DownloadRequest"
add_child(download_request)
download_request.request_completed.connect(_on_download_completed)
# Timeout fallback — if no response in 5s, use local manifest
_timeout_timer = Timer.new()
_timeout_timer.name = "VersionCheckTimeout"
_timeout_timer.wait_time = 5.0
_timeout_timer.one_shot = true
_timeout_timer.timeout.connect(_on_version_timeout)
add_child(_timeout_timer)
func _load_embedded_version() -> void:
# Try to load version from embedded file first
@@ -108,29 +117,68 @@ static func get_platform_name() -> String:
func check_for_updates() -> void:
emit_signal("update_check_started")
print("[GameUpdateManager] Checking for updates...")
# In the editor, skip network fetch — use local manifest directly
if Engine.is_editor_hint() or OS.has_feature("editor"):
print("[GameUpdateManager] Editor mode — using local manifest.")
_load_local_manifest()
return
print("[GameUpdateManager] Checking for updates from: ", VERSION_MANIFEST_URL)
_timeout_timer.start()
var error := http_request.request(VERSION_MANIFEST_URL)
if error != OK:
emit_signal("update_check_failed", "Failed to connect to update server")
_timeout_timer.stop()
push_warning("[GameUpdateManager] Request failed instantly, using local manifest.")
_load_local_manifest()
func _on_version_timeout() -> void:
push_warning("[GameUpdateManager] Version check timed out, using local manifest.")
http_request.cancel_request()
_load_local_manifest()
func _on_version_check_completed(result: int, response_code: int, _headers: PackedStringArray, body: PackedByteArray) -> void:
_timeout_timer.stop()
if result != HTTPRequest.RESULT_SUCCESS:
emit_signal("update_check_failed", "Network error")
push_warning("[GameUpdateManager] Network error (result=%d), falling back to local manifest." % result)
_load_local_manifest()
return
if response_code != 200:
emit_signal("update_check_failed", "Server error: " + str(response_code))
push_warning("[GameUpdateManager] Server returned %d, falling back to local manifest." % response_code)
_load_local_manifest()
return
var json := JSON.new()
if json.parse(body.get_string_from_utf8()) != OK:
emit_signal("update_check_failed", "Invalid update data")
push_warning("[GameUpdateManager] JSON parse failed, falling back to local manifest.")
_load_local_manifest()
return
manifest_data = json.data
_process_manifest()
func _load_local_manifest() -> void:
const LOCAL_MANIFEST := "res://assets/data/version.json"
if not FileAccess.file_exists(LOCAL_MANIFEST):
emit_signal("update_check_failed", "No manifest available (offline)")
return
var f := FileAccess.open(LOCAL_MANIFEST, FileAccess.READ)
if not f:
emit_signal("update_check_failed", "Could not read local manifest")
return
var parsed = JSON.parse_string(f.get_as_text())
if not parsed is Dictionary:
emit_signal("update_check_failed", "Invalid local manifest JSON")
return
manifest_data = parsed
_process_manifest()
func _process_manifest() -> void:
latest_version = manifest_data.get("latest_version", current_version)
print("[GameUpdateManager] current_version=%s latest_version=%s" % [current_version, latest_version])
var has_update := _compare_versions(current_version, latest_version) < 0
var min_version: String = manifest_data.get("minimum_app_version", "0.0.0")
var needs_store_update := _compare_versions(current_version, min_version) < 0
@@ -144,7 +192,9 @@ func _on_version_check_completed(result: int, response_code: int, _headers: Pack
"can_patch": _can_apply_patch() and not needs_store_update
}
print("[GameUpdateManager] Update check complete - Has update: ", has_update)
print("[GameUpdateManager] has_update=%s can_patch=%s needs_store=%s" % [
has_update, update_info.can_patch, needs_store_update
])
emit_signal("update_check_completed", has_update, update_info)
if needs_store_update and is_mobile():