fixed a bug where you couldnt have two config resource packs loaded at once

This commit is contained in:
JHDev2006
2025-09-26 12:36:34 +01:00
parent 40c2c04fcd
commit 3ecb8c34f5

View File

@@ -28,6 +28,8 @@ var is_random := false
signal updated
var current_resource_pack := ""
@export var force_properties := {}
var update_on_spawn := true
@@ -70,8 +72,12 @@ func get_resource(json_file: JSON) -> Resource:
var resource: Resource = null
var resource_path = json_file.resource_path
config_to_use = {}
current_resource_pack = ""
for i in Settings.file.visuals.resource_packs:
resource_path = get_resource_pack_path(resource_path, i)
var new_path = get_resource_pack_path(resource_path, i)
if resource_path != new_path or current_resource_pack == "":
current_resource_pack = i
resource_path = new_path
var source_json = JSON.parse_string(FileAccess.open(resource_path, FileAccess.READ).get_as_text())
if source_json == null:
@@ -85,7 +91,6 @@ func get_resource(json_file: JSON) -> Resource:
if json.get("source") is String:
source_resource_path = json_file.resource_path.replace(json_file.resource_path.get_file(), json.source)
else:
print(json)
Global.log_error("Error getting variations! " + resource_path)
return
for i in Settings.file.visuals.resource_packs:
@@ -136,7 +141,6 @@ func get_resource(json_file: JSON) -> Resource:
var idx := 0
for i in json.get("source"):
var frame_path = ResourceSetter.get_pure_resource_path(json_file.resource_path.replace(json_file.resource_path.get_file(), i))
print(frame_path)
resource.set_frame_texture(idx, load_image_from_path(frame_path))
idx += 1
else:
@@ -172,6 +176,7 @@ func get_variation_json(json := {}) -> Dictionary:
level_theme = force_properties.Theme
for i in json.keys().filter(func(key): return key.contains("config:")):
get_config_file(current_resource_pack)
if config_to_use != {}:
var option_name = i.get_slice(":", 1)
if config_to_use.options.has(option_name):
@@ -261,15 +266,19 @@ func get_variation_json(json := {}) -> Dictionary:
return json
func get_config_file(resource_pack := "") -> void:
if FileAccess.file_exists("user://resource_packs/" + resource_pack + "/config.json"):
config_to_use = JSON.parse_string(FileAccess.open("user://resource_packs/" + resource_pack + "/config.json", FileAccess.READ).get_as_text())
if config_to_use == null:
Global.log_error("Error parsing Config File! (" + resource_pack + ")")
config_to_use = {}
else:
print("resource pack to use: " + resource_pack)
func get_resource_pack_path(res_path := "", resource_pack := "") -> String:
var user_path := res_path.replace("res://Assets", "user://resource_packs/" + resource_pack)
user_path = user_path.replace("user://custom_characters/", "user://resource_packs/" + resource_pack + "/Sprites/Players/CustomCharacters/")
if FileAccess.file_exists(user_path):
if FileAccess.file_exists("user://resource_packs/" + resource_pack + "/config.json"):
config_to_use = JSON.parse_string(FileAccess.open("user://resource_packs/" + resource_pack + "/config.json", FileAccess.READ).get_as_text())
if config_to_use == null:
Global.log_error("Error parsing Config File! (" + resource_pack + ")")
config_to_use = {}
return user_path
else:
return res_path