From 97045e25ded4881a6170b3552899c6a6643b9c38 Mon Sep 17 00:00:00 2001 From: Nordup Date: Sun, 10 Aug 2025 15:03:11 +0700 Subject: [PATCH] use only gate icon, fix emty bookmark icon --- app/resources/bookmarks.tres | 6 +++--- app/scripts/api/featured_gates.gd | 12 +++++++----- app/scripts/loading/gate_loader.gd | 2 +- app/scripts/resources/bookmarks.gd | 11 +++++++++++ app/scripts/resources/gate.gd | 19 ++++++------------- app/scripts/ui/menu/bookmark_ui.gd | 6 +++++- app/scripts/ui/menu/star.gd | 8 ++++++-- app/scripts/ui/onboarding/onboarding.gd | 2 +- app/scripts/ui/search/result.gd | 3 +-- 9 files changed, 41 insertions(+), 28 deletions(-) diff --git a/app/resources/bookmarks.tres b/app/resources/bookmarks.tres index 3922f9d..a6ce2bd 100644 --- a/app/resources/bookmarks.tres +++ b/app/resources/bookmarks.tres @@ -1,8 +1,8 @@ -[gd_resource type="Resource" script_class="Bookmarks" load_steps=2 format=3 uid="uid://bewhdj6jugt6q"] +[gd_resource type="Resource" script_class="Bookmarks" load_steps=3 format=3 uid="uid://bewhdj6jugt6q"] [ext_resource type="Script" path="res://scripts/resources/bookmarks.gd" id="1_1h3wl"] +[ext_resource type="Script" path="res://scripts/resources/gate.gd" id="2_4h04h"] [resource] script = ExtResource("1_1h3wl") -featured_gates = Array[Resource("res://scripts/resources/gate.gd")]([]) -starred_gates = Array[Resource("res://scripts/resources/gate.gd")]([]) +starred_gates = Array[ExtResource("2_4h04h")]([]) diff --git a/app/scripts/api/featured_gates.gd b/app/scripts/api/featured_gates.gd index 70baace..ff3418f 100644 --- a/app/scripts/api/featured_gates.gd +++ b/app/scripts/api/featured_gates.gd @@ -1,7 +1,9 @@ extends Node +const KEY_URL = "url" +const KEY_TITLE = "title" +const KEY_DESCRIPTION = "description" const KEY_ICON = "icon" -const KEY_IMAGE = "image" @export var api: ApiSettings @export var bookmarks: Bookmarks @@ -41,8 +43,8 @@ func featured_gates_request() -> void: func star_gate(gate_d: Dictionary) -> void: - var icon_url = gate_d[KEY_ICON] if not gate_d[KEY_ICON].is_empty() else gate_d[KEY_IMAGE] - var icon_path = await FileDownloader.download(icon_url) - var gate = Gate.create(gate_d["url"], gate_d["title"], gate_d["description"], icon_path, "", "", "") - + var gate = Gate.create(gate_d[KEY_URL], gate_d[KEY_TITLE], gate_d[KEY_DESCRIPTION], gate_d[KEY_ICON], "") bookmarks.star(gate, true) + + gate.icon = await FileDownloader.download(gate.icon_url) + bookmarks.update(gate) diff --git a/app/scripts/loading/gate_loader.gd b/app/scripts/loading/gate_loader.gd index d594426..7954955 100644 --- a/app/scripts/loading/gate_loader.gd +++ b/app/scripts/loading/gate_loader.gd @@ -30,7 +30,7 @@ func load_gate(config_url: String) -> void: if c_gate.load_result != OK: return error(GateEvents.GateError.INVALID_CONFIG) gate_events.gate_config_loaded_emit(config_url, c_gate) - gate = Gate.create(config_url, c_gate.title, c_gate.description, "", "", "", "") + gate = Gate.create(config_url, c_gate.title, c_gate.description, c_gate.icon_url, c_gate.image_url) gate_events.gate_info_loaded_emit(gate) # Download all in parallel diff --git a/app/scripts/resources/bookmarks.gd b/app/scripts/resources/bookmarks.gd index 248c143..f7edd7f 100644 --- a/app/scripts/resources/bookmarks.gd +++ b/app/scripts/resources/bookmarks.gd @@ -23,11 +23,22 @@ func ready() -> void: on_ready.emit() +func make_first(url: String) -> void: + if not gates.has(url): return + + var gate = gates[url] + gates.erase(url) + gates[url] = gate + + func update(gate: Gate) -> void: if not gates.has(gate.url): return var replace = gates[gate.url] + if gate.icon_url == replace.icon_url: gate.icon = replace.icon + if gate.image_url == replace.image_url: gate.image = replace.image + gates.erase(gate.url) gates[gate.url] = gate diff --git a/app/scripts/resources/gate.gd b/app/scripts/resources/gate.gd index 8731082..469bc5f 100644 --- a/app/scripts/resources/gate.gd +++ b/app/scripts/resources/gate.gd @@ -5,28 +5,21 @@ class_name Gate set(value): url = Url.fix_gate_url(value) @export var title: String - @export var description: String - -@export var icon: String: - get: return icon if not icon.is_empty() else image - set(value): icon = value - +@export var icon_url: String +@export var image_url: String +@export var icon: String @export var image: String var resource_pack: String - var shared_libs_dir: String # local path where libs downloaded -static func create(_url: String, _title: String, _description: String, _icon: String, - _image: String, _resource_pack: String, _shared_libs_dir: String) -> Gate: +static func create(_url: String, _title: String, _description: String, _icon_url: String, _image_url: String) -> Gate: var gate = Gate.new() gate.url = _url gate.title = _title gate.description = _description - gate.icon = _icon - gate.image = _image - gate.resource_pack = _resource_pack - gate.shared_libs_dir = _shared_libs_dir + gate.icon_url = _icon_url + gate.image_url = _image_url return gate diff --git a/app/scripts/ui/menu/bookmark_ui.gd b/app/scripts/ui/menu/bookmark_ui.gd index 11aba17..7f0946b 100644 --- a/app/scripts/ui/menu/bookmark_ui.gd +++ b/app/scripts/ui/menu/bookmark_ui.gd @@ -23,7 +23,11 @@ func fill(gate: Gate, special: bool = false) -> void: url = gate.url title.text = "Unnamed" if gate.title.is_empty() else gate.title - icon.texture = FileTools.load_external_tex(gate.icon) + + var icon_path = gate.icon + if icon_path.is_empty(): icon_path = await FileDownloader.download(gate.icon_url) + + icon.texture = FileTools.load_external_tex(icon_path) func on_pressed() -> void: diff --git a/app/scripts/ui/menu/star.gd b/app/scripts/ui/menu/star.gd index ab9a5cf..6ea6dbe 100644 --- a/app/scripts/ui/menu/star.gd +++ b/app/scripts/ui/menu/star.gd @@ -15,6 +15,7 @@ func _ready() -> void: unstar.visible = false gate_events.open_gate.connect(show_buttons) + gate_events.open_gate.connect(update_gate_order) gate_events.search.connect(func(_query): hide_buttons()) gate_events.exit_gate.connect(hide_buttons) gate_events.gate_info_loaded.connect(update_info) @@ -38,10 +39,13 @@ func hide_buttons() -> void: gate = null +func update_gate_order(_url: String) -> void: + bookmarks.make_first(_url) + + func update_info(_gate: Gate) -> void: gate = _gate - if bookmarks.gates.has(gate.url): - bookmarks.update(gate) + bookmarks.update(gate) func _on_star_pressed() -> void: diff --git a/app/scripts/ui/onboarding/onboarding.gd b/app/scripts/ui/onboarding/onboarding.gd index 4230b3d..37fce73 100644 --- a/app/scripts/ui/onboarding/onboarding.gd +++ b/app/scripts/ui/onboarding/onboarding.gd @@ -20,7 +20,7 @@ func _ready() -> void: root.mouse_filter = Control.MOUSE_FILTER_PASS await get_tree().create_timer(1.0).timeout - show_onboarding() + #show_onboarding() func show_onboarding() -> void: diff --git a/app/scripts/ui/search/result.gd b/app/scripts/ui/search/result.gd index bdb227a..73d3064 100644 --- a/app/scripts/ui/search/result.gd +++ b/app/scripts/ui/search/result.gd @@ -22,8 +22,7 @@ func fill(gate: Dictionary) -> void: title.text = "Unnamed" if gate[KEY_TITLE].is_empty() else gate[KEY_TITLE] description.text = gate[KEY_DESCRIPTION] - var icon_url = gate[KEY_ICON] if not gate[KEY_ICON].is_empty() else gate[KEY_IMAGE] - var icon_path = await FileDownloader.download(icon_url) + var icon_path = await FileDownloader.download(gate[KEY_ICON]) icon.texture = FileTools.load_external_tex(icon_path)