extends Node2D class_name Ship # TODO: add weapons ## Emits when hull hp reaches zero. signal destroyed ## Reference to the engine module @onready var engine: ShipEngine = $Engine ## Reference to the hull module @onready var hull: Hull = $Hull ## Reference to the shield module @onready var shield: Shield = $Shield ## Reference to primary weapon #@onready var primary_weapon: Weapon = $PrimaryWeapon ## Reference to secondary weapon #@onready var secondary_weapon: Weapon = $SecondaryWeapon ## Faction which this ship belongs to var faction : Game.Faction = Game.Faction.Player func _ready(): #shield.material = material destroyed.connect(destroy) ## Reset all required variables func destroy(): hull.hp = hull.max_hp shield.capacity = shield.max_capacity ## Swaps old hull with the new one func change_hull(new_hull_id: String): var new_hull: Hull = Game.get_module(new_hull_id, 'hull').instantiate() var old_hull: Hull = hull add_child(new_hull) hull = new_hull hull.hp = old_hull.hp get_tree().create_timer(0.05).timeout.connect(old_hull.queue_free) ## Swaps old engine with the new one func change_engine(new_engine_id: String): var new_engine: ShipEngine = Game.get_module(new_engine_id, 'engine').instantiate() var old_engine: ShipEngine = engine add_child(new_engine) engine = new_engine get_tree().create_timer(0.05).timeout.connect(old_engine.queue_free) ## Swaps old shield with the new one func change_shield(new_shield_id: String): var new_shield: Shield = Game.get_module(new_shield_id, 'shield').instantiate() var old_shield: Shield = shield add_child(new_shield) shield = new_shield get_tree().create_timer(0.05).timeout.connect(old_shield.queue_free)