~starkingdoms/starkingdoms

ref: 5591c7a32888c9950b5d21d1d18a6150907d6ea7 starkingdoms/crates/unified/src/ship_editor/mod.rs -rw-r--r-- 1.4 KiB
5591c7a3ghostly_zsh feat: part list & dragging ghosts 9 hours 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
50
51
52
53
54
55
56
57
pub mod ui;
pub mod input;
pub mod plugins;
pub mod components;

use bevy::input_focus::InputFocus;
use crate::client::colors;
use crate::prelude::*;
use crate::ship_editor::components::{GhostCamera, MainCamera, GHOST_RENDER_LAYER, MAIN_RENDER_LAYER};
use crate::ship_editor::input::input_plugin;
use crate::ship_editor::ui::ui_plugin;

pub struct ShipEditorPlugin;

impl Plugin for ShipEditorPlugin {
    fn build(&self, app: &mut App) {
        app
            .init_resource::<InputFocus>()
            .add_systems(Startup, setup)
            .add_plugins(input_plugin)
            .add_plugins(ui_plugin);
    }
}

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<ColorMaterial>>,
) {
    commands.insert_resource(ClearColor(colors::BASE));
    commands.spawn((
        Camera2d,
        Camera {
            order: 0,
            ..Default::default()
        },
        Transform::from_xyz(0.0, 0.0, 0.0),
        MainCamera,
        IsDefaultUiCamera,
        MAIN_RENDER_LAYER,
    ));
    commands.spawn((
        Camera2d::default(),
        Camera {
            order: 1,
            ..Default::default()
        },
        GhostCamera,
        GHOST_RENDER_LAYER,
    ));
    let rectangle = meshes.add(Rectangle::new(50.0, 50.0));
    commands.spawn((
        Mesh2d(rectangle),
        MeshMaterial2d(materials.add(Color::linear_rgb(0.0, 0.0, 0.0))),
        Transform::from_xyz(0.0, 0.0, 0.0)
    ));
}