61 lines
1.8 KiB
Rust
61 lines
1.8 KiB
Rust
use crate::{DebugVisuals, client::camera::MainCamera};
|
|
use bevy::{core_pipeline::tonemapping::Tonemapping, prelude::*, render::view::ColorGrading};
|
|
use bevy_trenchbroom::TrenchBroomServer;
|
|
|
|
pub fn plugin(app: &mut App) {
|
|
#[cfg(feature = "dbg")]
|
|
{
|
|
app.add_plugins(bevy_inspector_egui::bevy_egui::EguiPlugin::default());
|
|
app.add_plugins(bevy_inspector_egui::quick::WorldInspectorPlugin::new());
|
|
app.add_plugins(avian3d::prelude::PhysicsDebugPlugin::default());
|
|
}
|
|
|
|
app.insert_resource(AmbientLight {
|
|
color: Color::WHITE,
|
|
brightness: 400.,
|
|
..Default::default()
|
|
});
|
|
app.insert_resource(ClearColor(Color::BLACK));
|
|
|
|
app.add_systems(Startup, write_trenchbroom_config);
|
|
app.add_systems(Update, (set_materials_unlit, set_tonemapping, set_shadows));
|
|
}
|
|
|
|
fn write_trenchbroom_config(server: Res<TrenchBroomServer>, type_registry: Res<AppTypeRegistry>) {
|
|
if let Err(e) = server
|
|
.config
|
|
.write_game_config("trenchbroom/hedz", &type_registry.read())
|
|
{
|
|
warn!("Failed to write trenchbroom config: {}", e);
|
|
}
|
|
}
|
|
|
|
fn set_tonemapping(
|
|
mut cams: Query<(&mut Tonemapping, &mut ColorGrading), With<MainCamera>>,
|
|
visuals: Res<DebugVisuals>,
|
|
) {
|
|
for (mut tm, mut color) in cams.iter_mut() {
|
|
*tm = visuals.tonemapping;
|
|
color.global.exposure = visuals.exposure;
|
|
}
|
|
}
|
|
|
|
fn set_materials_unlit(
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
visuals: Res<DebugVisuals>,
|
|
) {
|
|
if !materials.is_changed() {
|
|
return;
|
|
}
|
|
|
|
for (_, material) in materials.iter_mut() {
|
|
material.unlit = visuals.unlit;
|
|
}
|
|
}
|
|
|
|
fn set_shadows(mut lights: Query<&mut DirectionalLight>, visuals: Res<DebugVisuals>) {
|
|
for mut l in lights.iter_mut() {
|
|
l.shadows_enabled = visuals.shadows;
|
|
}
|
|
}
|