Skip to main content

EventFlags

Struct EventFlags 

Source
#[non_exhaustive]
pub struct EventFlags { /* private fields */ }
Expand description

A generic, string-keyed event flag system.

Stores boolean flags keyed by string name. This is the foundation for game-event tracking (story progression, item pickups, trainer defeats) in any JRPG. The struct is #[non_exhaustive] to allow game-specific extensions in downstream crates.

§Design

  • Flags are stored as HashMap<String, bool> — one entry per flag name.
  • The string API (get_flag, set_flag, remove_flag) works with any flag name, enabling game-specific typed wrappers.
  • All methods are pure data manipulation — no I/O, no platform code.

§Example

let mut flags = EventFlags::new();
flags.set_flag("player_has_sword", true);
assert!(flags.get_flag("player_has_sword"));

Implementations§

Source§

impl EventFlags

Source

pub fn new() -> Self

Creates a new EventFlags with no flags set.

Source

pub fn count_set(&self) -> u32

Returns the number of flags that are currently set to true.

Source

pub fn clear_all(&mut self)

Clears all flags.

Source

pub fn get_flag(&self, name: &str) -> bool

Returns the value of a named flag, or false if unset.

Source

pub fn set_flag(&mut self, name: &str, value: bool)

Sets a named flag to a specific value.

Source

pub fn remove_flag(&mut self, name: &str)

Removes a named flag entirely.

Source

pub fn iter(&self) -> impl Iterator<Item = (&String, &bool)>

Returns an iterator over all (name, value) pairs.

Source

pub fn as_hashmap(&self) -> &HashMap<String, bool>

Returns a shared reference to the underlying HashMap.

Source

pub fn as_hashmap_mut(&mut self) -> &mut HashMap<String, bool>

Returns a mutable reference to the underlying HashMap.

Source

pub fn merge_from(&mut self, other: &HashMap<String, bool>)

Merges entries from another HashMap into this flag set. Existing keys are overwritten.

Source

pub fn to_hashmap(&self) -> HashMap<String, bool>

Clones the underlying HashMap for external use.

Source

pub fn from_hashmap(map: &HashMap<String, bool>) -> Self

Creates an EventFlags from an existing HashMap.

Trait Implementations§

Source§

impl Clone for EventFlags

Source§

fn clone(&self) -> EventFlags

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EventFlags

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EventFlags

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.