use glam::Vec3;
use num_traits::FloatConst;
use rand::Rng;
use winit::keyboard::KeyCode;

use super::{
  anm::{Vm, VmLocation}, GameInitContext, GameState
};

pub struct LoadingState {
  sig: Vm,
  ascii_loading: Vm,
}

impl LoadingState {
  pub fn new(context: &mut GameInitContext) -> LoadingState {
    let ascii = context.anm_manager.load_anm(
      &context.engine.device,
      &context.engine.queue,
      &context.engine.window,
      "ascii.anm",
    );
    let sig_anm = context.anm_manager.load_anm(
      &context.engine.device,
      &context.engine.queue,
      &context.engine.window,
      "sig.anm",
    );
    let sig = context.anm_manager.new_vm(sig_anm, None, false, 0, VmLocation::new_ui());
    let ascii_loading = context.anm_manager.new_vm(
      ascii,
      Some(Vec3::new(480.0, 392.0, 0.0)),
      false,
      18,
      VmLocation::new_ui(),
    );

    LoadingState { sig, ascii_loading }
  }
}

impl GameState for LoadingState {
  fn update(&mut self, _context: &super::GameUpdateContext) {
    if _context.engine.keys.was_key_pressed(KeyCode::Space) {
      println!(
        "{}",
        rand::thread_rng().gen_range((-f32::PI() as i32)..(f32::PI() as i32))
      )
    }
  }
}
