A Quadrilateral Cowboy clone intended to help me learn Game Dev

Added console input display correctly, need to actually parse it now

+41 -30
+41 -30
src/level.rs
··· 23 23 #[derive(Component, Default)] 24 24 struct CurrentInput(String); 25 25 26 + enum ConsoleEntry { 27 + Command(String), 28 + Error(String), 29 + Output(String) 30 + } 31 + 26 32 #[derive(Component, Default)] 27 - struct ConsoleHistory(String); 33 + struct ConsoleHistory(Vec<ConsoleEntry>); 28 34 29 35 #[derive(Component)] 30 36 struct TerminalText; ··· 110 116 Node{ 111 117 width: percent(100), 112 118 height: percent(100), 113 - flex_direction: FlexDirection::Column, 114 - justify_content: JustifyContent::Center, 115 - align_items: AlignItems::Center, 119 + align_items: AlignItems::Start, 116 120 ..default() 117 121 }, 118 122 BackgroundColor(bevy::color::palettes::css::BLACK.into()), 119 123 UiTargetCamera(texture_camera) 120 124 )).with_children(|parent| { 121 125 parent.spawn(( 122 - Node{ 123 - position_type: PositionType::Absolute, 124 - width: Val::Auto, 125 - height: Val::Auto, 126 - align_items: AlignItems::Center, 127 - padding: UiRect::all(Val::Px(20.)), 128 - border_radius: BorderRadius::all(Val::Px(10.)), 126 + Text::new(""), 127 + TextFont{ 128 + font_size: 14.0, 129 + font: asset_server.load("fonts/NotoMono.ttf"), 129 130 ..default() 130 131 }, 131 - BackgroundColor(bevy::color::palettes::css::BLUE.into()) 132 - )).with_children(|parent| { 133 - parent.spawn(( 134 - Text::new("hi\nbevy!"), 135 - TextFont{ 136 - font_size: 40.0, 137 - font: asset_server.load("fonts/NotoMono.ttf"), 138 - ..default() 139 - }, 140 - Underline, 141 - TextColor::WHITE, 142 - TerminalText 143 - )); 144 - }); 132 + TextColor::WHITE, 133 + TerminalText 134 + )); 145 135 }); 146 136 147 137 let material_handle = materials.add(StandardMaterial{ ··· 192 182 } 193 183 194 184 fn check_input(mut keyboard_input_reader: MessageReader<KeyboardInput>, mut query: Query<(&mut CurrentInput, &Terminal, &mut ConsoleHistory)>, mut terminal_query: Query<(&mut Text, &TerminalText)>) { 185 + let mut current_input = query.single_mut().unwrap(); 186 + let mut current_terminal_text = terminal_query.single_mut().unwrap(); 187 + 195 188 for keyboard_input in keyboard_input_reader.read() { 196 189 if !keyboard_input.state.is_pressed() { 197 190 continue; 198 191 } 199 192 200 - let mut current_input = query.single_mut().unwrap(); 193 + current_terminal_text.0.0.clear(); 201 194 202 195 match (&keyboard_input.logical_key, &keyboard_input.text) { 203 196 (Key::Enter, _) => { ··· 205 198 continue; 206 199 } 207 200 208 - let _old_value = current_input.0.0.clone(); 209 - 201 + current_input.2.0.push(ConsoleEntry::Command(current_input.0.0.to_owned())); 202 + current_input.0.0.clear(); 203 + // TODO: Process input 210 204 }, 211 205 (Key::Backspace, _) => { 212 206 current_input.0.0.pop(); ··· 219 213 _ => continue, 220 214 } 221 215 222 - let mut current_terminal_text = terminal_query.single_mut().unwrap(); 223 - current_terminal_text.0.0 = current_input.0.0.clone(); 216 + for entry in current_input.2.0.iter() { 217 + match entry { 218 + ConsoleEntry::Command(cmd) => { 219 + current_terminal_text.0.0 += cmd; 220 + }, 221 + ConsoleEntry::Output(output) => { 222 + current_terminal_text.0.0 += output; 223 + // TODO: Need to figure out how to change color of text line-by-line 224 + }, 225 + ConsoleEntry::Error(error) => { 226 + current_terminal_text.0.0 += error; 227 + // TODO: Need to figure out how to change color of text line-by-line 228 + } 229 + } 230 + 231 + current_terminal_text.0.0 += "\n"; 232 + } 233 + 234 + current_terminal_text.0.0 += &current_input.0.0; 224 235 } 225 236 } 226 237