Your current LSS Browsing data will be saved upon playing a custom level, and will return you to where you originally were, before play

This commit is contained in:
JHDev2006
2025-09-20 22:13:43 +01:00
parent 4cc6e938fc
commit 567e751065
9 changed files with 84 additions and 29 deletions

View File

@@ -12,11 +12,16 @@ signal level_play
var level_thumbnail = null
var container_to_play: OnlineLevelContainer = null
static var saved_stuff := {}
func _ready() -> void:
set_process(false)
func open(container: OnlineLevelContainer) -> void:
has_downloaded = FileAccess.file_exists("user://custom_levels/downloaded/" + container.level_id + ".lvl")
container_to_play = container.duplicate()
has_downloaded = FileAccess.file_exists("user://custom_levels/downloaded/" + container.level_id + ".lvl") or saved_stuff.is_empty() == false
show()
level_thumbnail = container.level_thumbnail
%Download.text = "DOWNLOAD"
@@ -33,14 +38,18 @@ func setup_visuals(container: OnlineLevelContainer) -> void:
$Panel/AutoScrollContainer.scroll_pos = 0
$Panel/AutoScrollContainer.move_direction = -1
%LSSDescription.text = "Fetching Description..."
%SelectedOnlineLevel.level_name = container.level_name
%SelectedOnlineLevel.level_author = container.level_author
%SelectedOnlineLevel.level_id = container.level_id
%SelectedOnlineLevel.thumbnail_url = container.thumbnail_url
%SelectedOnlineLevel.level_thumbnail = level_thumbnail
%SelectedOnlineLevel.difficulty = container.difficulty
if saved_stuff.is_empty():
$Description.request(LEVEL_INFO_URL + container.level_id)
else:
%LSSDescription.text = saved_stuff.description
for i in ["level_name", "level_author", "level_id", "thumbnail_url", "level_thumbnail", "difficulty"]:
var value = null
if saved_stuff.has(i):
value = saved_stuff[i]
else: value = container.get(i)
%SelectedOnlineLevel.set(i, value)
saved_stuff[i] = value
%SelectedOnlineLevel.setup_visuals()
$Description.request(LEVEL_INFO_URL + container.level_id)
%Download.visible = not has_downloaded
%OnlinePlay.visible = has_downloaded
@@ -67,6 +76,7 @@ func on_request_completed(result: int, response_code: int, headers: PackedString
var string = body.get_string_from_utf8()
var json = JSON.parse_string(string)
%LSSDescription.text = Global.sanitize_string(json["level"]["description"])
saved_stuff.description = %LSSDescription.text
func level_downloaded(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray) -> void:
var string = body.get_string_from_utf8()