use crate::ecs::{CraftPartRequest, DragRequestEvent, ToggleDrillEvent};
use crate::thrust::ThrustSolution;
use bevy::app::{App, PluginGroup, PluginGroupBuilder};
use bevy_common_assets::toml::TomlAssetPlugin;
use crate::prelude::*;
use crate::config::part::PartConfig;
use crate::config::planet::PlanetConfigCollection;
use crate::config::recipe::RecipesConfig;
use crate::config::world::GlobalWorldConfig;
use crate::world_config::world_config_plugin;
pub struct SharedPluginGroup;
impl PluginGroup for SharedPluginGroup {
fn build(self) -> PluginGroupBuilder {
PluginGroupBuilder::start::<Self>()
.add(|app: &mut App| {
app.insert_resource(Time::from_hz(20.0));
})
.add_group(
PhysicsPlugins::default()
.with_length_unit(100.0)
.set(PhysicsInterpolationPlugin::interpolate_all())
.build()
.disable::<IslandPlugin>()
)
.add(physics_setup_plugin)
.add(register_everything)
.add(world_config_plugin)
/* Assets */
.add(TomlAssetPlugin::<GlobalWorldConfig>::new(&["wc.toml"]))
.add(TomlAssetPlugin::<PlanetConfigCollection>::new(&["pc.toml"]))
.add(TomlAssetPlugin::<PartConfig>::new(&["part.toml"]))
.add(TomlAssetPlugin::<RecipesConfig>::new(&["rc.toml"]))
}
}
pub fn register_everything(app: &mut App) {
app.add_message::<DragRequestEvent>();
app.add_message::<ToggleDrillEvent>();
app.add_message::<CraftPartRequest>();
app.add_message::<ThrustSolution>();
}
fn physics_setup_plugin(app: &mut App) {
app.insert_resource(Gravity::ZERO);
app.add_systems(Startup, setup_physics);
}
fn setup_physics() {}
/*
fn setup_physics(
mut rapier_config: Query<&mut RapierConfiguration>,
mut rapier_context: Query<&mut RapierContextSimulation>,
) {
let mut cfg = rapier_config.single_mut().unwrap();
cfg.gravity = Vec2::ZERO;
let ctx = rapier_context.single_mut().unwrap();
let mut params = ctx.integration_parameters;
params.num_internal_stabilization_iterations = 16;
}
*/