Struct ayaka_model::GameViewModel
source · pub struct GameViewModel<M: SettingsManager> { /* private fields */ }Expand description
A view model of Ayaka. It manages all settings and provides high-level APIs.
Implementations§
source§impl<M: SettingsManager> GameViewModel<M>
impl<M: SettingsManager> GameViewModel<M>
sourcepub fn new(settings_manager: M) -> Self
pub fn new(settings_manager: M) -> Self
Create a GameViewModel with a settings manager.
sourcepub fn open_game<'a>(
&'a mut self,
paths: &'a [impl AsRef<Path>],
frontend_type: FrontendType
) -> impl Future<Output = Result<()>> + Stream<Item = OpenGameStatus> + 'a
pub fn open_game<'a>( &'a mut self, paths: &'a [impl AsRef<Path>], frontend_type: FrontendType ) -> impl Future<Output = Result<()>> + Stream<Item = OpenGameStatus> + 'a
Open the game with paths and frontend type.
sourcepub fn context(&self) -> &Context
pub fn context(&self) -> &Context
The Context, should be called after Self::open_game.
sourcepub fn context_mut(&mut self) -> &mut Context
pub fn context_mut(&mut self) -> &mut Context
The Context, should be called after Self::open_game.
sourcepub fn record(&self) -> &ActionRecord
pub fn record(&self) -> &ActionRecord
The current ActionRecord.
sourcepub fn set_settings(&mut self, settings: Settings)
pub fn set_settings(&mut self, settings: Settings)
Set the Settings.
sourcepub fn records(&self) -> &[ActionRecord]
pub fn records(&self) -> &[ActionRecord]
The loaded ActionRecords.
sourcepub fn global_record(&self) -> &GlobalRecord
pub fn global_record(&self) -> &GlobalRecord
The loaded GlobalRecord.
sourcepub fn global_record_mut(&mut self) -> &mut GlobalRecord
pub fn global_record_mut(&mut self) -> &mut GlobalRecord
The loaded GlobalRecord.
sourcepub fn avaliable_locale(&self) -> impl Iterator<Item = &Locale>
pub fn avaliable_locale(&self) -> impl Iterator<Item = &Locale>
Get the avaliable locales from paragraphs.
sourcepub fn init_new(&mut self)
pub fn init_new(&mut self)
Start a new game.
The state of the model after this call is actually invalid.
You should call next_run immediately after this call,
to ensure there’s content in the game, and switch to the
first line of the first paragraph.
sourcepub fn init_context(&mut self, record: ActionRecord)
pub fn init_context(&mut self, record: ActionRecord)
Start a game with record.
sourcepub fn init_context_by_index(&mut self, index: usize)
pub fn init_context_by_index(&mut self, index: usize)
Start a game with the index of records.
sourcepub fn next_back_run(&mut self) -> bool
pub fn next_back_run(&mut self) -> bool
Step back to the last run.
sourcepub fn current_run(&self) -> Option<&RawContext>
pub fn current_run(&self) -> Option<&RawContext>
Get the current [RawContext].
sourcepub fn current_title(&self) -> Option<&String>
pub fn current_title(&self) -> Option<&String>
Get the current paragraph title.
sourcepub fn current_action(&self) -> Option<Action>
pub fn current_action(&self) -> Option<Action>
Get the current action by language.
sourcepub fn current_actions(&self) -> Option<(Action, Option<Action>)>
pub fn current_actions(&self) -> Option<(Action, Option<Action>)>
Get the current action by language and secondary language.
sourcepub fn save_current_to(&mut self, index: usize)
pub fn save_current_to(&mut self, index: usize)
Save current ActionRecord to the records.
sourcepub fn save_settings(&self) -> Result<()>
pub fn save_settings(&self) -> Result<()>
Save all settings and records.
sourcepub fn current_visited(&self) -> bool
pub fn current_visited(&self) -> bool
Determine if current run has been visited.
sourcepub fn records_text(&self) -> impl Iterator<Item = ActionText> + '_
pub fn records_text(&self) -> impl Iterator<Item = ActionText> + '_
Get the last action text from each record.
sourcepub fn current_history(
&self
) -> impl DoubleEndedIterator<Item = (Action, Option<Action>)> + '_
pub fn current_history( &self ) -> impl DoubleEndedIterator<Item = (Action, Option<Action>)> + '_
Get the current history by language and secondary language.
Auto Trait Implementations§
impl<M> !RefUnwindSafe for GameViewModel<M>
impl<M> Send for GameViewModel<M>where M: Send,
impl<M> Sync for GameViewModel<M>where M: Sync,
impl<M> Unpin for GameViewModel<M>where M: Unpin,
impl<M> !UnwindSafe for GameViewModel<M>
Blanket Implementations§
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.