add separate sort order field to levels, so they can be reordered without changing the id and invalidating solutions
This commit is contained in:
parent
90bc93fa02
commit
e43a422708
6 changed files with 27 additions and 11 deletions
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"id": "00_zeroes",
|
||||
"name": "Zeroes",
|
||||
"description": "learn how to output data\nthis is a multi-line test",
|
||||
"init_board": null,
|
||||
"inputs": [],
|
||||
"outputs": [0, 0, 0, 0, 0, 0, 0, 0]
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
{
|
||||
"id": "01_cat",
|
||||
"id": "intro_copy_input",
|
||||
"sort_order": 12,
|
||||
"name": "Copy Cat",
|
||||
"description": "learn how to meow",
|
||||
"description": "read input and output the same thing",
|
||||
"init_board": null,
|
||||
"inputs": [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 103, 33],
|
||||
"outputs": [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 103, 33]
|
||||
|
|
9
levels/01_loop.json
Normal file
9
levels/01_loop.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"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]
|
||||
}
|
9
levels/01_zero.json
Normal file
9
levels/01_zero.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"id": "intro_output",
|
||||
"sort_order": 10,
|
||||
"name": "Zero",
|
||||
"description": "learn how to output data",
|
||||
"init_board": "o o\n \n*P \n \n \n ",
|
||||
"inputs": [],
|
||||
"outputs": [0]
|
||||
}
|
|
@ -3,6 +3,7 @@ use serde::Deserialize;
|
|||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Level {
|
||||
id: String,
|
||||
sort_order: i32,
|
||||
name: String,
|
||||
description: String,
|
||||
init_board: Option<String>,
|
||||
|
@ -15,6 +16,10 @@ impl Level {
|
|||
&self.id
|
||||
}
|
||||
|
||||
pub fn sort_order(&self) -> i32 {
|
||||
self.sort_order
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
|
|
@ -236,7 +236,7 @@ fn get_levels() -> Vec<Level> {
|
|||
levels.push(level);
|
||||
}
|
||||
}
|
||||
levels.sort_by(|a, b| a.id().cmp(b.id()));
|
||||
levels.sort_by(|a, b| a.sort_order().cmp(&b.sort_order()));
|
||||
levels
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue