Files
tactical-shooter/scripts/combat/weapon_definitions.gd
T
shawn e70ce76207 P7.9: fix headless export — resolve Resource class_name ordering + duplicate RoundManager + simulation stub API
- Fix dead code in server_main.gd (unreachable lag compensation print)
- Remove WeaponData type hints from weapon_server.gd (Resource class_name in Node scripts = headless fail)
- Use preload() instead of WeaponData class_name in weapon_definitions.gd for const refs
- Lazy-init WEAPONS dict (const can't reference preload members)
- Remove duplicate class_name RoundManager from server/scripts/round/round_manager.gd
- Remove DamageProcessor type hints from round/round_manager.gd and bomb_objective.gd
- Add start()/stop()/can_tick()/tick()/spawn_entity()/despawn_entity() to simulation_server_stub.gd
- Fix get_world_3d() → get_tree().root.world_3d in weapon_server.gd Node context
- Fix var data := → var data = for untyped WeaponDefinitions.get_weapon() returns
- Clean export cache and verify server starts with zero parse errors
2026-07-02 17:57:09 -04:00

50 lines
1.8 KiB
GDScript

## 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.RIFLE,
"pistol": _WD.PISTOL,
"shotgun": _WD.SHOTGUN,
"smg": _WD.SMG,
}
# ---------------------------------------------------------------------------
# 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)