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:
@@ -113,7 +113,7 @@ func play_sfx(stream_name = "", position := Vector2.ZERO, pitch := 1.0) -> void:
|
||||
var stream = stream_name
|
||||
var is_custom = false
|
||||
if stream_name is String:
|
||||
is_custom = sfx_library[stream_name].contains("user://custom_characters")
|
||||
is_custom = sfx_library[stream_name].contains(Global.config_path.path_join("custom_characters"))
|
||||
stream = import_stream(sfx_library[stream_name])
|
||||
if is_custom == false:
|
||||
player.stream = ResourceSetter.get_resource(stream, player)
|
||||
@@ -236,7 +236,7 @@ func handle_music_override() -> void:
|
||||
func create_stream_from_json(json_path := "") -> AudioStream:
|
||||
if json_path.contains(".json") == false:
|
||||
var path = ResourceSetter.get_pure_resource_path(json_path)
|
||||
if path.contains("user://"):
|
||||
if path.contains(Global.config_path):
|
||||
match json_path.get_slice(".", 1):
|
||||
"wav":
|
||||
return AudioStreamWAV.load_from_file(ResourceSetter.get_pure_resource_path(json_path))
|
||||
|
@@ -26,11 +26,13 @@ var second_quest := false
|
||||
var extra_worlds_win := false
|
||||
const lang_codes := ["en", "fr", "es", "de", "it", "pt", "pl", "tr", "ru", "jp", "fil", "id", "ga"]
|
||||
|
||||
var config_path : String = get_config_path()
|
||||
|
||||
var rom_path := ""
|
||||
var rom_assets_exist := false
|
||||
const ROM_POINTER_PATH := "user://rom_pointer.smb"
|
||||
const ROM_PATH := "user://baserom.nes"
|
||||
const ROM_ASSETS_PATH := "user://resource_packs/BaseAssets"
|
||||
var ROM_POINTER_PATH = config_path.path_join("rom_pointer.smb")
|
||||
var ROM_PATH = config_path.path_join("baserom.nes")
|
||||
var ROM_ASSETS_PATH = config_path.path_join("resource_packs/BaseAssets")
|
||||
const ROM_PACK_NAME := "BaseAssets"
|
||||
const ROM_ASSETS_VERSION := 0
|
||||
|
||||
@@ -169,8 +171,46 @@ func _ready() -> void:
|
||||
get_server_version()
|
||||
if OS.is_debug_build():
|
||||
debug_mode = false
|
||||
setup_config_dirs()
|
||||
check_for_rom()
|
||||
|
||||
func setup_config_dirs() -> void:
|
||||
var dirs = [
|
||||
"custom_characters",
|
||||
"custom_levels",
|
||||
"logs",
|
||||
"marathon_recordings",
|
||||
"resource_packs",
|
||||
"saves"
|
||||
]
|
||||
|
||||
for d in dirs:
|
||||
var full_path = Global.config_path.path_join(d)
|
||||
if not DirAccess.dir_exists_absolute(full_path):
|
||||
DirAccess.make_dir_recursive_absolute(full_path)
|
||||
|
||||
func get_config_path() -> String:
|
||||
var exe_path := OS.get_executable_path()
|
||||
var exe_dir := exe_path.get_base_dir()
|
||||
var portable_flag := exe_dir.path_join("portable.txt")
|
||||
|
||||
# Test that exe dir is writeable, if not fallback to user://
|
||||
if FileAccess.file_exists(portable_flag):
|
||||
var test_file = exe_dir.path_join("test.txt")
|
||||
var f = FileAccess.open(test_file, FileAccess.WRITE)
|
||||
if f:
|
||||
f.close()
|
||||
var dir = DirAccess.open(exe_dir)
|
||||
if dir:
|
||||
dir.remove(test_file.get_file())
|
||||
var local_dir = exe_dir.path_join("config")
|
||||
if not DirAccess.dir_exists_absolute(local_dir):
|
||||
DirAccess.make_dir_recursive_absolute(local_dir)
|
||||
return local_dir
|
||||
else:
|
||||
push_warning("Portable flag found but exe directory is not writeable. Falling back to user://")
|
||||
return "user://"
|
||||
|
||||
func check_for_rom() -> void:
|
||||
rom_path = ""
|
||||
rom_assets_exist = false
|
||||
@@ -330,7 +370,7 @@ func close_freeze() -> void:
|
||||
$Transition/Freeze.hide()
|
||||
$Transition.hide()
|
||||
|
||||
var recording_dir = "user://marathon_recordings/"
|
||||
var recording_dir = config_path.path_join("marathon_recordings")
|
||||
|
||||
func update_game_status() -> void:
|
||||
var lives_str := str(Global.lives)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
extends Node
|
||||
|
||||
const SAVE_DIR := "user://saves/CAMPAIGN.sav"
|
||||
var SAVE_DIR : String = Global.config_path.path_join("saves/CAMPAIGN.sav")
|
||||
|
||||
var visited_levels := "1000000000000000000000000000000010000000000000000000"
|
||||
|
||||
@@ -71,14 +71,10 @@ func write_save(campaign: String = Global.current_campaign, force := false) -> v
|
||||
if Global.debugged_in and not force:
|
||||
return
|
||||
var save = null
|
||||
DirAccess.make_dir_recursive_absolute("user://saves")
|
||||
DirAccess.make_dir_recursive_absolute("user://resource_packs")
|
||||
DirAccess.make_dir_recursive_absolute("user://custom_characters")
|
||||
DirAccess.make_dir_recursive_absolute("user://custom_levels")
|
||||
var save_json = {}
|
||||
var path = "user://saves/" + campaign + ".sav"
|
||||
var path = Global.config_path.path_join("saves/" + campaign + ".sav")
|
||||
if FileAccess.file_exists(path):
|
||||
save = FileAccess.open("user://saves/" + campaign + ".sav", FileAccess.READ)
|
||||
save = FileAccess.open(path, FileAccess.READ)
|
||||
save_json = JSON.parse_string(save.get_as_text())
|
||||
save.close()
|
||||
else:
|
||||
@@ -150,7 +146,8 @@ func clear_save() -> void:
|
||||
visited_levels[0][0] = "1"
|
||||
var save = SAVE_TEMPLATE.duplicate(true)
|
||||
apply_save(save)
|
||||
DirAccess.remove_absolute("user://saves/" + Global.current_campaign + ".sav")
|
||||
var save_path = Global.config_path.path_join("saves" + Global.current_campaign + ".sav")
|
||||
DirAccess.remove_absolute(save_path)
|
||||
write_save(Global.current_campaign)
|
||||
|
||||
func clear_array(arr := []) -> void:
|
||||
@@ -172,9 +169,10 @@ func get_level_idx(world_num := 1, level_num := 1) -> int:
|
||||
return ((world_num - 1) * 4) + (level_num - 1)
|
||||
|
||||
func load_achievements() -> void:
|
||||
if FileAccess.file_exists("user://achievements.sav") == false:
|
||||
var path = Global.config_path.path_join("achievements.sav")
|
||||
if FileAccess.file_exists(path) == false:
|
||||
write_achievements()
|
||||
var file = FileAccess.open("user://achievements.sav", FileAccess.READ)
|
||||
var file = FileAccess.open(path, FileAccess.READ)
|
||||
var idx := 0
|
||||
for i in file.get_as_text():
|
||||
Global.achievements[idx] = i
|
||||
@@ -183,6 +181,7 @@ func load_achievements() -> void:
|
||||
file.close()
|
||||
|
||||
func write_achievements() -> void:
|
||||
var file = FileAccess.open("user://achievements.sav", FileAccess.WRITE)
|
||||
var path = Global.config_path.path_join("achievements.sav")
|
||||
var file = FileAccess.open(path, FileAccess.WRITE)
|
||||
file.store_string(Global.achievements)
|
||||
file.close()
|
||||
|
@@ -79,10 +79,10 @@ var file := {
|
||||
}
|
||||
}
|
||||
|
||||
const SETTINGS_DIR := "user://settings.cfg"
|
||||
static var SETTINGS_DIR := Global.config_path.path_join("settings.cfg")
|
||||
|
||||
func _enter_tree() -> void:
|
||||
DirAccess.make_dir_absolute("user://resource_packs")
|
||||
DirAccess.make_dir_absolute(Global.config_path.path_join("resource_packs"))
|
||||
load_settings()
|
||||
await get_tree().physics_frame
|
||||
apply_settings()
|
||||
|
@@ -201,7 +201,7 @@ func gen_time_string(timer_dict := {}) -> String:
|
||||
|
||||
func save_recording() -> void:
|
||||
var recording := [timer, current_recording, levels, str(["Mario", "Luigi", "Toad", "Toadette"].find(get_tree().get_first_node_in_group("Players").character)), anim_list]
|
||||
var recording_dir = "user://marathon_recordings/" + Global.current_campaign
|
||||
var recording_dir = Global.config_path.path_join("marathon_recordings/" + Global.current_campaign)
|
||||
DirAccess.make_dir_recursive_absolute(recording_dir)
|
||||
var file = FileAccess.open(recording_dir + "/" + str(Global.world_num) + "-" + str(Global.level_num) + ("warp" if is_warp_run else "") + ".json", FileAccess.WRITE)
|
||||
file.store_string(compress_recording(JSON.stringify(recording, "", false, true)))
|
||||
@@ -240,7 +240,7 @@ func load_best_marathon() -> void:
|
||||
anim_list = recording[4].duplicate()
|
||||
|
||||
func load_recording(world_num := 0, level_num := 0, is_warpless := true, campaign := "SMB1") -> Array:
|
||||
var recording_dir = "user://marathon_recordings/" + campaign
|
||||
var recording_dir = Global.config_path.path_join("marathon_recordings/" + campaign)
|
||||
var path = recording_dir + "/" + str(world_num) + "-" + str(level_num) + ("" if is_warpless else "warp") + ".json"
|
||||
print(path)
|
||||
if FileAccess.file_exists(path) == false:
|
||||
@@ -257,12 +257,12 @@ func load_best_times(campaign = Global.current_campaign) -> void:
|
||||
best_level_any_times.clear()
|
||||
for world_num in 8:
|
||||
for level_num in 4:
|
||||
var path = "user://marathon_recordings/" + campaign + "/" + str(world_num + 1) + "-" + str(level_num + 1) + ".json"
|
||||
var path = Global.config_path.path_join("marathon_recordings/" + campaign + "/" + str(world_num + 1) + "-" + str(level_num + 1) + ".json")
|
||||
if FileAccess.file_exists(path):
|
||||
best_level_warpless_times[world_num][level_num] = load_recording(world_num + 1, level_num + 1, true, campaign)[0]
|
||||
else:
|
||||
best_level_warpless_times[world_num][level_num] = -1
|
||||
path = "user://marathon_recordings/" + campaign + "/" + str(world_num + 1) + "-" + str(level_num + 1) +"warp" + ".json"
|
||||
path = Global.config_path.path_join("marathon_recordings/" + campaign + "/" + str(world_num + 1) + "-" + str(level_num + 1) +"warp" + ".json")
|
||||
if FileAccess.file_exists(path):
|
||||
best_level_any_times[str(world_num + 1) + "-" + str(level_num + 1)] = load_recording(world_num + 1, level_num + 1, false, campaign)[0]
|
||||
check_for_medal_achievement()
|
||||
|
Reference in New Issue
Block a user