use std::fmt;
use std::str::FromStr;
use uuid::Uuid;
use super::error::{Error, Result};
#[derive(Debug, Clone)]
pub struct ProductionItem {
pub uuid: Uuid,
pub path: Option<String>,
}
impl ProductionItem {
pub fn new(uuid: &str) -> Result<Self> {
Ok(Self {
uuid: Uuid::parse_str(uuid)?,
path: None,
})
}
pub fn with_uuid() -> Self {
Self {
uuid: Uuid::new_v4(),
path: None,
}
}
pub fn with_path(uuid: &str, path: impl Into<String>) -> Result<Self> {
Ok(Self {
uuid: Uuid::parse_str(uuid)?,
path: Some(path.into()),
})
}
pub fn set_uuid(&mut self, uuid: &str) -> Result<()> {
self.uuid = Uuid::parse_str(uuid)?;
Ok(())
}
pub fn set_path(&mut self, path: impl Into<String>) {
self.path = Some(path.into());
}
}
#[derive(Debug, Clone)]
pub struct ProductionComponent {
pub uuid: Uuid,
pub path: Option<String>,
}
impl ProductionComponent {
pub fn new(uuid: &str) -> Result<Self> {
Ok(Self {
uuid: Uuid::parse_str(uuid)?,
path: None,
})
}
pub fn with_uuid() -> Self {
Self {
uuid: Uuid::new_v4(),
path: None,
}
}
pub fn with_path(uuid: &str, path: impl Into<String>) -> Result<Self> {
Ok(Self {
uuid: Uuid::parse_str(uuid)?,
path: Some(path.into()),
})
}
pub fn set_uuid(&mut self, uuid: &str) -> Result<()> {
self.uuid = Uuid::parse_str(uuid)?;
Ok(())
}
pub fn set_path(&mut self, path: impl Into<String>) {
self.path = Some(path.into());
}
}
#[derive(Debug, Clone)]
pub struct ProductionObject {
pub uuid: Uuid,
pub model_resolution: ModelResolution,
}
impl ProductionObject {
pub fn new(uuid: &str) -> Result<Self> {
Ok(Self {
uuid: Uuid::parse_str(uuid)?,
model_resolution: ModelResolution::default(),
})
}
pub fn with_uuid() -> Self {
Self {
uuid: Uuid::new_v4(),
model_resolution: ModelResolution::default(),
}
}
pub fn with_resolution(uuid: &str, resolution: ModelResolution) -> Result<Self> {
Ok(Self {
uuid: Uuid::parse_str(uuid)?,
model_resolution: resolution,
})
}
pub fn set_resolution(&mut self, resolution: ModelResolution) {
self.model_resolution = resolution;
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum ModelResolution {
#[default]
FullRes,
LowRes,
Obfuscated,
}
impl fmt::Display for ModelResolution {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ModelResolution::FullRes => write!(f, "fullres"),
ModelResolution::LowRes => write!(f, "lowres"),
ModelResolution::Obfuscated => write!(f, "obfuscated"),
}
}
}
impl FromStr for ModelResolution {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
match s.to_lowercase().as_str() {
"fullres" => Ok(ModelResolution::FullRes),
"lowres" => Ok(ModelResolution::LowRes),
"obfuscated" => Ok(ModelResolution::Obfuscated),
_ => Err(Error::InvalidAttribute {
name: "modelresolution".to_string(),
message: format!("unknown model resolution: {}", s),
}),
}
}
}
#[derive(Debug, Clone, Default)]
pub struct Alternatives {
pub alternatives: Vec<Alternative>,
}
impl Alternatives {
pub fn new() -> Self {
Self::default()
}
pub fn add(&mut self, alternative: Alternative) {
self.alternatives.push(alternative);
}
pub fn len(&self) -> usize {
self.alternatives.len()
}
pub fn is_empty(&self) -> bool {
self.alternatives.is_empty()
}
}
#[derive(Debug, Clone)]
pub struct Alternative {
pub object_id: u32,
pub uuid: Uuid,
pub path: Option<String>,
pub model_resolution: ModelResolution,
}
impl Alternative {
pub fn new(object_id: u32, uuid: &str) -> Result<Self> {
Ok(Self {
object_id,
uuid: Uuid::parse_str(uuid)?,
path: None,
model_resolution: ModelResolution::default(),
})
}
pub fn with_path(object_id: u32, uuid: &str, path: impl Into<String>) -> Result<Self> {
Ok(Self {
object_id,
uuid: Uuid::parse_str(uuid)?,
path: Some(path.into()),
model_resolution: ModelResolution::default(),
})
}
pub fn with_resolution(object_id: u32, uuid: &str, resolution: ModelResolution) -> Result<Self> {
Ok(Self {
object_id,
uuid: Uuid::parse_str(uuid)?,
path: None,
model_resolution: resolution,
})
}
pub fn set_path(&mut self, path: impl Into<String>) {
self.path = Some(path.into());
}
pub fn set_resolution(&mut self, resolution: ModelResolution) {
self.model_resolution = resolution;
}
}
#[derive(Debug, Clone)]
pub struct ProductionBuild {
pub uuid: Uuid,
}
impl ProductionBuild {
pub fn new(uuid: &str) -> Result<Self> {
Ok(Self {
uuid: Uuid::parse_str(uuid)?,
})
}
pub fn with_uuid() -> Self {
Self {
uuid: Uuid::new_v4(),
}
}
}