|
use bevy::prelude::*; |
|
use bevy_asset_loader::loading_state::{ |
|
config::{ ConfigureLoadingState, LoadingStateConfig }, |
|
LoadingStateAppExt, |
|
}; |
|
use bevy_ecs_ldtk::LdtkPlugin; |
|
use bevy_rapier2d::plugin::{ NoUserData, RapierPhysicsPlugin }; |
|
|
|
use crate::{ |
|
components::camera::fit_inside_current_level::fit_inside_current_level, |
|
components, |
|
entities, |
|
plugins::{ gamestate::GameState, ldtk }, |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
pub fn setup_world_systems(app: &mut App) { |
|
|
|
app.add_plugins(( |
|
crate::entities::plugin, |
|
LdtkPlugin, |
|
RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(100.0), |
|
)) |
|
|
|
|
|
.configure_loading_state( |
|
LoadingStateConfig::new(GameState::SplashScreen).load_collection::<ldtk::LdtkAssets>() |
|
) |
|
|
|
|
|
.add_systems( |
|
PreUpdate, |
|
ldtk::level_selection_systems().run_if(in_state(GameState::Playing)) |
|
) |
|
|
|
.add_systems(OnEnter(GameState::Playing), crate::plugins::ldtk::spawn_ldtk_world) |
|
|
|
|
|
.add_systems( |
|
Update, |
|
( |
|
ldtk::update_level_selection, |
|
ldtk::restart_level, |
|
ldtk::respawn_world, |
|
components::collision::spawn_wall_collision, |
|
( |
|
components::interactions::spawn_interaction_sensor, |
|
components::interactions::setup_interactive_entity, |
|
components::interactions::interaction_detection, |
|
components::interactions::update_interactions, |
|
).chain(), |
|
( |
|
components::ground::spawn_ground_sensor, |
|
components::ground::ground_detection, |
|
components::ground::update_on_ground, |
|
).chain(), |
|
( |
|
components::climbing::detect_climb_range, |
|
components::climbing::ignore_gravity_if_climbing, |
|
).chain(), |
|
components::swimming::detect_swim_range, |
|
components::predefinedpath::move_on_path, |
|
components::items::dbg_player_items, |
|
components::line_of_sight::line_of_sight::<entities::Player>, |
|
entities::player::draw_health_bar, |
|
).run_if(in_state(GameState::Playing)) |
|
) |
|
|
|
|
|
|
|
.add_systems(PostUpdate, fit_inside_current_level.run_if(in_state(GameState::Playing))); |
|
} |
|
|