diff --git a/Makefile b/Makefile index 3b83568..0bf8477 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ test: .PHONY: run run: - cargo run + cargo run -- game.ayin .PHONY: review review: diff --git a/game.ayin b/game.ayin new file mode 100644 index 0000000..5790989 --- /dev/null +++ b/game.ayin @@ -0,0 +1,19 @@ +let setup = fn() { + return { + .player: { .position: { .x: 10, .y: 20 }, }, + }; +}; + +let update = fn(state, input) { + let new = 100; + state.player.position.x = new; + return state; +}; + +let draw = fn(frame, state) { + frame.clear(0,0,0); +}; + +let migrate = fn(state) { + return { .player: { .pos: state.player.position } }; +}; diff --git a/src/main.rs b/src/main.rs index 57d636e..6965ef0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -use ayin::ast; use ayin::runtime::*; use macroquad::prelude::*; @@ -17,12 +16,23 @@ async fn main() { env_logger::init(); info!("Hello, 👁️‍🗨️!"); - let mut state = setup(ast::Program(vec![])).await; + let args: Vec = std::env::args().collect(); + let file = args[1].clone(); - loop { - let events = fetch_events(); - update(&mut state, events); - draw(&state); - next_frame().await; + match std::fs::read_to_string(file) { + Err(err) => println!("Error: {err:#?}"), + Ok(txt) => match ayin::parser::parse_file(txt) { + Err(err) => println!("Error: {err:#?}"), + Ok(program) => { + let mut state = setup(program).await; + + loop { + let events = fetch_events(&mut state); + update(&mut state, events); + draw(&state); + next_frame().await; + } + } + }, } } diff --git a/src/runtime/runtime.rs b/src/runtime/runtime.rs index c2b5955..5ce600f 100644 --- a/src/runtime/runtime.rs +++ b/src/runtime/runtime.rs @@ -1,5 +1,6 @@ use super::types::*; use crate::ast; +use crate::ast::helpers; use crate::interpret; use gamepads; use macroquad::prelude::*; @@ -64,7 +65,39 @@ pub async fn migrate(mut state: State, code: ast::Program) -> State { } } -pub fn update(_state: &mut State, input: Input) {} +pub fn update(state: &mut State, input: Input) { + let input = helpers::record(vec![( + "gamepad1", + helpers::record(vec![ + ( + "buttons", + helpers::record(vec![ + ("a", input.gamepad1.buttons.a.into()), + ("b", input.gamepad1.buttons.b.into()), + ("x", input.gamepad1.buttons.x.into()), + ("y", input.gamepad1.buttons.y.into()), + ]), + ), + ( + "dpad", + helpers::record(vec![ + ("left", input.gamepad1.dpad.left.into()), + ("right", input.gamepad1.dpad.right.into()), + ("up", input.gamepad1.dpad.up.into()), + ("down", input.gamepad1.dpad.down.into()), + ]), + ), + ]), + )]); + match interpret::interpret( + &mut state.state, + "update".into(), + vec![ast::Expr::Value(state.game_state.clone()), input], + ) { + Ok(_) => {} + Err(err) => println!("Error: {}", err), + } +} pub fn fetch_events(state: &mut State) -> Input { state.gamepads.poll(); @@ -117,4 +150,9 @@ pub fn draw(state: &State) { }); set_default_camera(); + + println!( + "{:#?}", + interpret::value_to_stadnalone_expr(&state.state, state.game_state.clone()) + ); } diff --git a/src/runtime/types.rs b/src/runtime/types.rs index c434c36..a089026 100644 --- a/src/runtime/types.rs +++ b/src/runtime/types.rs @@ -90,7 +90,7 @@ pub struct Menu { pub menu: bool, } -pub const SCALE: i32 = 4; +pub const SCALE: i32 = 1; pub const SCREEN_WIDTH: i32 = 360 * SCALE; pub const SCREEN_HEIGHT: i32 = 360 * SCALE;