From e88f945e8f8db0b85935284842bfe1ab566f61c0 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Fri, 11 Oct 2024 23:38:35 +0200 Subject: [PATCH] make blueprint id a number instead of string --- src/blueprint.rs | 14 +++++++------- src/editor.rs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/blueprint.rs b/src/blueprint.rs index 3bdd4b0..5cc6d4b 100644 --- a/src/blueprint.rs +++ b/src/blueprint.rs @@ -10,7 +10,7 @@ use crate::{marble_engine::board::Board, userdata_dir}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Blueprint { - id: String, + id: usize, pub name: String, pub board: String, #[serde(skip, default)] @@ -18,17 +18,17 @@ pub struct Blueprint { } impl Blueprint { - pub fn new(content: &Board, number: usize) -> Self { + pub fn new(content: &Board, id: usize) -> Self { Self { - id: format!("blueprint_{number}"), - name: format!("Blueprint {number}"), + id, + name: format!("Blueprint {id}"), board: content.to_string(), tile_board: Some(content.clone()), } } - pub fn id(&self)->&String{ - &self.id + pub fn id(&self) -> usize { + self.id } pub fn convert_board(&mut self) -> &Board { @@ -45,7 +45,7 @@ impl Blueprint { fn path(&self) -> PathBuf { let dir = userdata_dir().join("blueprints"); fs::create_dir_all(&dir).unwrap(); - dir.join(format!("{}.json", &self.id)) + dir.join(format!("blueprint_{}.json", &self.id)) } pub fn save(&self) { diff --git a/src/editor.rs b/src/editor.rs index 8dead71..7f26c2e 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -283,7 +283,7 @@ impl Editor { let mut id = 0; 'outer: loop { for b in &self.blueprints { - if b.id() == &format!("blueprint_{id}") { + if b.id() == id { id += 1; continue 'outer; }