add separate sort order field to levels, so they can be reordered without changing the id and invalidating solutions

This commit is contained in:
Crispy 2024-10-07 12:04:55 +02:00
parent 90bc93fa02
commit e43a422708
6 changed files with 27 additions and 11 deletions

View file

@ -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
}

View file

@ -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
}