Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gbx-header"
version = "0.6.0"
version = "0.7.0"
authors = ["Markus Becker <mtib.becker@gmail.com>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
30 changes: 29 additions & 1 deletion src/gbx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ impl Default for MapType {
pub enum GBXVersion {
/// Unknown Type/Version
Unknown,
/// Challenge v5
TMc5,
/// Challenge v6
TMc6,
/// Replay v7
Expand All @@ -245,6 +247,7 @@ impl TryFrom<&str> for GBXVersion {

fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.to_lowercase().as_str() {
"tmc.5" => Ok(GBXVersion::TMc5),
"tmc.6" => Ok(GBXVersion::TMc6),
"tmr.7" => Ok(GBXVersion::TMr7),
_ => Err(format!("Unknown GBX file version: {}", value)),
Expand All @@ -256,6 +259,7 @@ impl GBXVersion {
/// Converts specific GBX file version and type (GBXVersion) into more generic GBXType.
pub fn content_type(&self) -> GBXType {
match self {
GBXVersion::TMc5 => GBXType::Challenge,
GBXVersion::TMc6 => GBXType::Challenge,
GBXVersion::TMr7 => GBXType::Replay,
GBXVersion::Unknown => GBXType::Unknown,
Expand All @@ -279,6 +283,12 @@ impl Default for GBXVersion {

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum Environment {
Alpine,
Bay,
Coast,
Island,
Rally,
Speed,
Stadium,
}

Expand All @@ -287,6 +297,12 @@ impl TryFrom<&str> for Environment {

fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.to_lowercase().as_str() {
"alpine" => Ok(Environment::Alpine),
"bay" => Ok(Environment::Bay),
"coast" => Ok(Environment::Coast),
"island" => Ok(Environment::Island),
"rally" => Ok(Environment::Rally),
"speed" => Ok(Environment::Speed),
"stadium" => Ok(Environment::Stadium),
_ => Err(format!("Unknown environment: {}", value)),
}
Expand All @@ -311,11 +327,17 @@ impl TryFrom<&str> for Mood {
type Error = String;

fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.to_lowercase().as_str() {
match value.trim().to_lowercase().as_str() {
"day" => Ok(Mood::Day),
"sunset" => Ok(Mood::Sunset),
"sunrise" => Ok(Mood::Sunrise),
"night" => Ok(Mood::Night),
"10x150sunrise" => Ok(Mood::Sunrise),
"20x60sunset" => Ok(Mood::Sunset),
"30x30" => Ok(Mood::Day),
"30x30sunrise" => Ok(Mood::Sunrise),
"30x30sunset" => Ok(Mood::Sunset),
"simple" => Ok(Mood::Day),
_ => Err(format!("Unknown mood: {}", value)),
}
}
Expand All @@ -329,15 +351,21 @@ impl Default for Mood {

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum DescType {
Platform,
Puzzle,
Race,
Stunts,
}

impl TryFrom<&str> for DescType {
type Error = String;

fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.to_lowercase().as_str() {
"platform" => Ok(DescType::Platform),
"puzzle" => Ok(DescType::Puzzle),
"race" => Ok(DescType::Race),
"stunts" => Ok(DescType::Stunts),
_ => Err(format!("Unknown desc.type: {}", value)),
}
}
Expand Down