ani
This commit is contained in:
@@ -73,6 +73,7 @@ var weapon_db = {
|
||||
var active_loadout_index: int = 0
|
||||
|
||||
var loadouts: Array = []
|
||||
var _legacy_skin_indices: Array[int] = []
|
||||
|
||||
func _ready() -> void:
|
||||
_ensure_default_loadouts()
|
||||
@@ -83,6 +84,7 @@ func _ensure_default_loadouts() -> void:
|
||||
for i in range(5):
|
||||
loadouts.append({
|
||||
"name": "Loadout " + str(i + 1),
|
||||
"skin": "default",
|
||||
"primary_1": "double_barrel_shotgun",
|
||||
"primary_2": "none",
|
||||
"special": "none",
|
||||
@@ -94,6 +96,32 @@ func get_active_loadout() -> Dictionary:
|
||||
return loadouts[active_loadout_index]
|
||||
return loadouts[0]
|
||||
|
||||
|
||||
func get_active_skin_id() -> String:
|
||||
return str(get_active_loadout().get("skin", "default"))
|
||||
|
||||
|
||||
func set_active_loadout(index: int) -> bool:
|
||||
if index < 0 or index >= loadouts.size():
|
||||
return false
|
||||
active_loadout_index = index
|
||||
save_loadouts()
|
||||
return true
|
||||
|
||||
|
||||
## Older saves stored character choice in SkinManager's separate config. Copy
|
||||
## that choice into every legacy loadout once, then the loadout becomes the
|
||||
## authoritative place for both equipment and character.
|
||||
func migrate_legacy_skin(skin_id: String) -> void:
|
||||
if _legacy_skin_indices.is_empty():
|
||||
return
|
||||
var migrated := skin_id if not skin_id.is_empty() else "default"
|
||||
for index in _legacy_skin_indices:
|
||||
if index >= 0 and index < loadouts.size():
|
||||
loadouts[index]["skin"] = migrated
|
||||
_legacy_skin_indices.clear()
|
||||
save_loadouts()
|
||||
|
||||
func save_loadouts() -> void:
|
||||
var save_data = {
|
||||
"active_index": active_loadout_index,
|
||||
@@ -106,6 +134,7 @@ func save_loadouts() -> void:
|
||||
file.close()
|
||||
|
||||
func load_loadouts() -> void:
|
||||
_legacy_skin_indices.clear()
|
||||
if FileAccess.file_exists(SAVE_PATH):
|
||||
var file = FileAccess.open(SAVE_PATH, FileAccess.READ)
|
||||
if file:
|
||||
@@ -126,6 +155,10 @@ func load_loadouts() -> void:
|
||||
var sl = saved_loadouts[i]
|
||||
if sl is Dictionary:
|
||||
if sl.has("name"): loadouts[i]["name"] = sl["name"]
|
||||
if sl.has("skin"):
|
||||
loadouts[i]["skin"] = sl["skin"]
|
||||
else:
|
||||
_legacy_skin_indices.append(i)
|
||||
if sl.has("primary_1"): loadouts[i]["primary_1"] = sl["primary_1"]
|
||||
if sl.has("primary_2"): loadouts[i]["primary_2"] = sl["primary_2"]
|
||||
if sl.has("special"): loadouts[i]["special"] = sl["special"]
|
||||
|
||||
Reference in New Issue
Block a user