Spread state context architecture (Fixes #18) (#30)
CI / build-and-test (push) Canceled after 0s

Reviewed-on: #30
Co-authored-by: Álex Román Núñez <eirexe@eirteam.moe>
This commit was merged in pull request #30.
This commit is contained in:
2026-09-15 17:59:03 +00:00
committed by EIREXE
parent 43a04e9491
commit b8b65e60e9
15 changed files with 384 additions and 302 deletions
+10 -10
View File
@@ -1,6 +1,9 @@
use crate::fighter::{
attack::{AttackKind, update_active_hitbox_list},
state::{FighterState, FighterStateImpl, ground::GroundedStateCommon, wait::WaitState},
state::{
CollisionContext, EnterContext, ExitContext, FighterState, FighterStateImpl,
InterruptContext, UpdateContext, ground::GroundedStateCommon, wait::WaitState,
},
};
#[derive(Clone, Debug, Hash)]
@@ -12,10 +15,7 @@ pub struct GroundAttackState {
impl FighterStateImpl for GroundAttackState {
const NAME: &'static str = "GroundAttack";
fn check_interrupt(
&self,
state_context: &mut super::FighterStateContext,
) -> Option<FighterState> {
fn check_interrupt(&self, state_context: &mut InterruptContext) -> Option<FighterState> {
if state_context.is_current_animation_finished() {
Some(FighterState::Wait(WaitState {
grounded_common: self.grounded_common.clone(),
@@ -25,7 +25,7 @@ impl FighterStateImpl for GroundAttackState {
}
}
fn update(&mut self, state_context: &mut super::FighterStateContext) {
fn update(&mut self, state_context: &mut UpdateContext) {
let animation_frame = state_context.get_current_animation_frame();
let script = state_context
.attack_scripts
@@ -44,7 +44,7 @@ impl FighterStateImpl for GroundAttackState {
}
}
fn on_enter(&mut self, state_context: &mut super::FighterStateContext) {
fn on_enter(&mut self, state_context: &mut EnterContext) {
state_context.play_animation(self.attack_kind.get_animation(), false);
let script = state_context.attack_script_assets.scripts[&self.attack_kind].clone();
state_context.stale_move_queue.push(self.attack_kind);
@@ -57,20 +57,20 @@ impl FighterStateImpl for GroundAttackState {
});
}
fn on_exit(&mut self, state_context: &mut super::FighterStateContext) {
fn on_exit(&mut self, state_context: &mut ExitContext) {
state_context.hitboxes.0 = None;
}
fn check_collision_interrupt(
&mut self,
_state_context: &mut super::FighterStateContext,
_state_context: &mut CollisionContext,
) -> Option<FighterState> {
None
}
}
pub fn check_interrupt(
state_context: &super::FighterStateContext,
state_context: &InterruptContext,
grounded_common: &GroundedStateCommon,
) -> Option<FighterState> {
if state_context