convert int IDs to strings

This commit is contained in:
2020-06-18 14:44:20 +01:00
parent e895f932a6
commit fe6f3f5c84
7 changed files with 57 additions and 56 deletions

View File

@@ -1,9 +1,8 @@
use crate::colour::Colour;
use crate::{from_base36, ToBase36};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Palette {
pub id: u64,
pub id: String,
pub name: Option<String>,
pub colours: Vec<Colour>,
}
@@ -13,7 +12,7 @@ impl From<String> for Palette {
fn from(string: String) -> Palette {
let lines: Vec<&str> = string.lines().collect();
let id = from_base36(&lines[0].replace("PAL ", ""));
let id = lines[0].replace("PAL ", "");
let name = match lines[1].starts_with("NAME") {
true => Some(lines[1].replace("NAME ", "").to_string()),
@@ -46,7 +45,7 @@ impl ToString for Palette {
}
colours.pop();
format!("PAL {}\n{}{}", self.id.to_base36(), name, colours)
format!("PAL {}\n{}{}", self.id, name, colours)
}
}
@@ -60,7 +59,7 @@ mod test {
let output = Palette::from("PAL 1\nNAME lamplight\n45,45,59\n66,60,39\n140,94,1".to_string());
let expected = Palette {
id: 1,
id: "1".to_string(),
name: Some("lamplight".to_string()),
colours: vec![
Colour {
@@ -89,7 +88,7 @@ mod test {
let output = Palette::from("PAL 9\n45,45,59\n66,60,39\n140,94,1".to_string());
let expected = Palette {
id: 9,
id: "9".to_string(),
name: None,
colours: vec![
Colour {
@@ -116,7 +115,7 @@ mod test {
#[test]
fn test_palette_to_string() {
let output = Palette {
id: 16,
id: "g".to_string(),
name: Some("moss".to_string()),
colours: vec![
Colour {