sdl works
This commit is contained in:
parent
15baba8cbb
commit
086fcf6dd9
10
README.md
10
README.md
@ -1,3 +1,13 @@
|
||||
|
||||
# web-stack-project
|
||||
|
||||
## Dependencies
|
||||
|
||||
SDL2, SDL-mixer and SDL-image
|
||||
|
||||
### Debian
|
||||
|
||||
```
|
||||
sudo apt install libsdl2-2.0-0 libsdl2-dev libsdl2-image-2.0-0 libsdl2-image-dev libsdl2-mixer-2.0-0 libsdl2-mixer-dev
|
||||
```
|
||||
|
||||
|
@ -40,7 +40,9 @@ impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_element(&mut self) -> Result<Node, ParserError> {}
|
||||
fn parse_element(&mut self) -> Result<Node, ParserError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn parse_value(&mut self) -> Result<Node, ParserError> {
|
||||
match self.current() {
|
||||
@ -70,19 +72,20 @@ impl Parser {
|
||||
Ok(Node::Object(values))
|
||||
}
|
||||
Some(t @ (Token::Name(_) | Token::String(_))) => {
|
||||
let key = match t {
|
||||
Token::Name(v) => v,
|
||||
Token::String(v) => &v[1..v.len() - 1].to_string(),
|
||||
_ => panic!("checked by previous predicate"),
|
||||
};
|
||||
self.step();
|
||||
match self.current() {
|
||||
Some(Token::Equal(_) | Token::Colon(_)) => {}
|
||||
_ => return Err("expected ':' or '='".to_string()),
|
||||
}
|
||||
self.step();
|
||||
values[key] = Box::new(self.parse_value()?);
|
||||
self.parse_object_tail(values)
|
||||
// let key = match t {
|
||||
// Token::Name(v) => v,
|
||||
// Token::String(v) => &v[1..v.len() - 1].to_string(),
|
||||
// _ => panic!("checked by previous predicate"),
|
||||
// };
|
||||
// self.step();
|
||||
// match self.current() {
|
||||
// Some(Token::Equal(_) | Token::Colon(_)) => {}
|
||||
// _ => return Err("expected ':' or '='".to_string()),
|
||||
// }
|
||||
// self.step();
|
||||
// values[key] = Box::new(self.parse_value()?);
|
||||
// self.parse_object_tail(values)
|
||||
todo!()
|
||||
}
|
||||
_ => Err("expected Name, String or '}'".to_string()),
|
||||
}
|
||||
@ -103,18 +106,19 @@ impl Parser {
|
||||
break Ok(Node::Object(values));
|
||||
}
|
||||
Some(t @ (Token::Name(_) | Token::String(_))) => {
|
||||
let key = match t {
|
||||
Token::Name(v) => v,
|
||||
Token::String(v) => &v[1..v.len() - 1].to_string(),
|
||||
_ => panic!("unterminated object, checked by previous predicate"),
|
||||
};
|
||||
self.step();
|
||||
match self.current() {
|
||||
Some(Token::Equal(_) | Token::Colon(_)) => {}
|
||||
_ => return Err("expected ':' or '='".to_string()),
|
||||
}
|
||||
self.step();
|
||||
values[key] = Box::new(self.parse_value()?);
|
||||
// let key = match t {
|
||||
// Token::Name(v) => v,
|
||||
// Token::String(v) => &v[1..v.len() - 1].to_string(),
|
||||
// _ => panic!("unterminated object, checked by previous predicate"),
|
||||
// };
|
||||
// self.step();
|
||||
// match self.current() {
|
||||
// Some(Token::Equal(_) | Token::Colon(_)) => {}
|
||||
// _ => return Err("expected ':' or '='".to_string()),
|
||||
// }
|
||||
// self.step();
|
||||
// values[key] = Box::new(self.parse_value()?);
|
||||
todo!()
|
||||
}
|
||||
_ => {
|
||||
break Err(
|
||||
@ -136,6 +140,10 @@ impl Parser {
|
||||
self.step();
|
||||
Ok(Node::Array(values))
|
||||
}
|
||||
Some(_) => {
|
||||
values.push(self.parse_value()?);
|
||||
todo!()
|
||||
}
|
||||
_ => Err("unterminated array, expected Value or ']'".to_string()),
|
||||
}
|
||||
}
|
||||
|
40
src/main.rs
40
src/main.rs
@ -1,5 +1,43 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use sdl2::{event::Event, keyboard::Keycode, pixels::Color};
|
||||
|
||||
mod bong;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
let sdl_context = sdl2::init().unwrap();
|
||||
let video_subsystem = sdl_context.video().unwrap();
|
||||
|
||||
let window = video_subsystem
|
||||
.window("rust-sdl2 demo", 800, 600)
|
||||
.position_centered()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let mut canvas = window.into_canvas().build().unwrap();
|
||||
|
||||
canvas.set_draw_color(Color::RGB(0, 255, 255));
|
||||
canvas.clear();
|
||||
canvas.present();
|
||||
let mut event_pump = sdl_context.event_pump().unwrap();
|
||||
let mut i = 0;
|
||||
'running: loop {
|
||||
i = (i + 1) % 255;
|
||||
canvas.set_draw_color(Color::RGB(i, 64, 255 - i));
|
||||
canvas.clear();
|
||||
for event in event_pump.poll_iter() {
|
||||
match event {
|
||||
Event::Quit { .. }
|
||||
| Event::KeyDown {
|
||||
keycode: Some(Keycode::Escape),
|
||||
..
|
||||
} => break 'running,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
// The rest of the game loop goes here...
|
||||
|
||||
canvas.present();
|
||||
::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user