make blueprint id a number instead of string

This commit is contained in:
Crispy 2024-10-11 23:38:35 +02:00
parent 52288bdf6c
commit e88f945e8f
2 changed files with 8 additions and 8 deletions

View file

@ -10,7 +10,7 @@ use crate::{marble_engine::board::Board, userdata_dir};
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Blueprint { pub struct Blueprint {
id: String, id: usize,
pub name: String, pub name: String,
pub board: String, pub board: String,
#[serde(skip, default)] #[serde(skip, default)]
@ -18,17 +18,17 @@ pub struct Blueprint {
} }
impl Blueprint { impl Blueprint {
pub fn new(content: &Board, number: usize) -> Self { pub fn new(content: &Board, id: usize) -> Self {
Self { Self {
id: format!("blueprint_{number}"), id,
name: format!("Blueprint {number}"), name: format!("Blueprint {id}"),
board: content.to_string(), board: content.to_string(),
tile_board: Some(content.clone()), tile_board: Some(content.clone()),
} }
} }
pub fn id(&self)->&String{ pub fn id(&self) -> usize {
&self.id self.id
} }
pub fn convert_board(&mut self) -> &Board { pub fn convert_board(&mut self) -> &Board {
@ -45,7 +45,7 @@ impl Blueprint {
fn path(&self) -> PathBuf { fn path(&self) -> PathBuf {
let dir = userdata_dir().join("blueprints"); let dir = userdata_dir().join("blueprints");
fs::create_dir_all(&dir).unwrap(); fs::create_dir_all(&dir).unwrap();
dir.join(format!("{}.json", &self.id)) dir.join(format!("blueprint_{}.json", &self.id))
} }
pub fn save(&self) { pub fn save(&self) {

View file

@ -283,7 +283,7 @@ impl Editor {
let mut id = 0; let mut id = 0;
'outer: loop { 'outer: loop {
for b in &self.blueprints { for b in &self.blueprints {
if b.id() == &format!("blueprint_{id}") { if b.id() == id {
id += 1; id += 1;
continue 'outer; continue 'outer;
} }