PkmnLib_rs/src/dynamic_data/flow/choice_queue.rs

37 lines
1013 B
Rust
Raw Normal View History

use crate::dynamic_data::choices::TurnChoice;
use crate::dynamic_data::models::pokemon::Pokemon;
2022-06-03 14:35:18 +00:00
#[derive(Debug)]
pub struct ChoiceQueue<'battle, 'library> {
queue: Vec<Option<TurnChoice<'battle, 'library>>>,
current: usize,
}
impl<'battle, 'library> ChoiceQueue<'battle, 'library> {
pub fn new(queue: Vec<Option<TurnChoice<'battle, 'library>>>) -> Self {
Self { queue, current: 0 }
}
pub fn dequeue<'b>(&'b mut self) -> TurnChoice<'battle, 'library> {
let c = self.queue[self.current].take();
self.current += 1;
c.unwrap()
}
pub fn peek(&mut self) -> &'battle TurnChoice {
self.queue[self.current].as_ref().unwrap()
}
pub fn has_next(&self) -> bool {
self.current < self.queue.len()
}
pub fn move_pokemon_choice_next(&mut self, _pokemon: &Pokemon) {
todo!()
}
pub(crate) fn get_queue(&self) -> &[Option<TurnChoice<'battle, 'library>>] {
&self.queue[self.current..self.queue.len()]
}
}