use only gate icon, fix emty bookmark icon

This commit is contained in:
Nordup 2025-08-10 15:03:11 +07:00
parent 550f89bcf6
commit 97045e25de
9 changed files with 41 additions and 28 deletions

View file

@ -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")]([])

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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)