From 67557832fa660a2c952ff9ea136a4a89c8a10a6d Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Thu, 10 Oct 2024 20:51:19 +0200 Subject: [PATCH] add more levels and organise them into sections --- README.md | 17 ++++++++------- .../{01_zero.json => 01_intro/01_output.json} | 6 +++--- levels/01_intro/02_digits.json | 9 ++++++++ levels/01_intro/03_loop.json | 9 ++++++++ .../04_copy_input.json} | 4 ++-- levels/01_intro/05_copy_odd.json | 9 ++++++++ levels/01_loop.json | 9 -------- levels/02_lists/count_fives.json | 9 ++++++++ levels/02_lists/list_length.json | 9 ++++++++ levels/02_lists/null_separation.json | 11 ++++++++++ levels/02_lists/reverse_input.json | 11 ++++++++++ src/main.rs | 21 +++++++++++++------ 12 files changed, 96 insertions(+), 28 deletions(-) rename levels/{01_zero.json => 01_intro/01_output.json} (51%) create mode 100644 levels/01_intro/02_digits.json create mode 100644 levels/01_intro/03_loop.json rename levels/{01_cat.json => 01_intro/04_copy_input.json} (86%) create mode 100644 levels/01_intro/05_copy_odd.json delete mode 100644 levels/01_loop.json create mode 100644 levels/02_lists/count_fives.json create mode 100644 levels/02_lists/list_length.json create mode 100644 levels/02_lists/null_separation.json create mode 100644 levels/02_lists/reverse_input.json diff --git a/README.md b/README.md index 1f20aa1..4dd547a 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble story/lore timestamps in solutions and blueprints multiple input/output sets +undo/redo tooltips lock tile types for early levels to make it less overwhelming make a gui alternative to pressing R to rotate between tile variants @@ -79,16 +80,16 @@ blueprint rotation? ## levels ### intro, basic mechanics -- output a zero -- output two numbers in sequence -- output zeroes forever (looping) -- copy the input -- copy only odd input numbers +- output a zero (marble, io) +- output multiple numbers in sequence (digits) +- output zeroes forever (looping, trigger, bag output) +- copy the input (input) +- copy only odd input numbers (comparator, flipper) ### 0-terminated list processing -- calculate list length +- calculate list length (math, bag input) - count instances of 5 in a list -- copy the second list (ignore input until first zero) -- reverse a list +- copy the second list +- reverse a list (bouncing) ### user-friendly numbers - convert a number to decimal ascii - parse an ascii number diff --git a/levels/01_zero.json b/levels/01_intro/01_output.json similarity index 51% rename from levels/01_zero.json rename to levels/01_intro/01_output.json index 7de9959..e2ef487 100644 --- a/levels/01_zero.json +++ b/levels/01_intro/01_output.json @@ -1,9 +1,9 @@ { - "id": "intro_output", - "sort_order": 10, + "id": "output", + "sort_order": 11, "name": "Zero", "description": "learn how to output data", - "init_board": "o o\n \n*P \n \n \n ", + "init_board": "\n o \n\n I\n\n", "inputs": [], "outputs": [0] } \ No newline at end of file diff --git a/levels/01_intro/02_digits.json b/levels/01_intro/02_digits.json new file mode 100644 index 0000000..5f29471 --- /dev/null +++ b/levels/01_intro/02_digits.json @@ -0,0 +1,9 @@ +{ + "id": "digits", + "sort_order": 12, + "name": "Digits", + "description": "place digits and use number keys to assign them values", + "init_board": null, + "inputs": [], + "outputs": [4, 8, 16] +} \ No newline at end of file diff --git a/levels/01_intro/03_loop.json b/levels/01_intro/03_loop.json new file mode 100644 index 0000000..e097900 --- /dev/null +++ b/levels/01_intro/03_loop.json @@ -0,0 +1,9 @@ +{ + "id": "loop", + "sort_order": 13, + "name": "Loop", + "description": "repeated output", + "init_board": "\n \n o\n\n\n\n ^ \n\n", + "inputs": [], + "outputs": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] +} \ No newline at end of file diff --git a/levels/01_cat.json b/levels/01_intro/04_copy_input.json similarity index 86% rename from levels/01_cat.json rename to levels/01_intro/04_copy_input.json index 39a6b5e..62da9a1 100644 --- a/levels/01_cat.json +++ b/levels/01_intro/04_copy_input.json @@ -1,6 +1,6 @@ { - "id": "intro_copy_input", - "sort_order": 12, + "id": "copy_input", + "sort_order": 14, "name": "Copy Cat", "description": "read input and output the same thing", "init_board": null, diff --git a/levels/01_intro/05_copy_odd.json b/levels/01_intro/05_copy_odd.json new file mode 100644 index 0000000..7db2780 --- /dev/null +++ b/levels/01_intro/05_copy_odd.json @@ -0,0 +1,9 @@ +{ + "id": "copy_odd", + "sort_order": 15, + "name": "Odd Cat", + "description": "copy only the odd numbers from the input", + "init_board": null, + "inputs": [112, 92, 51, 79, 112, 96, 84, 59, 195, 208, 137, 196, 68, 204, 82, 148, 251, 56, 105, 38, 63, 204, 240, 220, 180, 54, 211, 17, 82, 17, 181, 43], + "outputs": [51, 79, 59, 195, 137, 251, 105, 63, 211, 17, 17, 181, 43] +} \ No newline at end of file diff --git a/levels/01_loop.json b/levels/01_loop.json deleted file mode 100644 index 960b5c8..0000000 --- a/levels/01_loop.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "id": "intro_loop", - "sort_order": 11, - "name": "Loop", - "description": "repeated output", - "init_board": "o o\n \n*P \n \n \n ", - "inputs": [], - "outputs": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] -} \ No newline at end of file diff --git a/levels/02_lists/count_fives.json b/levels/02_lists/count_fives.json new file mode 100644 index 0000000..088445a --- /dev/null +++ b/levels/02_lists/count_fives.json @@ -0,0 +1,9 @@ +{ + "id": "count_fives", + "sort_order": 22, + "name": "Fives", + "description": "count how many fives are in the input", + "init_board": null, + "inputs": [182, 236, 71, 5, 5, 242, 29, 99, 19, 230, 217, 5, 67, 5, 223, 224, 70, 243, 3, 74, 242, 5, 171, 31, 96, 5, 169, 70, 5, 163, 72, 5, 172, 148, 5, 208, 28, 220, 17, 184, 172, 238, 5, 105, 119, 5, 106, 100, 73, 53, 42, 221, 155, 5, 74, 100, 161, 36, 16, 239, 193, 164, 64, 162, 222, 155, 107, 14, 45, 52, 159, 31, 199, 124, 129, 0], + "outputs": [12] +} \ No newline at end of file diff --git a/levels/02_lists/list_length.json b/levels/02_lists/list_length.json new file mode 100644 index 0000000..3ea9674 --- /dev/null +++ b/levels/02_lists/list_length.json @@ -0,0 +1,9 @@ +{ + "id": "list_length", + "sort_order": 21, + "name": "Length", + "description": "count how many numbers are in the input, until the first zero", + "init_board": null, + "inputs": [182, 236, 71, 5, 5, 242, 29, 99, 19, 230, 217, 5, 67, 5, 223, 224, 70, 243, 3, 74, 242, 5, 171, 31, 96, 5, 169, 70, 5, 163, 72, 5, 172, 148, 5, 208, 28, 220, 17, 184, 172, 238, 5, 105, 119, 5, 106, 100, 73, 53, 42, 221, 155, 5, 74, 100, 161, 36, 16, 239, 193, 164, 64, 162, 222, 155, 107, 14, 45, 52, 159, 31, 199, 124, 129, 0], + "outputs": [75] +} \ No newline at end of file diff --git a/levels/02_lists/null_separation.json b/levels/02_lists/null_separation.json new file mode 100644 index 0000000..5f2c52f --- /dev/null +++ b/levels/02_lists/null_separation.json @@ -0,0 +1,11 @@ +{ + "id": "null_separation", + "sort_order": 23, + "name": "Null Separation", + "description": "output everything after the first zero in the input data", + "init_board": null, + "inputs": [199, 34, 71, 209, 4, 0, 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 103, 33, 0], + "outputs": [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 103, 33], + "input_is_text": true, + "output_is_text": true +} \ No newline at end of file diff --git a/levels/02_lists/reverse_input.json b/levels/02_lists/reverse_input.json new file mode 100644 index 0000000..ff1fa56 --- /dev/null +++ b/levels/02_lists/reverse_input.json @@ -0,0 +1,11 @@ +{ + "id": "reverse_input", + "sort_order": 24, + "name": "Reverse", + "description": "read input until zero and output the same thing in reverse", + "init_board": null, + "inputs": [116, 110, 114, 111, 112, 109, 105, 32, 121, 114, 101, 118, 0], + "outputs": [118, 101, 114, 121, 32, 105, 109, 112, 111, 114, 110, 116], + "input_is_text": true, + "output_is_text": true +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 06ecfc6..43d43c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -94,7 +94,7 @@ impl Game { fn draw(&mut self, d: &mut RaylibDrawHandle) { d.clear_background(Color::new(64, 64, 64, 255)); - let level_list_width = d.get_screen_width() / 3; + let level_list_width = (d.get_screen_width() / 3).min(400); let screen_height = d.get_screen_height(); d.draw_rectangle(0, 0, level_list_width, screen_height, Color::GRAY); @@ -230,21 +230,30 @@ impl Game { fn get_levels() -> Vec { let mut levels = Vec::::new(); - for d in read_dir("levels").unwrap().flatten() { - let l = read_to_string(d.path()) + let mut add_level = |path| { + let l = read_to_string(path) .ok() .as_deref() .and_then(|s| serde_json::from_str(s).ok()); if let Some(level) = l { levels.push(level); } + }; + for d in read_dir("levels").unwrap().flatten() { + if d.path().is_dir() { + for d in read_dir(d.path()).unwrap().flatten() { + add_level(d.path()); + } + } else { + add_level(d.path()); + } } levels.sort_by_key(Level::sort_order); levels } fn get_solutions() -> HashMap> { - let mut levels = HashMap::new(); + let mut by_level = HashMap::new(); let solution_dir = userdata_dir().join("solutions"); if let Ok(dir_contents) = read_dir(solution_dir) { for dir in dir_contents.flatten() { @@ -263,11 +272,11 @@ fn get_solutions() -> HashMap> { } } - levels.insert(level_name, solutions); + by_level.insert(level_name, solutions); } } } } - levels + by_level }