mirror of
https://github.com/JHDev2006/Super-Mario-Bros.-Remastered-Public.git
synced 2025-10-22 15:38:14 +00:00
made sub level transitions a bit smoother
This commit is contained in:
@@ -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]
|
||||
|
||||
|
@@ -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])]
|
||||
|
@@ -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:
|
||||
|
@@ -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"):
|
||||
|
Reference in New Issue
Block a user