diff --git a/src/editor.rs b/src/editor.rs index 5404140..382b585 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -20,7 +20,7 @@ impl Plugin for EditorPlugin { .add_system_set(SystemSet::on_enter(AppState::Editor).with_system(setup)) .add_system_set( SystemSet::on_update(AppState::Editor) - .with_system(keyboard_input_system) + .with_system(move_system) .with_system(follow_ends_system), ); } @@ -30,6 +30,8 @@ impl Plugin for EditorPlugin { struct DragEndEvent(Entity); +// Resources + // Components #[derive(Component)] @@ -47,7 +49,6 @@ struct End(Entity); struct PlatformBundle { #[bundle] mesh: ColorMesh2dBundle, - //platform: Platform, } #[derive(Bundle)] @@ -60,6 +61,15 @@ struct PlatformEndBundle { end: End, } +#[derive(Bundle)] +struct CharacterBundle { + #[bundle] + mesh: ColorMesh2dBundle, + #[bundle] + pickable: PickableBundle, + draggable: Draggable, +} + // Functions fn spawn_platform( @@ -129,6 +139,50 @@ fn spawn_platform( commands.entity(platform).insert(ends); } +fn spawn_character( + commands: &mut Commands, + meshes: &mut ResMut>, + materials: &mut ResMut>, + asset_server: &Res, + + transform: Transform, + color: Color, + index: usize, +) { + let font = asset_server.get_handle("UacariLegacy-Thin.ttf"); + commands + .spawn_bundle(CharacterBundle { + mesh: ColorMesh2dBundle { + mesh: meshes + .add(Mesh::from(Quad { + size: Vec2 { x: 64., y: 64. }, + flip: false, + })) + .into(), + material: materials.add(ColorMaterial::from(color)), + transform, + ..default() + }, + pickable: PickableBundle::default(), + draggable: Draggable, + }) + .with_children(|c| { + c.spawn_bundle(Text2dBundle { + text: Text::from_section( + &index.to_string(), + TextStyle { + font: font.clone(), + font_size: 32., + color: Color::WHITE, + }, + ) + .with_alignment(TextAlignment::CENTER), + transform: Transform::from_xyz(0., 0., 1.), + ..Default::default() + }); + }); +} + pub fn spawn_stored_level( commands: &mut Commands, meshes: &mut ResMut>, @@ -137,8 +191,6 @@ pub fn spawn_stored_level( stored_level: &StoredLevel, ) { - let _font = asset_server.get_handle::("UacariLegacy-Thin.ttf"); - for platform in stored_level.platforms.iter() { spawn_platform( commands, @@ -148,6 +200,18 @@ pub fn spawn_stored_level( platform.size, ); } + + for (i, character) in stored_level.characters.iter().enumerate() { + spawn_character( + commands, + meshes, + materials, + asset_server, + Transform::from_xyz(character.pos.x, character.pos.y, 0.), + character.color.into(), + i, + ); + } } // Systems @@ -182,7 +246,7 @@ fn setup( } } -fn keyboard_input_system( +fn move_system( keyboard_input: Res>, mut camera_query: Query<&mut Transform, (With, Without)>, mut drag_query: Query<(&mut Transform, &Selection, Option<&End>), With>,