feat: weapon swapping

This commit is contained in:
Sara 2025-08-11 16:49:49 +02:00
parent 6b7a092961
commit 7a13823c97
6 changed files with 44 additions and 18 deletions

View file

@ -102,10 +102,6 @@ void Rifle::on_animation_changed(String new_animation) {
void Rifle::ready() {
this->muzzle = cast_to<HitscanMuzzle>(get_node(NodePath("%HitscanMuzzle")));
get_anim()->connect("current_animation_changed", callable_mp(this, &self_type::on_animation_changed));
get_input()->connect(PlayerInput::sig_primary_fire, callable_mp(this, &self_type::on_primary_fire));
get_input()->connect(PlayerInput::sig_alt_mode, callable_mp(this, &self_type::on_alt_mode));
get_input()->connect(PlayerInput::sig_reload, callable_mp(this, &self_type::on_reload));
play_equip_anim();
}
void Rifle::process(double delta) {
@ -173,6 +169,11 @@ PackedStringArray Rifle::get_configuration_warnings() const {
return warnings;
}
bool Rifle::allows_swapping() const {
String const current{ get_anim()->get_current_animation() };
return !this->in_alt_mode && (current == "reload" || !is_animating());
}
bool Rifle::allows_running() const {
String const animation{ get_anim()->get_current_animation() };
return animation == "run" && !this->request_alt_mode;
@ -183,9 +184,18 @@ bool Rifle::run_requested() const {
}
void Rifle::notify_selected() {
get_input()->connect(PlayerInput::sig_primary_fire, callable_mp(this, &self_type::on_primary_fire));
get_input()->connect(PlayerInput::sig_alt_mode, callable_mp(this, &self_type::on_alt_mode));
get_input()->connect(PlayerInput::sig_reload, callable_mp(this, &self_type::on_reload));
play_equip_anim();
}
void Rifle::notify_deselected() {
get_input()->disconnect(PlayerInput::sig_primary_fire, callable_mp(this, &self_type::on_primary_fire));
get_input()->disconnect(PlayerInput::sig_alt_mode, callable_mp(this, &self_type::on_alt_mode));
get_input()->disconnect(PlayerInput::sig_reload, callable_mp(this, &self_type::on_reload));
}
void Rifle::reload_full() {
int const available = get_inventory()->withdraw_rifle_ammo(get_max_ammo());
reload_num(available);