~starkingdoms/starkingdoms

ref: d2b8956323d8e82903824637cdcfb2f978dd94e9 starkingdoms/crates/unified/src/client/starguide/init.rs -rw-r--r-- 1.6 KiB
d2b89563 — core chore: please thy lord clippy 16 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
38
39
40
41
42
43
44
45
46
47
48
49
use bevy::anti_alias::fxaa::Fxaa;
use bevy::core_pipeline::tonemapping::DebandDither;
use bevy::post_process::bloom::Bloom;
use crate::prelude::*;
use crate::ecs::{Me, Part, STARGUIDE_LAYER, StarguideCamera, StarguideMe, StarguideOrbit};

pub fn starguide_init_plugin(app: &mut App) {
    app
        .add_systems(Startup, init_starguide)
        .add_systems(Update, player_init)
        .add_systems(Update, player_position_update);
}

pub fn init_starguide(
    mut commands: Commands,
) {
    commands.spawn((Camera2d, Camera {
        is_active: false,
        clear_color: ClearColorConfig::Custom(Color::linear_rgba(0.0, 0.0, 0.0, 1.0)),
        ..default()
    }))
    .insert(Bloom::default())
    .insert(DebandDither::Enabled)
    .insert(Fxaa::default())
    .insert(STARGUIDE_LAYER)
    .insert(StarguideCamera);
}

pub fn player_init(
    me: Single<(Entity, &Sprite, &Part), Added<Me>>,
    mut commands: Commands,
    asset_server: Res<AssetServer>,
) {
    let mut sprite = Sprite::from_image(asset_server.load(&me.2.strong_config.part.sprite_connected));
    sprite.custom_size = Some(Vec2::new(
        me.2.strong_config.physics.width,
        me.2.strong_config.physics.height,
    ));
    commands.spawn((sprite, StarguideMe, STARGUIDE_LAYER,
            Transform::from_scale(Vec3::splat(10.0))));
}

fn player_position_update(
    me: Single<&Transform, (Changed<Transform>, With<Me>)>,
    mut starguide_me: Single<&mut Transform, (With<StarguideMe>, Without<StarguideOrbit>, Without<Me>)>,
) {
    starguide_me.translation = me.translation;
    starguide_me.rotation = me.rotation;
}