Game

Struct Game 

Source
pub struct Game<C = StringMap> {
    pub inner: GameInner,
    pub context: C,
    pub tags: GameTags,
    /* private fields */
}
Expand description

Wraps GameInner with customizable a context used to represent the game-specific state.

The context is exposed to your pages, allowing you to interact with your game state within them.

§Example

use ifengine::{GameError, View};
use story::chap1;

let game = ifengine::Game!(chap1::p1);

let view = match game.view() {
   Ok(view: View) => view,
   Err(e: GameError) => {
       panic!("Unhandled err: {e}");
   }
};

ui.render(view, &mut game);

§Additional

When processing for rendering, you can use the inner field directly.

Fields§

§inner: GameInner§context: C§tags: GameTags

Implementations§

Source§

impl<C: GameContext> Game<C>

Source

pub fn new_with_page(page_name: impl Into<PageId>, page: Page<C>) -> Self

Source

pub fn simulating(&self) -> bool

Source

pub fn view(&mut self) -> Result<View, GameError>

Calls the active page in a loop, until a View is produced.

Source

pub fn id(&self) -> Option<PageId>

Source§

impl<C: GameContext> Game<C>

Source

pub fn interact( &mut self, e: Interactable<'_>, pageid: &PageId, ) -> Result<(), GameError>

Source

pub fn interact_all<F>(&self, view: View) -> Vec<Result<Self, GameError>>

Source§

impl<C: GameContext> Game<C>

Source

pub fn simulate<F>(&self, visitor: F) -> Simulation
where F: FnMut(&mut SimulationState<C>) -> bool,

The user must ensure that all cycles must be modelled by tunnels. We guarantee to never visit the same tunnel from the same location twice, but the presence of other loops will result in failure to halt. Although certain types of elements generated from proc_macros Panics if current game state is not a view F:

Methods from Deref<Target = GameInner>§

Source

pub fn handle_choice(&mut self, key: InternalKey, index: u8)

Source

pub fn handle_action(&mut self, action: Action) -> Result<(), GameError>

Source

pub fn fresh(&self) -> bool

Trait Implementations§

Source§

impl<C: Clone> Clone for Game<C>

Source§

fn clone(&self) -> Game<C>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<C: Debug> Debug for Game<C>

Source§

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

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

impl<C: GameContext> Deref for Game<C>

Source§

type Target = GameInner

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<C: GameContext> DerefMut for Game<C>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'de, C> Deserialize<'de> for Game<C>
where C: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<C> Serialize for Game<C>
where C: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<C> Freeze for Game<C>
where C: Freeze,

§

impl<C = HashMap<String, String>> !RefUnwindSafe for Game<C>

§

impl<C> Send for Game<C>
where C: Send,

§

impl<C> Sync for Game<C>
where C: Sync,

§

impl<C> Unpin for Game<C>
where C: Unpin,

§

impl<C = HashMap<String, String>> !UnwindSafe for Game<C>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,