From ae42cd10a460c4bf4bbc9599b4a10dfd8ec3ed75 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sat, 29 Mar 2025 00:48:14 +0100 Subject: [PATCH] fix comment line spacing, add comments to first level --- levels/chapter_01.json | 9 ++++++++- src/board.rs | 13 +++++++++---- src/editor.rs | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/levels/chapter_01.json b/levels/chapter_01.json index 4e6c18a..81c6a2d 100644 --- a/levels/chapter_01.json +++ b/levels/chapter_01.json @@ -5,7 +5,14 @@ "id": "output", "name": "Zero", "description": "learn how to output data", - "init_board": "\n o \n\n I\n\n", + "init_board": { + "comments": [ + { "text": "Welcome :3", "x": 3, "y": 0 }, + { "text": "< This is a marble,\n it will move down when you start the machine", "x": 3, "y": 2 }, + { "text": "< This is an input/output silo\n when a marble enters it, it disappears\n and the value it held is added to the level output", "x": 3, "y": 5 } + ], + "grid": "\n\n o \n\n\n I\n\n\n" + }, "stages": [{ "input": [], "output": [0] diff --git a/src/board.rs b/src/board.rs index a253178..0017248 100644 --- a/src/board.rs +++ b/src/board.rs @@ -73,11 +73,16 @@ impl Board { pub fn draw_comments(&self, d: &mut RaylibDrawHandle, offset: Vector2, scale: f32) { let tile_size = (TILE_TEXTURE_SIZE * scale) as i32; + let font_size = 10 * (scale as i32).max(1); + let line_space = 12 * (scale as i32).max(1); - for c in &self.comments { - let px = c.x * tile_size + offset.x as i32; - let py = c.y * tile_size + offset.y as i32; - d.draw_text(&c.text, px, py, 10 * scale as i32, Color::ORANGE); + for comment in &self.comments { + let x = comment.x * tile_size + offset.x as i32; + let y = comment.y * tile_size + offset.y as i32; + for (i, line) in comment.text.lines().enumerate() { + let y = y + line_space * i as i32; + d.draw_text(&line, x, y, font_size, Color::ORANGE); + } } } diff --git a/src/editor.rs b/src/editor.rs index 36b50da..003d6b1 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -146,7 +146,7 @@ impl Editor { machine, sim_state: SimState::Editing, view_offset: Vector2::zero(), - zoom: 1., + zoom: 2., active_tool: Tool::None, output_as_text, input_as_text,