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

@@ -8,6 +8,10 @@ static var has_entered := false
var selected_lvl_idx := 0
const CUSTOM_LEVEL_PATH := "user://custom_levels/"
const base64_charset := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
static var page_number_save := -1
static var last_played_container = null
static var saved_search_values := [-1, -1, -1]
func _ready() -> void:
has_entered = true
@@ -23,6 +27,28 @@ func _ready() -> void:
AudioManager.stop_all_music()
Global.second_quest = false
%LevelList.open(true)
await get_tree().process_frame
if last_played_container != null:
print(saved_search_values)
%LSSBrowser.setup_page_numbers()
%LSSBrowser.page_number = saved_search_values[0]
%Page.selected_index = saved_search_values[0] - 1
%LSSBrowser.filter = saved_search_values[1]
%Sort.selected_index = saved_search_values[1]
%LSSBrowser.order = saved_search_values[2]
%Order.selected_index = %LSSBrowser.order
%LSSLevelInfo.open(last_played_container)
await get_tree().process_frame
%LSSBrowser.grab_levels()
%LevelList.close()
func clear_saved_stuff() -> void:
%LSSLevelInfo.saved_stuff.clear()
saved_search_values = [-1, -1, -1]
%LSSBrowser.number_of_pages = -1
func _exit_tree() -> void:
Global.get_node("GameHUD").show()
@@ -38,11 +64,13 @@ func new_level() -> void:
Global.transition_to_scene("res://Scenes/Levels/LevelEditor.tscn")
func back_to_title_screen() -> void:
clear_saved_stuff()
if Global.transitioning_scene:
await Global.transition_finished
Global.transition_to_scene("res://Scenes/Levels/TitleScreen.tscn")
func edit_level() -> void:
clear_saved_stuff()
Global.current_game_mode = Global.GameMode.LEVEL_EDITOR
LevelEditor.load_play = false
Global.transition_to_scene("res://Scenes/Levels/LevelEditor.tscn")
@@ -56,6 +84,12 @@ func play_level() -> void:
LevelTransition.level_to_transition_to = ("res://Scenes/Levels/LevelEditor.tscn")
Global.transition_to_scene("res://Scenes/Levels/LevelTransition.tscn")
func lss_level_played() -> void:
last_played_container = %LSSLevelInfo.container_to_play.duplicate()
page_number_save = %LSSBrowser.page_number
saved_search_values[0] = %LSSBrowser.page_number
saved_search_values[1] = %LSSBrowser.filter
saved_search_values[2] = %LSSBrowser.order
func delete_level() -> void:
DirAccess.remove_absolute(current_level_file)

View File

@@ -14,7 +14,7 @@ signal level_edit
func open(container: CustomLevelContainer = null) -> void:
if container != null:
for i in ["level_name", "level_author", "level_theme", "game_style", "level_time", "difficulty"]:
for i in ["level_name", "level_author", "level_theme", "game_style", "level_time", "difficulty", "is_downloaded", "level_id", "thumbnail"]:
%SelectedLevel.set(i, container.get(i))
%SelectedLevel.update_visuals()
LevelEditor.level_name = container.level_name

View File

@@ -13,7 +13,8 @@ const ONLINE_LEVEL_CONTAINER = preload("uid://cr2pku7fjkgpo")
var filter = 0
var selected_lvl_idx := -1
var sort := -1
var order := 0
static var number_of_pages := -1
func _ready() -> void:
set_process(false)
@@ -49,7 +50,7 @@ func grab_levels() -> void:
var filter_str = ["", "", "&sort=plays", "&sort=rating"][filter]
var get_type = ["featured?", "get?", "get?", "get?"][filter]
var page_str = "&page=" + str(page_number)
var url = LSS_URL + "/api/levels/filter/" + get_type + "game=" + str(Global.LSS_GAME_ID) + "&authors=1" + filter_str + page_str + "&sortType=" + str(sort)
var url = LSS_URL + "/api/levels/filter/" + get_type + "game=" + str(Global.LSS_GAME_ID) + "&authors=1" + filter_str + page_str + "&sortType=" + str(order)
http_request.request(url, [], HTTPClient.METHOD_GET)
func level_list_retrieved(result := 0, response_code := 0, headers: PackedStringArray = [], body: PackedByteArray = []) -> void:
@@ -63,10 +64,13 @@ func level_list_retrieved(result := 0, response_code := 0, headers: PackedString
return
var json = JSON.parse_string(string)
list = json
print(list)
spawn_containers()
%Page.values.clear()
for i in json.numberOfPages:
number_of_pages = json.numberOfPages
setup_page_numbers()
func setup_page_numbers() -> void:
for i in number_of_pages:
%Page.values.append(str(int(i + 1)))
func spawn_containers() -> void:
@@ -99,5 +103,5 @@ func set_page(page_idx := 0) -> void:
grab_levels()
func set_order(order_idx := 0) -> void:
sort = [-1, 1][order_idx]
order = [-1, 1][order_idx]
grab_levels()

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

View File

@@ -37,7 +37,6 @@ func setup_visuals() -> void:
if featured:
self_modulate = Color.YELLOW
var idx := 0
print(difficulty)
var difficulty_int = DIFFICULTY_TO_STAR_TRANSLATION[difficulty]
for i in %DifficultyStars.get_children():
i.region_rect.position.x = 32 if idx > difficulty_int else [0, 8, 8, 16, 24][difficulty_int]
@@ -72,7 +71,6 @@ func calculate_rating() -> int:
for i in ratings:
total += i
rating = total / float(ratings.size())
print(rating)
return rating
func on_request_completed(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray) -> void: