feat: implement loadout management system, interactive pause menu, and weapon slot switching functionality
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
})
|
||||
|
||||
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"]
|
||||
@@ -0,0 +1 @@
|
||||
uid://ck4n30620akl4
|
||||
Reference in New Issue
Block a user