mirror of
https://github.com/JHDev2006/Super-Mario-Bros.-Remastered-Public.git
synced 2025-10-22 23:48:11 +00:00
Add true portable mode (#259)
This commit is contained in:
@@ -34,10 +34,9 @@ func save_level(level_name := "Unnamed Level", level_author := "You", level_desc
|
||||
return level_file
|
||||
|
||||
func write_file(json := {}, lvl_file_name := "") -> void:
|
||||
DirAccess.make_dir_absolute(LevelEditor.CUSTOM_LEVEL_DIR)
|
||||
for i in "<>:?!/":
|
||||
lvl_file_name = lvl_file_name.replace(i, "")
|
||||
var file = FileAccess.open(LevelEditor.CUSTOM_LEVEL_DIR + lvl_file_name, FileAccess.WRITE)
|
||||
var file = FileAccess.open(Global.config_path.path_join("custom_levels/" + lvl_file_name), FileAccess.WRITE)
|
||||
file.store_string(JSON.stringify(json, "", false))
|
||||
file.close()
|
||||
print("saved")
|
||||
|
@@ -24,7 +24,7 @@ func update() -> void:
|
||||
if resource_setter != null:
|
||||
var path = "res://Assets/Sprites/Players/" + character + "/" + Player.POWER_STATES[int(power_state)] + ".json"
|
||||
if Player.CHARACTERS.find(character) > 3:
|
||||
path = path.replace("res://Assets/Sprites/Players/", "user://custom_characters/")
|
||||
path = path.replace("res://Assets/Sprites/Players/", Global.config_path.path_join("custom_characters/"))
|
||||
var json = resource_setter.get_resource(load(path))
|
||||
sprite_frames = json
|
||||
if sprite_frames == null:
|
||||
|
@@ -9,7 +9,7 @@ func _ready() -> void:
|
||||
get_resource_packs()
|
||||
|
||||
func open_folder() -> void:
|
||||
OS.shell_show_in_file_manager(ProjectSettings.globalize_path("user://resource_packs"), true)
|
||||
OS.shell_show_in_file_manager(ProjectSettings.globalize_path(Global.config_path.path_join("resource_packs")), true)
|
||||
|
||||
func get_resource_packs() -> void:
|
||||
for i in containers:
|
||||
@@ -17,12 +17,12 @@ func get_resource_packs() -> void:
|
||||
i.queue_free()
|
||||
containers = []
|
||||
resource_packs = []
|
||||
for i in DirAccess.get_directories_at("user://resource_packs"):
|
||||
for i in DirAccess.get_directories_at(Global.config_path.path_join("resource_packs")):
|
||||
resource_packs.append(i)
|
||||
for i in resource_packs:
|
||||
var pack_info_path = "user://resource_packs/" + i + "/" + "pack_info.json"
|
||||
var pack_info_path = Global.config_path.path_join("resource_packs/" + i + "/pack_info.json")
|
||||
if FileAccess.file_exists(pack_info_path) and i != Global.ROM_PACK_NAME:
|
||||
create_container("user://resource_packs/" + i)
|
||||
create_container(Global.config_path.path_join("resource_packs/" + i))
|
||||
|
||||
func create_container(resource_pack := "") -> void:
|
||||
var container = RESOURCE_PACK_CONTAINER.instantiate()
|
||||
@@ -36,7 +36,7 @@ func create_container(resource_pack := "") -> void:
|
||||
container.icon = ImageTexture.create_from_image(image)
|
||||
elif FileAccess.file_exists(resource_pack + "/icon.gif"):
|
||||
container.icon = GifManager.animated_texture_from_file(resource_pack + "/icon.gif")
|
||||
container.pack_name = resource_pack.replace("user://resource_packs/", "")
|
||||
container.pack_name = resource_pack.replace(Global.config_path.path_join("resource_packs"), "")
|
||||
$"../ScrollContainer/VBoxContainer".add_child(container)
|
||||
containers.append(container)
|
||||
container.add_to_group("Options")
|
||||
|
@@ -12,15 +12,15 @@ const base_info_json := {
|
||||
func create_template() -> void:
|
||||
get_directories("res://Assets", files, directories)
|
||||
for i in directories:
|
||||
DirAccess.make_dir_recursive_absolute(i.replace("res://Assets", "user://resource_packs/new_pack"))
|
||||
DirAccess.make_dir_recursive_absolute(i.replace("res://Assets", Global.config_path.path_join("resource_packs/new_pack")))
|
||||
for i in files:
|
||||
var destination = i
|
||||
if destination.contains("res://"):
|
||||
destination = i.replace("res://Assets", "user://resource_packs/new_pack")
|
||||
destination = i.replace("res://Assets", Global.config_path.path_join("resource_packs/new_pack"))
|
||||
else:
|
||||
destination = i.replace("user://resource_packs/BaseAssets", "user://resource_packs/new_pack")
|
||||
destination = i.replace(Global.config_path.path_join("resource_packs/BaseAssets"), Global.config_path.path_join("resource_packs/new_pack"))
|
||||
print("Copying '" + i + "' to: '" + destination)
|
||||
if i.contains(".bgm") or i.contains(".json") or i.contains("user://"):
|
||||
if i.contains(".bgm") or i.contains(".json") or i.contains(Global.config_path):
|
||||
DirAccess.copy_absolute(i, destination)
|
||||
else:
|
||||
var resource = load(i)
|
||||
@@ -33,7 +33,9 @@ func create_template() -> void:
|
||||
file.store_buffer(resource.data)
|
||||
file.close()
|
||||
|
||||
var file = FileAccess.open("user://resource_packs/new_pack/pack_info.json", FileAccess.WRITE)
|
||||
var pack_info_path = Global.config_path.path_join("resource_packs/new_pack/pack_info.json")
|
||||
DirAccess.make_dir_recursive_absolute(pack_info_path.get_base_dir())
|
||||
var file = FileAccess.open(pack_info_path, FileAccess.WRITE)
|
||||
file.store_string(JSON.stringify(base_info_json, "\t"))
|
||||
file.close()
|
||||
print("Done")
|
||||
@@ -51,7 +53,7 @@ func get_files(base_dir := "", files := []) -> void:
|
||||
i = i.replace(".import", "")
|
||||
print(i)
|
||||
var target_path = base_dir + "/" + i
|
||||
var rom_assets_path = target_path.replace("res://Assets", "user://resource_packs/BaseAssets")
|
||||
var rom_assets_path = target_path.replace("res://Assets", Global.config_path.path_join("resource_packs/BaseAssets"))
|
||||
if FileAccess.file_exists(rom_assets_path):
|
||||
files.append(rom_assets_path)
|
||||
else:
|
||||
|
Reference in New Issue
Block a user