sdl works
This commit is contained in:
parent
15baba8cbb
commit
086fcf6dd9
10
README.md
10
README.md
@ -1,3 +1,13 @@
|
|||||||
|
|
||||||
# web-stack-project
|
# 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> {
|
fn parse_value(&mut self) -> Result<Node, ParserError> {
|
||||||
match self.current() {
|
match self.current() {
|
||||||
@ -70,19 +72,20 @@ impl Parser {
|
|||||||
Ok(Node::Object(values))
|
Ok(Node::Object(values))
|
||||||
}
|
}
|
||||||
Some(t @ (Token::Name(_) | Token::String(_))) => {
|
Some(t @ (Token::Name(_) | Token::String(_))) => {
|
||||||
let key = match t {
|
// let key = match t {
|
||||||
Token::Name(v) => v,
|
// Token::Name(v) => v,
|
||||||
Token::String(v) => &v[1..v.len() - 1].to_string(),
|
// Token::String(v) => &v[1..v.len() - 1].to_string(),
|
||||||
_ => panic!("checked by previous predicate"),
|
// _ => panic!("checked by previous predicate"),
|
||||||
};
|
// };
|
||||||
self.step();
|
// self.step();
|
||||||
match self.current() {
|
// match self.current() {
|
||||||
Some(Token::Equal(_) | Token::Colon(_)) => {}
|
// Some(Token::Equal(_) | Token::Colon(_)) => {}
|
||||||
_ => return Err("expected ':' or '='".to_string()),
|
// _ => return Err("expected ':' or '='".to_string()),
|
||||||
}
|
// }
|
||||||
self.step();
|
// self.step();
|
||||||
values[key] = Box::new(self.parse_value()?);
|
// values[key] = Box::new(self.parse_value()?);
|
||||||
self.parse_object_tail(values)
|
// self.parse_object_tail(values)
|
||||||
|
todo!()
|
||||||
}
|
}
|
||||||
_ => Err("expected Name, String or '}'".to_string()),
|
_ => Err("expected Name, String or '}'".to_string()),
|
||||||
}
|
}
|
||||||
@ -103,18 +106,19 @@ impl Parser {
|
|||||||
break Ok(Node::Object(values));
|
break Ok(Node::Object(values));
|
||||||
}
|
}
|
||||||
Some(t @ (Token::Name(_) | Token::String(_))) => {
|
Some(t @ (Token::Name(_) | Token::String(_))) => {
|
||||||
let key = match t {
|
// let key = match t {
|
||||||
Token::Name(v) => v,
|
// Token::Name(v) => v,
|
||||||
Token::String(v) => &v[1..v.len() - 1].to_string(),
|
// Token::String(v) => &v[1..v.len() - 1].to_string(),
|
||||||
_ => panic!("unterminated object, checked by previous predicate"),
|
// _ => panic!("unterminated object, checked by previous predicate"),
|
||||||
};
|
// };
|
||||||
self.step();
|
// self.step();
|
||||||
match self.current() {
|
// match self.current() {
|
||||||
Some(Token::Equal(_) | Token::Colon(_)) => {}
|
// Some(Token::Equal(_) | Token::Colon(_)) => {}
|
||||||
_ => return Err("expected ':' or '='".to_string()),
|
// _ => return Err("expected ':' or '='".to_string()),
|
||||||
}
|
// }
|
||||||
self.step();
|
// self.step();
|
||||||
values[key] = Box::new(self.parse_value()?);
|
// values[key] = Box::new(self.parse_value()?);
|
||||||
|
todo!()
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
break Err(
|
break Err(
|
||||||
@ -136,6 +140,10 @@ impl Parser {
|
|||||||
self.step();
|
self.step();
|
||||||
Ok(Node::Array(values))
|
Ok(Node::Array(values))
|
||||||
}
|
}
|
||||||
|
Some(_) => {
|
||||||
|
values.push(self.parse_value()?);
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
_ => Err("unterminated array, expected Value or ']'".to_string()),
|
_ => 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;
|
mod bong;
|
||||||
|
|
||||||
fn main() {
|
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