made sub level transitions a bit smoother

This commit is contained in:
JHDev2006
2025-09-20 19:09:34 +01:00
parent 99066de39b
commit 4cc6e938fc
11 changed files with 2839 additions and 2708 deletions

View File

@@ -657,6 +657,7 @@ func transition_to_sublevel(sub_lvl_idx := 0) -> void:
LevelPersistance.reset_states()
sub_level_id = sub_lvl_idx
$LevelLoader.load_level(sub_lvl_idx)
Global.do_fake_transition(0.1)
await get_tree().physics_frame
if (play_pipe_transition or play_door_transition) and play_transition:
parse_tiles()

View File

@@ -304,16 +304,16 @@ func transition_to_scene(scene_path := "") -> void:
func do_fake_transition() -> void:
func do_fake_transition(duration := 0.2) -> void:
if fade_transition:
$Transition/AnimationPlayer.play("FadeIn")
await $Transition/AnimationPlayer.animation_finished
await get_tree().create_timer(0.2, false).timeout
await get_tree().create_timer(duration, false).timeout
$Transition/AnimationPlayer.play_backwards("FadeIn")
else:
%TransitionBlock.modulate.a = 1
$Transition.show()
await get_tree().create_timer(0.25, false).timeout
await get_tree().create_timer(duration + 0.05, false).timeout
$Transition.hide()
func freeze_screen() -> void:

View File

@@ -12,6 +12,7 @@ var game_style := "SMBLL"
var difficulty := 0
var file_path := ""
var is_downloaded := false
var thumbnail: Texture = null
var level_id := ""
var idx := 0
@@ -55,9 +56,14 @@ func _ready() -> void:
update_visuals()
func update_visuals() -> void:
if is_downloaded:
%LevelIcon.texture = ImageTexture.create_from_image(Image.load_from_file("user://custom_levels/downloaded/thumbnails/" + level_id + ".png"))
if is_downloaded and FileAccess.file_exists("user://custom_levels/downloaded/thumbnails/" + level_id + ".png"):
thumbnail = ImageTexture.create_from_image(Image.load_from_file("user://custom_levels/downloaded/thumbnails/" + level_id + ".png"))
%Thumbnail.texture = thumbnail
%LevelIcon.hide()
%Thumbnail.show()
else:
%Thumbnail.hide()
%LevelIcon.show()
%LevelIcon.texture = ResourceSetter.get_resource(ICON_TEXTURES[level_time])
%LevelIcon.region_rect = THEME_RECTS[level_theme]

View File

@@ -52,19 +52,20 @@ func get_levels(path := "user://custom_levels") -> void:
continue
%LevelContainers.get_node("Label").hide()
var container = CUSTOM_LEVEL_CONTAINER.instantiate()
var file = FileAccess.open(path + "/" + i, FileAccess.READ)
var file_path = path + "/" + i
var file = FileAccess.open(file_path, FileAccess.READ)
var json = JSON.parse_string(file.get_as_text())
file.close()
var data = json["Levels"][0]["Data"].split("=")
var info = json["Info"]
container.is_downloaded = path.contains("/downloaded/")
container.is_downloaded = path.contains("downloaded")
if container.is_downloaded:
container.level_id = path.get_file().replace(".lvl", "")
container.level_id = file_path.get_file().replace(".lvl", "")
container.level_name = info["Name"]
container.level_author = info["Author"]
container.level_desc = info["Description"]
container.idx = idx
container.file_path = path + "/" + i
container.file_path = file_path
container.level_theme = Level.THEME_IDXS[base64_charset.find(data[0])]
container.level_time = base64_charset.find(data[1])
container.game_style = Global.CAMPAIGNS[base64_charset.find(data[3])]

View File

@@ -79,6 +79,7 @@ func spawn_containers() -> void:
container.level_author = i.author.username
container.difficulty = i.difficulty
container.level_id = i._id
container.ratings = i.rates
container.level_selected.connect(show_info)
if i.has("thumbnail"):
if i.thumbnail != null:

View File

@@ -7,6 +7,8 @@ var level_thumbnail = null
var level_id := ""
var thumbnail_url := ""
var ratings := []
var difficulty := "Easy"
var featured = false
@@ -38,10 +40,19 @@ func setup_visuals() -> void:
print(difficulty)
var difficulty_int = DIFFICULTY_TO_STAR_TRANSLATION[difficulty]
for i in %DifficultyStars.get_children():
i.region_rect.position.x = 24 if idx > difficulty_int else [0, 0, 8, 8, 16][difficulty_int]
i.region_rect.position.x = 32 if idx > difficulty_int else [0, 8, 8, 16, 24][difficulty_int]
idx += 1
setup_rating_stars()
get_thumbnail()
func setup_rating_stars() -> void:
var rating = calculate_rating()
var idx := 0
for i in %RatingStars.get_children():
i.region_rect.position.x = 16 if idx > rating else (0 if abs(idx - rating) >= 0.5 else 8)
idx += 1
func get_thumbnail() -> void:
if cached_thumbnails.has(level_id):
%LevelIcon.texture = cached_thumbnails[level_id]
@@ -53,6 +64,17 @@ func get_thumbnail() -> void:
return
$ThumbnailDownloader.request(thumbnail_url, [], HTTPClient.METHOD_GET)
func calculate_rating() -> int:
var rating := -1.0
var total := 0
if ratings.is_empty():
return 0
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:
var image = Image.new()
if thumbnail_url.contains(".webp"):