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::fmt::{Debug, Formatter};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::dynamic_data::DamageSource;
|
||||
use crate::dynamic_data::ExecutingMove;
|
||||
@@ -27,7 +28,7 @@ impl<'battle, 'library> EventHook {
|
||||
|
||||
/// Run a new event. This will send the event to all externally defined event listeners. It will
|
||||
/// dispose of the event afterwards.
|
||||
pub fn trigger<'b>(&self, evt: Event<'b, 'battle, 'library>) {
|
||||
pub fn trigger(&self, evt: Event) {
|
||||
let b = Box::new(&evt);
|
||||
for f in &self.evt_hook_function {
|
||||
f(&b);
|
||||
@@ -43,7 +44,7 @@ impl Debug for EventHook {
|
||||
|
||||
/// The different events that can occur during the battle, for which a GUI should show something.
|
||||
#[derive(Debug)]
|
||||
pub enum Event<'own, 'battle, 'library> {
|
||||
pub enum Event<'own> {
|
||||
/// A switch event happens when a Pokemon gets switched out for something else.
|
||||
Switch {
|
||||
/// The side the Pokemon got switched from/on
|
||||
@@ -51,7 +52,7 @@ pub enum Event<'own, 'battle, 'library> {
|
||||
/// The index of the Pokemon that got switched in/out on its side
|
||||
index: u8,
|
||||
/// The new Pokemon that will be on the spot. If none, the spot will now be empty.
|
||||
pokemon: Option<&'own Pokemon<'battle, 'library>>,
|
||||
pokemon: Option<&'own Pokemon>,
|
||||
},
|
||||
/// A swap event happens when two Pokemon on a side swap positions. Note that this is rare.
|
||||
Swap {
|
||||
@@ -67,23 +68,23 @@ pub enum Event<'own, 'battle, 'library> {
|
||||
/// enjoy.
|
||||
SpeciesChange {
|
||||
/// The pokemon that changed species.
|
||||
pokemon: &'own Pokemon<'battle, 'library>,
|
||||
pokemon: &'own Pokemon,
|
||||
/// The new species of the Pokemon.
|
||||
species: &'own Species,
|
||||
species: Arc<Species>,
|
||||
/// The form of the species the Pokemon will have.
|
||||
form: &'own Form,
|
||||
form: Arc<Form>,
|
||||
},
|
||||
/// This event happens when a Pokemon changes form during battle. This is rather common.
|
||||
FormChange {
|
||||
/// The pokemon that changed forms.
|
||||
pokemon: &'own Pokemon<'battle, 'library>,
|
||||
pokemon: &'own Pokemon,
|
||||
/// The new form of the Pokemon.
|
||||
form: &'own Form,
|
||||
},
|
||||
/// This event happens when a Pokemon takes damage.
|
||||
Damage {
|
||||
/// The Pokemon that takes damage.
|
||||
pokemon: &'own Pokemon<'battle, 'library>,
|
||||
pokemon: &'own Pokemon,
|
||||
/// The source of damage.
|
||||
source: DamageSource,
|
||||
/// The health of the Pokemon before the damage.
|
||||
@@ -94,7 +95,7 @@ pub enum Event<'own, 'battle, 'library> {
|
||||
/// This event happens when a Pokemon gets healed
|
||||
Heal {
|
||||
/// The Pokemon that gets healed.
|
||||
pokemon: &'own Pokemon<'battle, 'library>,
|
||||
pokemon: &'own Pokemon,
|
||||
/// The health of the Pokemon before the heal.
|
||||
original_health: u32,
|
||||
/// The health of the Pokemon after the heal.
|
||||
@@ -103,24 +104,24 @@ pub enum Event<'own, 'battle, 'library> {
|
||||
/// This event happens when a Pokemon faints.
|
||||
Faint {
|
||||
/// The pokemon that has fainted.
|
||||
pokemon: &'own Pokemon<'battle, 'library>,
|
||||
pokemon: &'own Pokemon,
|
||||
},
|
||||
/// This event happens when a Pokemon uses a move on a target, just before any hits.
|
||||
MoveUse {
|
||||
/// The data of the move used.
|
||||
executing_move: &'own ExecutingMove<'own, 'battle, 'library>,
|
||||
executing_move: &'own ExecutingMove,
|
||||
},
|
||||
/// This event happens when a Pokemon missed.
|
||||
Miss {
|
||||
/// The pokemon that missed.
|
||||
user: &'own Pokemon<'battle, 'library>,
|
||||
user: &'own Pokemon,
|
||||
},
|
||||
/// The turn is finished running, waiting for new input.
|
||||
EndTurn,
|
||||
/// A pokemon had its stat boost changed
|
||||
StatBoostChange {
|
||||
/// The pokemon that had its stat boosts changed.
|
||||
user: &'own Pokemon<'battle, 'library>,
|
||||
user: &'own Pokemon,
|
||||
/// The statistic that changed.
|
||||
stat: Statistic,
|
||||
/// The value of the stat before the change.
|
||||
|
||||
Reference in New Issue
Block a user