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 deleted file mode 100644 index f0b8fbb..0000000 Binary files a/assets/scene/ChessDelights _ Resource For Online Chess Guides,Learning Chess, Free Chess Tools And More.jpeg and /dev/null differ diff --git a/assets/scene/chessboard.png b/assets/scene/chessboard.png index 944a32d..b821401 100644 Binary files a/assets/scene/chessboard.png and b/assets/scene/chessboard.png differ diff --git a/assets/scene/chessboard.png~ b/assets/scene/chessboard.png~ deleted file mode 100644 index 4ae126b..0000000 Binary files a/assets/scene/chessboard.png~ and /dev/null differ diff --git a/src/main.rs b/src/main.rs index e6cdaa4..9638f91 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,17 +20,29 @@ fn main() { fn setup(mut commands: Commands, assets: Res) { commands.spawn(Camera2d); commands - .spawn(( + .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(( + Node { + width: px(512), + height: px(512), + margin: UiRect::bottom(px(15)), + ..default() + }, + ImageNode::new(assets.load("scene/chessboard.png")), - Node { - width: percent(100), - height: percent(100), - ..default() - }, + )) + .insert(RelativeCursorPosition::default()); +}); - Sprite::from_image(assets.load("scene/chessboard.png")) - )) - .insert(RelativeCursorPosition::default()); commands .spawn(Node { width: percent(100), @@ -38,74 +50,47 @@ fn setup(mut commands: Commands, assets: Res) { align_items: AlignItems::Center, justify_content: JustifyContent::Center, flex_direction: FlexDirection::Column, + left: percent(-40.0), + top: percent(-40.0), ..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)), + TextColor(Color::srgb(1.0, 0.5, 1.0)), + )); }); } fn relative_cursor_position_system(rcp: Single<&RelativeCursorPosition>, text: Single<&mut Text>){ + //let ratio; + let is_white = true; 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 = ' '} + let mut x = ((pos.x + 0.5) * 8.0) as usize + 1; + let mut y; + if is_white { + y = ((pos.y - 0.5) * -8.0 ) as usize + 1; + } else { + y = ((pos.y + 0.5) * 8.0) as usize + 1; } - ** output_text = format!("{}{}", coordinate_x, coordinate_y); + let m = ((y - 1) * 8) + x-1; + x = (pos.x > -0.5 && pos.x < 0.5) as usize * x; + let cx = [' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; + y = (pos.y > -0.5 && pos.y < 0.5) as usize * y; + let cy = [' ', '1', '2', '3', '4', '5', '6', '7', '8']; + + ** output_text = format!("{}|{}|{}", cx[x], cy[y], m); } else { - ** output_text = "uncnown".to_string(); + ** output_text = " ".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 {} -*/