32 lines
752 B
GDScript
32 lines
752 B
GDScript
extends Node2D
|
|
|
|
# TODO: implement add_weapon
|
|
|
|
## Shortcut to get_parent()
|
|
@onready var ship: Ship = get_parent()
|
|
## List of weapons
|
|
@onready var list: Array[Node] = get_children()
|
|
|
|
## Updates list with actual children of this node
|
|
func update_weapon_list() -> void:
|
|
list = get_children()
|
|
|
|
## Removes weapon with given ID
|
|
func remove_weapon(id: String) -> void:
|
|
for weapon in list:
|
|
if weapon.id == id:
|
|
list.erase(weapon)
|
|
weapon.free()
|
|
break
|
|
update_weapon_list()
|
|
|
|
## Adds weapon with given ID to list
|
|
func add_weapon(_id: String) -> void:
|
|
pass
|
|
|
|
## Returns a reference to weapon with given id if it exists, otherwise returns null
|
|
func get_weapon(id: String) -> Node:
|
|
for weapon in list:
|
|
if weapon.id == id:
|
|
return weapon
|
|
return null
|