make blueprint id a number instead of string
This commit is contained in:
parent
52288bdf6c
commit
e88f945e8f
2 changed files with 8 additions and 8 deletions
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue