// src/game/state.cpp
#include "state.h"

void WalkingState::update() {
  // stop crawling after duration
  if (current_state == PlayerState::Crawl1 &&
      state_timer.elapsed_time() >= CRAWL_DURATION) {
    current_state = PlayerState::Walk1;
    state_timer.stop();
  }
}

void WalkingState::start_crawl() {
  current_state = PlayerState::Crawl1;
  state_timer.reset();
  state_timer.start();
}

void WalkingState::toggle_walk_frame() {
  if (current_state == PlayerState::Walk1) {
    current_state = PlayerState::Walk2;
  } else if (current_state == PlayerState::Walk2) {
    current_state = PlayerState::Walk1;
  }
}

CharacterFrame WalkingState::get_character_frame() const {
  switch (current_state) {
  case PlayerState::Walk1:
    return CharacterFrame::Walk1;
  case PlayerState::Walk2:
    return CharacterFrame::Walk2;
  case PlayerState::Crawl1:
    return CharacterFrame::Crawl1;
  default:
    return CharacterFrame::Walk1;
  }
}
