Removes derive-getters, as it was incredibly annoying in IDEs, and couldn't figure out borrow lifetimes.

This commit is contained in:
2022-06-06 14:43:41 +02:00
parent ce33ec0649
commit c27ea0ae1e
16 changed files with 395 additions and 57 deletions

View File

@@ -6,20 +6,20 @@ use crate::dynamic_data::models::battle_party::BattleParty;
use crate::dynamic_data::models::battle_random::BattleRandom;
use crate::dynamic_data::models::battle_result::BattleResult;
use crate::dynamic_data::models::battle_side::BattleSide;
use crate::dynamic_data::script_handling::script::Script;
use crate::dynamic_data::script_handling::script_set::ScriptSet;
use derive_getters::Getters;
use crate::dynamic_data::script_handling::volatile_scripts::VolatileScripts;
use crate::{PkmnResult, ScriptCategory};
use std::sync::{Arc, RwLock};
#[derive(Getters, Debug)]
#[derive(Debug)]
pub struct Battle<'a> {
#[getter(skip)]
library: &'a DynamicLibrary<'a>,
parties: Vec<BattleParty<'a>>,
can_flee: bool,
number_of_sides: u8,
pokemon_per_side: u8,
sides: Vec<BattleSide<'a>>,
#[getter(skip)]
random: BattleRandom,
choice_queue: ChoiceQueue,
has_ended: bool,
@@ -27,7 +27,7 @@ pub struct Battle<'a> {
event_hook: EventHook,
history_holder: Box<HistoryHolder>,
current_turn: u32,
volatile: ScriptSet,
volatile: Arc<RwLock<ScriptSet>>,
last_turn_time: i64,
}
@@ -60,7 +60,7 @@ impl<'a> Battle<'a> {
event_hook: Default::default(),
history_holder: Box::new(HistoryHolder {}),
current_turn: 0,
volatile: ScriptSet::default(),
volatile: Default::default(),
last_turn_time: 0,
}));
@@ -71,15 +71,60 @@ impl<'a> Battle<'a> {
battle
}
pub fn library(&self) -> &'a DynamicLibrary<'a> {
self.library
}
pub fn parties(&self) -> &Vec<BattleParty<'a>> {
&self.parties
}
pub fn can_flee(&self) -> bool {
self.can_flee
}
pub fn number_of_sides(&self) -> u8 {
self.number_of_sides
}
pub fn pokemon_per_side(&self) -> u8 {
self.pokemon_per_side
}
pub fn sides(&self) -> &Vec<BattleSide<'a>> {
&self.sides
}
pub fn random(&self) -> &BattleRandom {
&self.random
}
pub fn has_ended(&self) -> bool {
self.has_ended
}
pub fn result(&self) -> BattleResult {
self.result
}
pub fn event_hook(&self) -> &EventHook {
&self.event_hook
}
pub fn history_holder(&self) -> &Box<HistoryHolder> {
&self.history_holder
}
pub fn current_turn(&self) -> u32 {
self.current_turn
}
pub fn last_turn_time(&self) -> i64 {
self.last_turn_time
}
pub fn choice_queue(&self) -> &ChoiceQueue {
&self.choice_queue
}
pub fn can_slot_be_filled(&self) -> bool {
todo!()
}
}
pub fn library(&self) -> &'a DynamicLibrary<'a> {
self.library
impl<'a> VolatileScripts<'a> for Battle<'a> {
fn volatile_scripts(&self) -> &Arc<RwLock<ScriptSet>> {
&self.volatile
}
fn load_volatile_script(&self, key: &str) -> PkmnResult<Box<dyn Script>> {
self.library.load_script(ScriptCategory::Battle, key)
}
}