PkmnLib_rs/src/dynamic_data/flow/choice_queue.rs

39 lines
1.0 KiB
Rust
Raw Normal View History

use crate::dynamic_data::choices::TurnChoice;
use crate::dynamic_data::models::pokemon::Pokemon;
use parking_lot::RwLock;
use std::sync::Arc;
2022-06-03 14:35:18 +00:00
#[derive(Debug)]
pub struct ChoiceQueue<'battle, 'library> {
queue: Vec<Arc<RwLock<TurnChoice<'battle, 'library>>>>,
current: usize,
}
impl<'battle, 'library> ChoiceQueue<'battle, 'library> {
pub fn new(queue: Vec<Arc<RwLock<TurnChoice<'battle, 'library>>>>) -> Self {
Self { queue, current: 0 }
}
pub fn dequeue<'b>(&'b mut self) -> &'b Arc<RwLock<TurnChoice<'battle, 'library>>> {
let c = &self.queue[self.current];
self.current += 1;
c
}
pub fn peek(&mut self) -> &'battle Arc<RwLock<TurnChoice>> {
&self.queue[self.current]
}
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) -> &Vec<Arc<RwLock<TurnChoice<'battle, 'library>>>> {
&self.queue
}
}