This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::dynamic_data::choices::TurnChoice;
|
||||
use crate::dynamic_data::script_handling::ScriptSource;
|
||||
use crate::dynamic_data::Pokemon;
|
||||
use crate::{script_hook, ValueIdentifiable};
|
||||
use crate::{script_hook, ValueIdentifiable, ValueIdentifier};
|
||||
use parking_lot::lock_api::MappedRwLockReadGuard;
|
||||
use parking_lot::{RawRwLock, RwLock, RwLockReadGuard};
|
||||
|
||||
@@ -12,8 +12,10 @@ use parking_lot::{RawRwLock, RwLock, RwLockReadGuard};
|
||||
/// helper functions to change the turn order while doing the execution. This is needed, as several
|
||||
/// moves in Pokemon actively mess with this order.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
|
||||
pub struct ChoiceQueue {
|
||||
/// A unique identifier so we know what value this is.
|
||||
identifier: ValueIdentifier,
|
||||
/// Our storage of turn choices. Starts out completely filled, then slowly empties as turns get
|
||||
/// executed.
|
||||
queue: RwLock<Vec<Option<TurnChoice>>>,
|
||||
@@ -26,6 +28,7 @@ impl ChoiceQueue {
|
||||
pub(crate) fn new(mut queue: Vec<Option<TurnChoice>>) -> Self {
|
||||
queue.sort_unstable_by(|a, b| b.cmp(a));
|
||||
Self {
|
||||
identifier: Default::default(),
|
||||
queue: RwLock::new(queue),
|
||||
current: 0,
|
||||
}
|
||||
@@ -119,6 +122,12 @@ impl ChoiceQueue {
|
||||
}
|
||||
}
|
||||
|
||||
impl ValueIdentifiable for ChoiceQueue {
|
||||
fn value_identifier(&self) -> ValueIdentifier {
|
||||
self.identifier
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user