unstar fix, save bookmarks on star/unstar, remove featured gates

This commit is contained in:
Nordup 2024-04-10 01:04:01 +04:00
parent f821952b9a
commit 689a1ad5a7
3 changed files with 14 additions and 28 deletions

View file

@ -10,15 +10,18 @@ extends Node
func _ready() -> void:
load_bookmarks()
bookmarks.ready()
bookmarks.save_image.connect(save_image)
bookmarks.on_star.connect(func(_gate): save_bookmarks())
bookmarks.on_unstar.connect(func(_gate): save_bookmarks())
func load_bookmarks() -> void:
if not FileAccess.file_exists(path): return
var loaded = ResourceLoader.load(path) as Bookmarks
if loaded == null: return
bookmarks.featured_gates = loaded.featured_gates
bookmarks.starred_gates = loaded.starred_gates
@ -43,7 +46,8 @@ func clear_image_folder() -> void:
if not DirAccess.dir_exists_absolute(image_save_dir): return
var used_images: Array[String] = []
for gate in bookmarks.gates.values(): used_images.append(gate.image.get_file())
for gate in bookmarks.gates.values():
used_images.append(gate.image.get_file())
for file in DirAccess.get_files_at(image_save_dir):
if not file in used_images:

View file

@ -5,27 +5,15 @@ signal on_star(gate: Gate)
signal on_unstar(gate: Gate)
signal save_image(gate: Gate)
@export var featured_gates: Array[Gate]
@export var starred_gates: Array[Gate]
var gates = {}
func ready() -> void:
var add_to_dict = func(array: Array[Gate]):
for gate in array:
if gate == null or not Url.is_valid(gate.url): continue
gates[gate.url] = gate
add_to_dict.call(featured_gates)
add_to_dict.call(starred_gates)
func is_featured(url: String) -> bool:
for gate in featured_gates:
if gate.url == url:
return true
return false
for gate in starred_gates:
if gate == null or not Url.is_valid(gate.url): continue
gates[gate.url] = gate
func update(gate: Gate) -> void:
@ -34,12 +22,9 @@ func update(gate: Gate) -> void:
var replace = gates[gate.url]
gates[gate.url] = gate
if is_featured(gate.url):
featured_gates.erase(replace)
featured_gates.append(gate)
else:
starred_gates.erase(replace)
starred_gates.append(gate)
starred_gates.erase(replace)
starred_gates.append(gate)
save_image.emit(gate)

View file

@ -22,10 +22,7 @@ func _ready() -> void:
func show_buttons(_url: String) -> void:
url = _url
if bookmarks.is_featured(url):
star.visible = false
unstar.visible = false
elif bookmarks.gates.has(url):
if bookmarks.gates.has(url):
star.visible = false
unstar.visible = true
else:
@ -36,6 +33,7 @@ func show_buttons(_url: String) -> void:
func hide_buttons() -> void:
star.visible = false
unstar.visible = false
gate = null
func update_info(_gate: Gate, _is_cached: bool) -> void:
@ -44,7 +42,6 @@ func update_info(_gate: Gate, _is_cached: bool) -> void:
bookmarks.update(gate)
func _on_star_pressed() -> void:
if gate == null:
gate = Gate.new()