mirror of
https://github.com/JHDev2006/Super-Mario-Bros.-Remastered-Public.git
synced 2025-10-22 07:28:14 +00:00
Add true portable mode (#259)
This commit is contained in:
@@ -41,21 +41,24 @@ func get_custom_characters() -> void:
|
||||
idx += 1
|
||||
print(Player.CHARACTER_NAMES)
|
||||
|
||||
DirAccess.make_dir_recursive_absolute("user://custom_characters")
|
||||
for i in DirAccess.get_directories_at("user://custom_characters"):
|
||||
if FileAccess.file_exists("user://custom_characters/" + i + "/CharacterInfo.json"):
|
||||
var char_path = "user://custom_characters/" + i + "/"
|
||||
var json = JSON.parse_string(FileAccess.open(char_path + "CharacterInfo.json", FileAccess.READ).get_as_text())
|
||||
var base_path = Global.config_path.rstrip("/")
|
||||
var char_dir = base_path.path_join("custom_characters")
|
||||
|
||||
for i in DirAccess.get_directories_at(char_dir):
|
||||
var char_path = char_dir.path_join(i)
|
||||
var char_info_path = char_path.path_join("CharacterInfo.json")
|
||||
if FileAccess.file_exists(char_info_path):
|
||||
var json = JSON.parse_string(FileAccess.open(char_path.path_join("CharacterInfo.json"), FileAccess.READ).get_as_text())
|
||||
Player.CHARACTERS.append(i)
|
||||
Player.CHARACTER_NAMES.append(json.name)
|
||||
if FileAccess.file_exists(char_path + "CharacterColour.json"):
|
||||
Player.CHARACTER_COLOURS.append(load(char_path + "CharacterColour.json"))
|
||||
if FileAccess.file_exists(char_path + "LifeIcon.json"):
|
||||
GameHUD.character_icons.append(load(char_path + "LifeIcon.json"))
|
||||
if FileAccess.file_exists(char_path + "ColourPalette.json"):
|
||||
Player.CHARACTER_PALETTES.append(load(char_path + "ColourPalette.json"))
|
||||
if FileAccess.file_exists(char_path + "SFX.json"):
|
||||
AudioManager.character_sfx_map[i] = JSON.parse_string(FileAccess.open(char_path + "SFX.json", FileAccess.READ).get_as_text())
|
||||
if FileAccess.file_exists(char_path.path_join("CharacterColour.json")):
|
||||
Player.CHARACTER_COLOURS.append(load(char_path.path_join("CharacterColour.json")))
|
||||
if FileAccess.file_exists(char_path.path_join("LifeIcon.json")):
|
||||
GameHUD.character_icons.append(load(char_path.path_join("LifeIcon.json")))
|
||||
if FileAccess.file_exists(char_path.path_join("ColourPalette.json")):
|
||||
Player.CHARACTER_PALETTES.append(load(char_path.path_join("ColourPalette.json")))
|
||||
if FileAccess.file_exists(char_path.path_join("SFX.json")):
|
||||
AudioManager.character_sfx_map[i] = JSON.parse_string(FileAccess.open(char_path.path_join("SFX.json"), FileAccess.READ).get_as_text())
|
||||
|
||||
func open() -> void:
|
||||
get_custom_characters()
|
||||
|
@@ -4,7 +4,6 @@ signal level_selected(container: CustomLevelContainer)
|
||||
|
||||
const CUSTOM_LEVEL_CONTAINER = preload("uid://dt20tjug8m6oh")
|
||||
|
||||
const CUSTOM_LEVEL_PATH := "user://custom_levels/"
|
||||
const base64_charset := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
|
||||
signal closed
|
||||
@@ -25,7 +24,8 @@ func open(refresh_list := true) -> void:
|
||||
set_process(true)
|
||||
|
||||
func open_folder() -> void:
|
||||
OS.shell_show_in_file_manager(ProjectSettings.globalize_path(CUSTOM_LEVEL_PATH))
|
||||
var custom_level_path = Global.config_path.path_join("custom_levels")
|
||||
OS.shell_show_in_file_manager(ProjectSettings.globalize_path(custom_level_path))
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if Input.is_action_just_pressed("ui_back"):
|
||||
@@ -41,11 +41,12 @@ func refresh() -> void:
|
||||
if i is CustomLevelContainer:
|
||||
i.queue_free()
|
||||
containers.clear()
|
||||
get_levels("user://custom_levels")
|
||||
get_levels("user://custom_levels/downloaded")
|
||||
get_levels(Global.config_path.path_join("custom_levels"))
|
||||
get_levels(Global.config_path.path_join("custom_levels/downloaded"))
|
||||
|
||||
func get_levels(path := "user://custom_levels") -> void:
|
||||
DirAccess.make_dir_recursive_absolute(path)
|
||||
func get_levels(path : String = "") -> void:
|
||||
if path == "":
|
||||
path = Global.config_path.path_join("custom_levels")
|
||||
var idx := 0
|
||||
for i in DirAccess.get_files_at(path):
|
||||
if i.contains(".lvl") == false:
|
||||
|
@@ -6,7 +6,6 @@ static var current_level_file := ""
|
||||
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
|
||||
|
@@ -21,7 +21,7 @@ func _ready() -> void:
|
||||
|
||||
func open(container: OnlineLevelContainer) -> void:
|
||||
container_to_play = container.duplicate()
|
||||
has_downloaded = FileAccess.file_exists("user://custom_levels/downloaded/" + container.level_id + ".lvl") or saved_stuff.is_empty() == false
|
||||
has_downloaded = FileAccess.file_exists(Global.config_path.path_join("custom_levels/downloaded/" + container.level_id + ".lvl")) or saved_stuff.is_empty() == false
|
||||
show()
|
||||
level_thumbnail = container.level_thumbnail
|
||||
%Download.text = "DOWNLOAD"
|
||||
@@ -66,7 +66,7 @@ func close() -> void:
|
||||
set_process(false)
|
||||
|
||||
func download_level() -> void:
|
||||
DirAccess.make_dir_recursive_absolute("user://custom_levels/downloaded")
|
||||
DirAccess.make_dir_recursive_absolute(Global.config_path.path_join("custom_levels/downloaded"))
|
||||
var url = "https://levelsharesquare.com/api/levels/" + level_id + "/code"
|
||||
print(url)
|
||||
$DownloadLevel.request(url, [], HTTPClient.METHOD_GET)
|
||||
@@ -85,7 +85,7 @@ func on_request_completed(result: int, response_code: int, headers: PackedString
|
||||
func level_downloaded(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray) -> void:
|
||||
var string = body.get_string_from_utf8()
|
||||
var json = JSON.parse_string(string)
|
||||
var file = FileAccess.open("user://custom_levels/downloaded/" + level_id + ".lvl", FileAccess.WRITE)
|
||||
var file = FileAccess.open(Global.config_path.path_join("custom_levels/downloaded/" + level_id + ".lvl"), FileAccess.WRITE)
|
||||
var data = null
|
||||
if json.levelData.data is Array:
|
||||
data = get_json_from_bytes(json.levelData.data)
|
||||
@@ -101,11 +101,11 @@ func level_downloaded(result: int, response_code: int, headers: PackedStringArra
|
||||
func save_thumbnail() -> void:
|
||||
if OnlineLevelContainer.cached_thumbnails.has(level_id):
|
||||
var thumbnail = OnlineLevelContainer.cached_thumbnails.get(level_id)
|
||||
DirAccess.make_dir_recursive_absolute("user://custom_levels/downloaded/thumbnails")
|
||||
thumbnail.get_image().save_png("user://custom_levels/downloaded/thumbnails/"+ level_id + ".png")
|
||||
DirAccess.make_dir_recursive_absolute(Global.config_path.path_join("custom_levels/downloaded/thumbnails"))
|
||||
thumbnail.get_image().save_png(Global.config_path.path_join("custom_levels/downloaded/thumbnails/" + level_id + ".png"))
|
||||
|
||||
func play_level() -> void:
|
||||
var file_path := "user://custom_levels/downloaded/" + level_id + ".lvl"
|
||||
var file_path := Global.config_path.path_join("custom_levels/downloaded/" + level_id + ".lvl")
|
||||
var file = JSON.parse_string(FileAccess.open(file_path, FileAccess.READ).get_as_text())
|
||||
LevelEditor.level_file = file
|
||||
set_process(false)
|
||||
|
Reference in New Issue
Block a user