|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mod option_selection; |
|
mod setup; |
|
mod typewriter; |
|
mod updating; |
|
|
|
use bevy::{ |
|
app::{ App, Plugin, Update }, |
|
asset::Handle, |
|
ecs::{ |
|
schedule::{ common_conditions::resource_added, Condition, IntoSystemConfigs, SystemSet }, |
|
system::{ Commands, Res, Resource }, |
|
}, |
|
log::info, |
|
render::texture::Image, |
|
state::{ condition::in_state, state::{ FreelyMutableState, States } }, |
|
text::Font, |
|
}; |
|
use bevy_asset_loader::{ |
|
asset_collection::AssetCollection, |
|
loading_state::{ config::{ ConfigureLoadingState, LoadingStateConfig }, LoadingStateAppExt }, |
|
}; |
|
use bevy_yarnspinner::prelude::{ YarnFileSource, YarnSpinnerPlugin, YarnProject }; |
|
|
|
pub use updating::SpeakerChangeEvent; |
|
pub(crate) use typewriter::not_in_dialogue; |
|
|
|
|
|
#[derive(Debug, Default)] |
|
pub struct YarnSpinnerDialogueViewPlugin<T> { |
|
|
|
pub loading_state: T, |
|
|
|
pub playing_state: T, |
|
} |
|
|
|
|
|
|
|
#[derive(Debug, Default, Clone, Copy, SystemSet, Eq, PartialEq, Hash)] |
|
pub struct YarnSpinnerDialogueViewSystemSet; |
|
|
|
#[derive(AssetCollection, Resource)] |
|
struct Assets { |
|
#[asset(path = "fonts/bahnschrift.ttf")] |
|
font: Handle<Font>, |
|
#[asset(path = "ui/dialogue_continue.png")] |
|
continue_indicator: Handle<Image>, |
|
#[asset(path = "ui/dialogue_edge.png")] |
|
edge: Handle<Image>, |
|
} |
|
|
|
impl<T: States + FreelyMutableState> Plugin for YarnSpinnerDialogueViewPlugin<T> { |
|
fn build(&self, app: &mut App) { |
|
app.add_plugins( |
|
YarnSpinnerPlugin::with_yarn_source(YarnFileSource::file("dialogues/kade_dialog.yarn")) |
|
) |
|
.configure_loading_state( |
|
LoadingStateConfig::new(self.loading_state.clone()).load_collection::<Assets>() |
|
) |
|
.add_systems(Update, setup::setup.run_if(resource_added::<Assets>)) |
|
.add_plugins(updating::ui_updating_plugin) |
|
.add_plugins(typewriter::typewriter_plugin) |
|
.add_plugins(option_selection::option_selection_plugin) |
|
.add_systems( |
|
Update, |
|
|
|
spawn_dialogue_runner.run_if( |
|
in_state(self.playing_state.clone()).and_then(resource_added::<YarnProject>) |
|
) |
|
); |
|
} |
|
} |
|
|
|
fn spawn_dialogue_runner(mut commands: Commands, project: Res<YarnProject>) { |
|
info!("Starting dialogue runner."); |
|
|
|
let dialogue_runner = project.create_dialogue_runner(); |
|
|
|
|
|
commands.spawn(dialogue_runner); |
|
} |
|
|