## WeaponDefinitions — Central registry of all weapon definitions. ## ## Provides a WEAPONS dictionary keyed by weapon_id for runtime lookup, ## plus a convenience getter. The data itself lives in WeaponData constants, ## so this file serves as a single import point for the full arsenal. ## ## Usage (as autoload singleton or direct preload): ## var data = WeaponDefinitions.get_weapon("rifle") ## # or: ## var all = WeaponDefinitions.WEAPONS ## extends RefCounted class_name WeaponDefinitions # Preload WeaponData script directly (no class_name dependency — the server # weapon_data.gd intentionally avoids class_name to avoid conflicts with # client/weapons/data/weapon_data.gd which also registers WeaponData). const _WD = preload("res://scripts/combat/weapon_data.gd") # --------------------------------------------------------------------------- # Weapon Registry — lazily initialised to avoid const + .new() errors # --------------------------------------------------------------------------- ## Whether the WEAPONS dictionary has been populated. static var _initialized: bool = false ## All weapons indexed by weapon_id — the single source of truth for the ## game's starter arsenal. Populated on first access via _ensure_init(). static var WEAPONS: Dictionary = {} static func _ensure_init() -> void: if _initialized: return _initialized = true WEAPONS = { "rifle": _WD.make("rifle", "Assault Rifle", 30.0, 10.0, 30, 2.1, true, 0.5, 200.0, 1), "pistol": _WD.make("pistol", "Pistol", 25.0, 4.0, 12, 1.5, false, 0.3, 80.0, 1), "shotgun": _WD.make("shotgun","Shotgun", 8.0, 1.0, 8, 3.0, false, 3.0, 30.0, 8), "smg": _WD.make("smg", "Submachine Gun", 18.0, 12.0, 25, 1.8, true, 1.5, 100.0, 1), } # --------------------------------------------------------------------------- # Lookup # --------------------------------------------------------------------------- ## Return the WeaponData for the given weapon_id, or null if unknown. static func get_weapon(id: String): _ensure_init() return WEAPONS.get(id, null)