Remove lifetime mess, replace a lot of code with Arc instead of borrows.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This cleans up the codebase massively, and allows me to maintain some semblance of sanity.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use std::sync::atomic::{AtomicU8, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::static_data::MoveData;
|
||||
|
||||
@@ -6,9 +7,9 @@ use crate::static_data::MoveData;
|
||||
/// such as the remaining amount of users, how it has been learned, etc.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
pub struct LearnedMove<'library> {
|
||||
pub struct LearnedMove {
|
||||
/// The immutable move information of the move.
|
||||
move_data: &'library MoveData,
|
||||
move_data: Arc<MoveData>,
|
||||
/// The maximal power points for this move.
|
||||
max_pp: u8,
|
||||
/// The amount of remaining power points. If this is 0, we can not use the move anymore.
|
||||
@@ -28,11 +29,11 @@ pub enum MoveLearnMethod {
|
||||
Level = 1,
|
||||
}
|
||||
|
||||
impl<'a> LearnedMove<'a> {
|
||||
impl LearnedMove {
|
||||
/// Instantiate a new learned move.
|
||||
pub fn new(move_data: &'a MoveData, learn_method: MoveLearnMethod) -> Self {
|
||||
pub fn new(move_data: &Arc<MoveData>, learn_method: MoveLearnMethod) -> Self {
|
||||
Self {
|
||||
move_data,
|
||||
move_data: move_data.clone(),
|
||||
max_pp: move_data.base_usages(),
|
||||
remaining_pp: AtomicU8::new(move_data.base_usages()),
|
||||
learn_method,
|
||||
@@ -40,8 +41,8 @@ impl<'a> LearnedMove<'a> {
|
||||
}
|
||||
|
||||
/// The immutable move information of the move.
|
||||
pub fn move_data(&self) -> &MoveData {
|
||||
self.move_data
|
||||
pub fn move_data(&self) -> &Arc<MoveData> {
|
||||
&self.move_data
|
||||
}
|
||||
/// The maximal power points for this move.
|
||||
pub fn max_pp(&self) -> u8 {
|
||||
|
||||
Reference in New Issue
Block a user