Struct bones_lib::SessionBuilder
source · pub struct SessionBuilder {
pub name: Ustr,
pub stages: SystemStagesBuilder,
pub active: bool,
pub visible: bool,
pub priority: i32,
pub runner: Box<dyn SessionRunner>,
/* private fields */
}
Expand description
Builder type used to create Session
. If using this directly (as opposed to Sessions::create_with
),
it is important to rember to finish session and add to Sessions
with SessionBuilder::finish_and_add
.
Fields§
§name: Ustr
Name of session
stages: SystemStagesBuilder
System stage builder
active: bool
Whether or not this session should have it’s systems run.
visible: bool
Whether or not this session should be rendered.
priority: i32
The priority of this session relative to other sessions in the Game
.
runner: Box<dyn SessionRunner>
The session runner to use for this session.
Implementations§
source§impl SessionBuilder
impl SessionBuilder
sourcepub fn new<N: TryInto<Ustr>>(name: N) -> Self
pub fn new<N: TryInto<Ustr>>(name: N) -> Self
Create a new SessionBuilder
. Be sure to add it to Sessions
when finished, with SessionBuilder::finish_and_add
, or Sessions::create
.
§Panics
Panics if the name.try_into()
cannot convert into Ustr
.
sourcepub fn from_existing_session<N: TryInto<Ustr>>(
name: N,
session: Session,
) -> Self
pub fn from_existing_session<N: TryInto<Ustr>>( name: N, session: Session, ) -> Self
Create a SessionBuilder
to match existing Session
, consuming it. This is useful if a GamePlugin
wishes to modify a session created by another plugin.
The builder is initialized with settings from session, can be further modified, and then added to session to replace existing.
sourcepub fn stages(&mut self) -> &mut SystemStagesBuilder
pub fn stages(&mut self) -> &mut SystemStagesBuilder
Get the SystemStagesBuilder
(though the stage build functions are also on SessionBuilder
for convenience).
sourcepub fn set_active(&mut self, active: bool) -> &mut Self
pub fn set_active(&mut self, active: bool) -> &mut Self
Whether or not session should run systems.
sourcepub fn set_visible(&mut self, visible: bool) -> &mut Self
pub fn set_visible(&mut self, visible: bool) -> &mut Self
Whether or not session should be rendered.
sourcepub fn set_priority(&mut self, priority: i32) -> &mut Self
pub fn set_priority(&mut self, priority: i32) -> &mut Self
The priority of this session relative to other sessions in the Game
.
sourcepub fn insert_resource<T: HasSchema>(&mut self, resource: T) -> &mut Self
pub fn insert_resource<T: HasSchema>(&mut self, resource: T) -> &mut Self
Insert a resource.
Note: The resource is not actually initialized in World until first step of SystemStages
.
To mutate or inspect a resource inserted by another SessionPlugin
during session build, use SessionBuilder::resource_mut
.
sourcepub fn init_resource<T: HasSchema + Default>(&mut self) -> RefMut<'_, T>
pub fn init_resource<T: HasSchema + Default>(&mut self) -> RefMut<'_, T>
Insert a resource using default value (if not found). Returns a mutable ref for modification.
Note: The resource is not actually initialized in World until first step of SystemStages
.
To mutate or inspect a resource inserted by another SessionPlugin
during session build, use SessionBuilder::resource_mut
.
sourcepub fn resource_mut<T: HasSchema>(&self) -> Option<RefMut<'_, T>>
pub fn resource_mut<T: HasSchema>(&self) -> Option<RefMut<'_, T>>
Get mutable reference to a resource if it exists.
sourcepub fn add_startup_system<Args, S>(&mut self, system: S) -> &mut Self
pub fn add_startup_system<Args, S>(&mut self, system: S) -> &mut Self
Add a system that will run only once, before all of the other non-startup systems.
If wish to reset startup systems during gameplay and run again, can modify SessionStarted
resource in world.
sourcepub fn add_single_success_system<Args, S>(&mut self, system: S) -> &mut Self
pub fn add_single_success_system<Args, S>(&mut self, system: S) -> &mut Self
Add a system that will run each frame until it succeeds (returns Some). Runs before all stages. Uses Option to allow for easy usage of ?
.
sourcepub fn add_system_to_stage<Args, S>(
&mut self,
label: impl StageLabel,
system: S,
) -> &mut Self
pub fn add_system_to_stage<Args, S>( &mut self, label: impl StageLabel, system: S, ) -> &mut Self
Add a System
to the stage with the given label.
sourcepub fn insert_stage_before<L: StageLabel, S: SystemStage + 'static>(
&mut self,
label: L,
stage: S,
) -> &mut SessionBuilder
pub fn insert_stage_before<L: StageLabel, S: SystemStage + 'static>( &mut self, label: L, stage: S, ) -> &mut SessionBuilder
Insert a new stage, before another existing stage
sourcepub fn insert_stage_after<L: StageLabel, S: SystemStage + 'static>(
&mut self,
label: L,
stage: S,
) -> &mut SessionBuilder
pub fn insert_stage_after<L: StageLabel, S: SystemStage + 'static>( &mut self, label: L, stage: S, ) -> &mut SessionBuilder
Insert a new stage, after another existing stage
sourcepub fn set_session_runner(&mut self, runner: Box<dyn SessionRunner>)
pub fn set_session_runner(&mut self, runner: Box<dyn SessionRunner>)
Set the session runner for this session.
sourcepub fn install_plugin(&mut self, plugin: impl SessionPlugin) -> &mut Self
pub fn install_plugin(&mut self, plugin: impl SessionPlugin) -> &mut Self
Install a plugin.
sourcepub fn finish_and_add(self, sessions: &mut Sessions) -> &mut Session
pub fn finish_and_add(self, sessions: &mut Sessions) -> &mut Session
Finalize and add to Sessions
.
Alternatively, you may directly pass a SessionBuilder
to Sessions::create
to add and finalize.