extends Node const SAVE_PATH = "user://loadouts.json" var weapon_db = { "none": { "name": "None", "category": "none", "script": "" }, "double_barrel_shotgun": { "name": "Double Barrel Shotgun", "category": "primary", "script": "res://weapons/double_barrel_shotgun.gd" }, "ak47": { "name": "AK-47", "category": "primary", "script": "res://weapons/ak47.gd" }, "m4": { "name": "M4", "category": "primary", "script": "res://weapons/m4.gd" }, "mp7": { "name": "MP7", "category": "primary", "script": "res://weapons/mp7.gd" }, "dmr": { "name": "DMR", "category": "primary", "script": "res://weapons/dmr.gd" }, "plasma_gun": { "name": "Plasma Gun", "category": "primary", "script": "res://weapons/plasma_gun.gd" }, "nail_gun": { "name": "Nail Gun", "category": "primary", "script": "res://weapons/nail_gun.gd" }, "awp": { "name": "AWP", "category": "special", "script": "res://weapons/awp.gd" }, "rocket_launcher": { "name": "Rocket Launcher", "category": "special", "script": "res://weapons/rocket_launcher.gd" }, "rocket_swarm": { "name": "Rocket Swarm", "category": "special", "script": "res://weapons/rocket_swarm.gd" }, "mortar": { "name": "Mortar", "category": "special", "script": "res://weapons/mortar.gd" }, "knife": { "name": "Knife", "category": "melee", "script": "res://weapons/knife.gd" } } var active_loadout_index: int = 0 var loadouts: Array = [] func _ready() -> void: _ensure_default_loadouts() load_loadouts() func _ensure_default_loadouts() -> void: loadouts.clear() for i in range(5): loadouts.append({ "name": "Loadout " + str(i + 1), "primary_1": "double_barrel_shotgun", "primary_2": "none", "special": "none", "melee": "knife" }) func get_active_loadout() -> Dictionary: if active_loadout_index >= 0 and active_loadout_index < loadouts.size(): return loadouts[active_loadout_index] return loadouts[0] func save_loadouts() -> void: var save_data = { "active_index": active_loadout_index, "loadouts": loadouts } var json_string = JSON.stringify(save_data) var file = FileAccess.open(SAVE_PATH, FileAccess.WRITE) if file: file.store_string(json_string) file.close() func load_loadouts() -> void: if FileAccess.file_exists(SAVE_PATH): var file = FileAccess.open(SAVE_PATH, FileAccess.READ) if file: var json_string = file.get_as_text() file.close() var json = JSON.new() var error = json.parse(json_string) if error == OK: var data = json.get_data() if data is Dictionary: if data.has("active_index"): active_loadout_index = data["active_index"] if data.has("loadouts") and data["loadouts"] is Array: var saved_loadouts = data["loadouts"] # Overwrite defaults, up to 5 for i in range(min(5, saved_loadouts.size())): var sl = saved_loadouts[i] if sl is Dictionary: if sl.has("name"): loadouts[i]["name"] = sl["name"] 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"] if sl.has("melee"): loadouts[i]["melee"] = sl["melee"]