Implements the script source methods on all current structs that implement it.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-06-12 18:41:49 +02:00
parent f0bc62ce19
commit 00f66bbf59
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
5 changed files with 27 additions and 8 deletions

View File

@ -31,6 +31,8 @@ pub struct Battle<'a> {
current_turn: u32,
volatile_scripts: Arc<RwLock<ScriptSet>>,
last_turn_time: i64,
script_source_data: RwLock<ScriptSourceData>,
}
impl<'a> Battle<'a> {
@ -64,6 +66,7 @@ impl<'a> Battle<'a> {
current_turn: 0,
volatile_scripts: Default::default(),
last_turn_time: 0,
script_source_data: Default::default(),
}));
for i in 0..number_of_sides {
@ -176,11 +179,11 @@ impl<'a> VolatileScripts<'a> for Battle<'a> {
impl<'a> ScriptSource<'a> for Battle<'a> {
fn get_script_count(&self) -> usize {
todo!()
1
}
fn get_script_source_data(&self) -> &RwLock<ScriptSourceData> {
todo!()
&self.script_source_data
}
fn get_own_scripts(&self, scripts: &mut Vec<ScriptWrapper>) {

View File

@ -23,6 +23,8 @@ pub struct BattleSide<'a> {
battle: Weak<RwLock<Battle<'a>>>,
has_fled_battle: bool,
volatile_scripts: Arc<RwLock<ScriptSet>>,
script_source_data: RwLock<ScriptSourceData>,
}
impl<'a> BattleSide<'a> {
@ -47,6 +49,7 @@ impl<'a> BattleSide<'a> {
battle,
has_fled_battle: false,
volatile_scripts: Default::default(),
script_source_data: Default::default(),
}
}
pub fn index(&self) -> u8 {
@ -277,11 +280,11 @@ impl<'a> VolatileScripts<'a> for BattleSide<'a> {
impl<'a> ScriptSource<'a> for BattleSide<'a> {
fn get_script_count(&self) -> usize {
todo!()
self.battle.upgrade().unwrap().read().get_script_count() + 1
}
fn get_script_source_data(&self) -> &RwLock<ScriptSourceData> {
todo!()
&self.script_source_data
}
fn get_own_scripts(&self, scripts: &mut Vec<ScriptWrapper>) {

View File

@ -65,6 +65,7 @@ pub struct ExecutingMove<'a, 'b> {
use_move: &'a MoveData,
script: ScriptContainer,
targets: Vec<Option<&'a Pokemon<'b>>>,
script_source_data: RwLock<ScriptSourceData>,
}
impl<'a, 'b> ExecutingMove<'a, 'b> {
@ -89,6 +90,7 @@ impl<'a, 'b> ExecutingMove<'a, 'b> {
use_move,
script,
targets,
script_source_data: Default::default(),
}
}
pub fn target_count(&self) -> usize {
@ -150,7 +152,7 @@ impl<'a, 'b> ScriptSource<'a> for ExecutingMove<'a, 'b> {
}
fn get_script_source_data(&self) -> &RwLock<ScriptSourceData> {
todo!()
&self.script_source_data
}
fn get_own_scripts(&self, scripts: &mut Vec<ScriptWrapper>) {

View File

@ -92,6 +92,8 @@ pub struct Pokemon<'a> {
ability_script: ScriptContainer,
status_script: ScriptContainer,
volatile: Arc<RwLock<ScriptSet>>,
script_source_data: RwLock<ScriptSourceData>,
}
impl<'a> Pokemon<'a> {
@ -154,6 +156,7 @@ impl<'a> Pokemon<'a> {
ability_script: ScriptContainer::default(),
status_script: ScriptContainer::default(),
volatile: Default::default(),
script_source_data: Default::default(),
};
pokemon.recalculate_flat_stats();
pokemon
@ -535,11 +538,18 @@ impl<'a> Pokemon<'a> {
impl<'a> ScriptSource<'a> for Pokemon<'a> {
fn get_script_count(&self) -> usize {
todo!()
let mut c = 3;
if let Some(battle_data) = &self.battle_data {
if let Some(battle) = battle_data.battle.upgrade() {
c += battle.read().sides()[battle_data.battle_side_index as usize]
.get_script_count();
}
}
c
}
fn get_script_source_data(&self) -> &RwLock<ScriptSourceData> {
todo!()
&self.script_source_data
}
fn get_own_scripts(&self, scripts: &mut Vec<ScriptWrapper>) {

View File

@ -23,7 +23,7 @@ macro_rules! script_hook {
};
}
#[derive(Default)]
#[derive(Default, Debug)]
pub struct ScriptSourceData {
is_initialized: bool,
scripts: Vec<ScriptWrapper>,
@ -46,6 +46,7 @@ pub trait ScriptSource<'a> {
fn collect_scripts(&self, scripts: &mut Vec<ScriptWrapper>);
}
#[derive(Debug)]
pub enum ScriptWrapper {
Script(Weak<RwLock<Option<Box<dyn Script>>>>),
Set(Weak<RwLock<ScriptSet>>),