mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-24 02:17:27 -04:00
unstar fix, save bookmarks on star/unstar, remove featured gates
This commit is contained in:
parent
f821952b9a
commit
689a1ad5a7
3 changed files with 14 additions and 28 deletions
|
@ -10,15 +10,18 @@ extends Node
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
load_bookmarks()
|
load_bookmarks()
|
||||||
bookmarks.ready()
|
bookmarks.ready()
|
||||||
|
|
||||||
bookmarks.save_image.connect(save_image)
|
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:
|
func load_bookmarks() -> void:
|
||||||
if not FileAccess.file_exists(path): return
|
if not FileAccess.file_exists(path): return
|
||||||
|
|
||||||
var loaded = ResourceLoader.load(path) as Bookmarks
|
var loaded = ResourceLoader.load(path) as Bookmarks
|
||||||
if loaded == null: return
|
if loaded == null: return
|
||||||
|
|
||||||
bookmarks.featured_gates = loaded.featured_gates
|
|
||||||
bookmarks.starred_gates = loaded.starred_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
|
if not DirAccess.dir_exists_absolute(image_save_dir): return
|
||||||
|
|
||||||
var used_images: Array[String] = []
|
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):
|
for file in DirAccess.get_files_at(image_save_dir):
|
||||||
if not file in used_images:
|
if not file in used_images:
|
||||||
|
|
|
@ -5,27 +5,15 @@ signal on_star(gate: Gate)
|
||||||
signal on_unstar(gate: Gate)
|
signal on_unstar(gate: Gate)
|
||||||
signal save_image(gate: Gate)
|
signal save_image(gate: Gate)
|
||||||
|
|
||||||
@export var featured_gates: Array[Gate]
|
|
||||||
@export var starred_gates: Array[Gate]
|
@export var starred_gates: Array[Gate]
|
||||||
|
|
||||||
var gates = {}
|
var gates = {}
|
||||||
|
|
||||||
|
|
||||||
func ready() -> void:
|
func ready() -> void:
|
||||||
var add_to_dict = func(array: Array[Gate]):
|
for gate in starred_gates:
|
||||||
for gate in array:
|
if gate == null or not Url.is_valid(gate.url): continue
|
||||||
if gate == null or not Url.is_valid(gate.url): continue
|
gates[gate.url] = gate
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
func update(gate: Gate) -> void:
|
func update(gate: Gate) -> void:
|
||||||
|
@ -34,12 +22,9 @@ func update(gate: Gate) -> void:
|
||||||
var replace = gates[gate.url]
|
var replace = gates[gate.url]
|
||||||
|
|
||||||
gates[gate.url] = gate
|
gates[gate.url] = gate
|
||||||
if is_featured(gate.url):
|
starred_gates.erase(replace)
|
||||||
featured_gates.erase(replace)
|
starred_gates.append(gate)
|
||||||
featured_gates.append(gate)
|
|
||||||
else:
|
|
||||||
starred_gates.erase(replace)
|
|
||||||
starred_gates.append(gate)
|
|
||||||
save_image.emit(gate)
|
save_image.emit(gate)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,7 @@ func _ready() -> void:
|
||||||
|
|
||||||
func show_buttons(_url: String) -> void:
|
func show_buttons(_url: String) -> void:
|
||||||
url = _url
|
url = _url
|
||||||
if bookmarks.is_featured(url):
|
if bookmarks.gates.has(url):
|
||||||
star.visible = false
|
|
||||||
unstar.visible = false
|
|
||||||
elif bookmarks.gates.has(url):
|
|
||||||
star.visible = false
|
star.visible = false
|
||||||
unstar.visible = true
|
unstar.visible = true
|
||||||
else:
|
else:
|
||||||
|
@ -36,6 +33,7 @@ func show_buttons(_url: String) -> void:
|
||||||
func hide_buttons() -> void:
|
func hide_buttons() -> void:
|
||||||
star.visible = false
|
star.visible = false
|
||||||
unstar.visible = false
|
unstar.visible = false
|
||||||
|
gate = null
|
||||||
|
|
||||||
|
|
||||||
func update_info(_gate: Gate, _is_cached: bool) -> void:
|
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)
|
bookmarks.update(gate)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _on_star_pressed() -> void:
|
func _on_star_pressed() -> void:
|
||||||
if gate == null:
|
if gate == null:
|
||||||
gate = Gate.new()
|
gate = Gate.new()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue