Rewriting ships: Added weapon base and changed hull parent to Node

This commit is contained in:
2ndbeam 2024-04-29 12:08:13 +03:00
commit 6957169ba5
13 changed files with 121 additions and 37 deletions

View file

@ -3,23 +3,30 @@ extends Node2D
# TODO: implement add_weapon
## Shortcut to get_parent()
@onready var ship = get_parent()
@onready var ship: Ship = get_parent()
## List of weapons
var list: Array[Weapon] = get_children() as Array[Weapon]
@onready var list: Array[Node] = get_children() as Array[Node]
## Updates list with actual children of this node
func update_weapon_list() -> void:
list = get_children() as Array[Weapon]
list = get_children() as Array[Node]
## Removes weapon with given ID and returns true if successful
func remove_weapon(id: String) -> bool:
## Removes weapon with given ID
func remove_weapon(id: String) -> void:
for weapon in list:
if weapon.id == id:
list.erase(weapon)
weapon.free()
return true
return false
break
update_weapon_list()
## Adds weapon with given ID to list
func add_weapon(id: String) -> void:
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) -> Weapon:
for weapon in list:
if weapon.id == id:
return weapon as Weapon
return null