Character pictures are kept in characters/ next to the settings, with an index.json of when the server last changed each one and when it was downloaded. Only new or changed pictures are downloaded, using the server's new /character/details. Older servers fall back to the name list, and pictures are downloaded again after 7 days. Downloaded songs are written to songs/ and only their paths are kept in memory. The folder is emptied when the game starts and when the playlist resets.
65 lines
2.1 KiB
GDScript
65 lines
2.1 KiB
GDScript
class_name CharacterSelectPopup
|
|
extends BasePopup
|
|
|
|
## Emitted with the picture of the character that was picked.
|
|
signal character_selected(texture: ImageTexture)
|
|
|
|
var can_select_character: bool = false
|
|
var character: PackedScene = preload("res://popups/CharacterCard.tscn")
|
|
## Keeps the pictures on disk, so only changed ones are downloaded.
|
|
var character_cache: CharacterCache = CharacterCache.new()
|
|
|
|
@onready var character_panel: Panel = %CharacterPanel
|
|
@onready var title_label: Label = %TitleLabel
|
|
@onready var character_grid: GridContainer = %CharacterGridContainer
|
|
@onready var close_timer: Timer = %CloseTimer
|
|
|
|
|
|
func _ready() -> void:
|
|
close_timer.timeout.connect(_on_close_timeout)
|
|
|
|
|
|
func _on_close_timeout() -> void:
|
|
GameLog.debug("_on_close_timeout!")
|
|
Settings.character_select_open = false
|
|
close_timer.stop()
|
|
|
|
|
|
func load_characters() -> void:
|
|
GameLog.debug("load_characters")
|
|
var list_loaded: Callable = func list_loaded(names: Array[String]) -> void:
|
|
GameLog.debug("list_loaded")
|
|
Settings.delete_children(character_grid)
|
|
for character_name: String in names:
|
|
GameLog.debug("character_name ", character_name)
|
|
var character_box: CharacterCard = character.instantiate()
|
|
character_grid.add_child(character_box)
|
|
character_box.set_character_name(character_name, character_cache.fetch_image)
|
|
character_box.new_character_selected.connect(_on_character_selected)
|
|
character_cache.load_list(list_loaded)
|
|
|
|
|
|
func show_grid(player_name: String) -> void:
|
|
GameLog.debug("show_grid")
|
|
title_label.text = "Select character for " + player_name
|
|
close_timer.stop()
|
|
open()
|
|
can_select_character = true
|
|
Settings.character_select_open = true
|
|
|
|
|
|
func close() -> void:
|
|
super()
|
|
Settings.character_select_open = false
|
|
|
|
|
|
func _on_character_selected(texture: ImageTexture) -> void:
|
|
GameLog.debug("_on_character_selected")
|
|
# Not close(): character_select_open stays true until close_timer fires, so the click
|
|
# that picked the character does not also select a song behind it
|
|
visible = false
|
|
if can_select_character:
|
|
character_selected.emit(texture)
|
|
close_timer.start()
|
|
can_select_character = false
|