diff --git a/.gitignore b/.gitignore index 88f5115..472c342 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,6 @@ Cargo.lock # асеты -assets/**/* +#assets/**/* !assets/shaders/ !assets/shaders/**/* diff --git a/Cargo.toml b/Cargo.toml index 0737146..d5a9bad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,11 @@ version = "0.1.0" edition = "2024" [dependencies] +bevy = "0.18" + +[profildev] +opt-level = 1 +debug = true + +[profile.dev.package."*"] +opt-level = 3 diff --git a/assets/fonts/Baskerville Bold Italic.ttf b/assets/fonts/Baskerville Bold Italic.ttf new file mode 100644 index 0000000..26fd4bd Binary files /dev/null and b/assets/fonts/Baskerville Bold Italic.ttf differ diff --git a/assets/scene/ChessDelights _ Resource For Online Chess Guides,Learning Chess, Free Chess Tools And More.jpeg b/assets/scene/ChessDelights _ Resource For Online Chess Guides,Learning Chess, Free Chess Tools And More.jpeg new file mode 100644 index 0000000..f0b8fbb Binary files /dev/null and b/assets/scene/ChessDelights _ Resource For Online Chess Guides,Learning Chess, Free Chess Tools And More.jpeg differ diff --git a/assets/scene/chessboard.png b/assets/scene/chessboard.png new file mode 100644 index 0000000..944a32d Binary files /dev/null and b/assets/scene/chessboard.png differ diff --git a/assets/scene/chessboard.png~ b/assets/scene/chessboard.png~ new file mode 100644 index 0000000..4ae126b Binary files /dev/null and b/assets/scene/chessboard.png~ differ diff --git a/src/main.rs b/src/main.rs index e7a11a9..e6cdaa4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,111 @@ +use bevy::{prelude::*, ui::RelativeCursorPosition}; + fn main() { println!("Hello, world!"); + + App::new() + .add_plugins(DefaultPlugins.set(WindowPlugin { + primary_window: Some(Window { + resolution: (800, 800).into(), + title: "local-chess".into(), + ..default() + }), + ..default() + })) + .add_systems(Startup, setup) + .add_systems(Update, relative_cursor_position_system) + .run(); } + +fn setup(mut commands: Commands, assets: Res) { + commands.spawn(Camera2d); + commands + .spawn(( + + Node { + width: percent(100), + height: percent(100), + ..default() + }, + + Sprite::from_image(assets.load("scene/chessboard.png")) + )) + .insert(RelativeCursorPosition::default()); + commands + .spawn(Node { + width: percent(100), + height: percent(100), + align_items: AlignItems::Center, + justify_content: JustifyContent::Center, + flex_direction: FlexDirection::Column, + ..default() + }) + .with_children(|parent| { + parent.spawn(( + Text::new("who"), + TextFont { + font: assets.load("fonts/Baskerville Bold Italic.ttf").into(), + //font_size: FontSize::Px(33.0), + font_size: 50.0, + ..default() + }, + TextColor(Color::srgb(0.1, 0.1, 0.1)), + )); + }); +} + +fn relative_cursor_position_system(rcp: Single<&RelativeCursorPosition>, text: Single<&mut Text>){ + let mut output_text = text.into_inner(); + if let Some(pos) = rcp.normalized{ + let x = ((pos.x + 0.5) * 10.0) as i8; + let mut coordinate_x: char; + match x { + 1 => {coordinate_x = 'a'} + 2 => {coordinate_x = 'b'} + 3 => {coordinate_x = 'c'} + 4 => {coordinate_x = 'd'} + 5 => {coordinate_x = 'e'} + 6 => {coordinate_x = 'f'} + 7 => {coordinate_x = 'g'} + 8 => {coordinate_x = 'h'} + _ => {coordinate_x = ' '} + } + + let y = ((pos.y * -1. + 0.5) * 10.0) as i8; + let mut coordinate_y: char; + match y { + 1 => {coordinate_y = '1'} + 2 => {coordinate_y = '2'} + 3 => {coordinate_y = '3'} + 4 => {coordinate_y = '4'} + 5 => {coordinate_y = '5'} + 6 => {coordinate_y = '6'} + 7 => {coordinate_y = '7'} + 8 => {coordinate_y = '8'} + _ => {coordinate_y = ' '} + } + ** output_text = format!("{}{}", coordinate_x, coordinate_y); + } else { + ** output_text = "uncnown".to_string(); + } +} +/* +fn relative_cursor_position_system( + relative_cursor_position: Single<&RelativeCursorPosition>, + output_query: Single<(&mut Text, &mut TextColor)>, +) { + let (mut output, mut text_color) = output_query.into_inner(); + + **output = if let Some(relative_cursor_position) = relative_cursor_position.normalized { + format!( + "({}, {})", + relative_cursor_position.x, relative_cursor_position.y + ) + } else { + "unknown".to_string() + }; +} + +#[derive(Component)] +pub struct Chess {} +*/