~starkingdoms/starkingdoms

ref: 827d7ac625a9afa1a6afee0c2e10e0afc1fcb162 starkingdoms/crates/unified/src/client/rendering/mod.rs -rw-r--r-- 998 bytes
827d7ac6 — core chore: client refactoring 24 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use bevy::anti_alias::fxaa::Fxaa;
use bevy::app::{App, Startup};
use bevy::core_pipeline::tonemapping::DebandDither;
use bevy::post_process::bloom::Bloom;
use crate::ecs::{MainCamera, Me};
use crate::prelude::*;

pub fn render_plugin(app: &mut App) {
    app
        .add_systems(Startup, setup_graphics)
        .add_systems(Update, follow_camera);
}


fn setup_graphics(mut commands: Commands) {
    commands
        .spawn(Camera2d)
        .insert(Camera {
            clear_color: ClearColorConfig::Custom(Color::BLACK),
            ..default()
        })
        .insert(Bloom::default())
        .insert(DebandDither::Enabled)
        .insert(Fxaa::default())
        .insert(MainCamera);
}

fn follow_camera(
    mut camera: Query<&mut Transform, (With<MainCamera>, Without<Me>)>,
    player: Query<&Transform, With<Me>>,
) {
    let mut camera = camera.single_mut().unwrap();
    let Ok(player) = player.single() else {
        return;
    };
    camera.translation = player.translation;
}