Don't store the ChoiceQueue as an Arc<RwLock> to prevent locking issues.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -3,23 +3,23 @@ use crate::dynamic_data::models::pokemon::Pokemon;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ChoiceQueue<'battle, 'library> {
|
||||
queue: Vec<TurnChoice<'battle, 'library>>,
|
||||
queue: Vec<Option<TurnChoice<'battle, 'library>>>,
|
||||
current: usize,
|
||||
}
|
||||
|
||||
impl<'battle, 'library> ChoiceQueue<'battle, 'library> {
|
||||
pub fn new(queue: Vec<TurnChoice<'battle, 'library>>) -> Self {
|
||||
pub fn new(queue: Vec<Option<TurnChoice<'battle, 'library>>>) -> Self {
|
||||
Self { queue, current: 0 }
|
||||
}
|
||||
|
||||
pub fn dequeue<'b>(&'b mut self) -> &'b TurnChoice<'battle, 'library> {
|
||||
let c = &self.queue[self.current];
|
||||
pub fn dequeue<'b>(&'b mut self) -> TurnChoice<'battle, 'library> {
|
||||
let c = self.queue[self.current].take();
|
||||
self.current += 1;
|
||||
c
|
||||
c.unwrap()
|
||||
}
|
||||
|
||||
pub fn peek(&mut self) -> &'battle TurnChoice {
|
||||
&self.queue[self.current]
|
||||
&self.queue[self.current].as_ref().unwrap()
|
||||
}
|
||||
|
||||
pub fn has_next(&self) -> bool {
|
||||
@@ -30,7 +30,7 @@ impl<'battle, 'library> ChoiceQueue<'battle, 'library> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub(crate) fn get_queue(&self) -> &Vec<TurnChoice<'battle, 'library>> {
|
||||
&self.queue
|
||||
pub(crate) fn get_queue(&self) -> &[Option<TurnChoice<'battle, 'library>>] {
|
||||
&self.queue[self.current..self.queue.len()]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user