Updated spells, cleaned up duration spell schema
This commit is contained in:
@@ -38,11 +38,9 @@ diesel::table! {
|
||||
components_materials_needed -> Nullable<Text>,
|
||||
components_materials_cost -> Nullable<Integer>,
|
||||
components_materials_consumed -> Nullable<Bool>,
|
||||
duration_type -> Text,
|
||||
duration_amount -> Nullable<Integer>,
|
||||
duration_unit -> Nullable<Text>,
|
||||
durations -> Jsonb,
|
||||
classes -> Array<Text>,
|
||||
sources -> Array<Text>,
|
||||
sources -> Jsonb,
|
||||
tags -> Array<Text>,
|
||||
description -> Jsonb
|
||||
}
|
||||
|
||||
@@ -31,11 +31,9 @@ pub struct QuerySpell {
|
||||
pub components_materials_needed: Option<String>,
|
||||
pub components_materials_cost: Option<i32>,
|
||||
pub components_materials_consumed: Option<bool>,
|
||||
pub duration_type: String,
|
||||
pub duration_amount: Option<i32>,
|
||||
pub duration_unit: Option<String>,
|
||||
pub durations: serde_json::Value,
|
||||
pub classes: Vec<String>,
|
||||
pub sources: Vec<String>,
|
||||
pub sources: serde_json::Value,
|
||||
pub tags: Vec<String>,
|
||||
pub description: serde_json::Value
|
||||
}
|
||||
@@ -97,11 +95,9 @@ pub struct InsertSpell {
|
||||
pub components_materials_needed: Option<String>,
|
||||
pub components_materials_cost: Option<i32>,
|
||||
pub components_materials_consumed: Option<bool>,
|
||||
pub duration_type: String,
|
||||
pub duration_amount: Option<i32>,
|
||||
pub duration_unit: Option<String>,
|
||||
pub durations: serde_json::Value,
|
||||
pub classes: Vec<String>,
|
||||
pub sources: Vec<String>,
|
||||
pub sources: serde_json::Value,
|
||||
pub tags: Vec<String>,
|
||||
pub description: serde_json::Value
|
||||
}
|
||||
@@ -139,7 +135,7 @@ pub struct Spell {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub area: Option<Area>,
|
||||
pub components: Components,
|
||||
pub duration: Duration,
|
||||
pub durations: Vec<Duration>,
|
||||
pub classes: Vec<String>,
|
||||
pub sources: Vec<Source>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@@ -436,33 +432,6 @@ pub enum DurationType {
|
||||
Special
|
||||
}
|
||||
|
||||
impl DurationType {
|
||||
pub fn to_string(&self) -> String {
|
||||
match self {
|
||||
DurationType::Concentration => "concentration".to_string(),
|
||||
DurationType::Instantaneous => "instantaneous".to_string(),
|
||||
DurationType::Timed => "timed".to_string(),
|
||||
DurationType::UntilDispelled => "dispelled".to_string(),
|
||||
DurationType::Special => "special".to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for DurationType {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"concentration" => Ok(DurationType::Concentration),
|
||||
"instantaneous" => Ok(DurationType::Instantaneous),
|
||||
"timed" => Ok(DurationType::Timed),
|
||||
"dispelled" => Ok(DurationType::UntilDispelled),
|
||||
"special" => Ok(DurationType::Special),
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Source {
|
||||
pub source: String,
|
||||
@@ -631,22 +600,21 @@ impl From<QuerySpell> for Spell {
|
||||
materials_cost: query.components_materials_cost,
|
||||
materials_consumed: query.components_materials_consumed
|
||||
},
|
||||
duration: Duration {
|
||||
duration_type: match DurationType::from_str(&query.duration_type) {
|
||||
Ok(duration_type) => duration_type,
|
||||
Err(_) => {
|
||||
log::error!("Failed to parse spell duration type: {}", query.duration_type);
|
||||
DurationType::Special
|
||||
}
|
||||
},
|
||||
amount: query.duration_amount,
|
||||
unit: query.duration_unit
|
||||
durations: match serde_json::from_value(query.durations) {
|
||||
Ok(durations) => durations,
|
||||
Err(err) => {
|
||||
log::error!("Failed to parse spell durations: {}", err);
|
||||
Vec::new()
|
||||
}
|
||||
},
|
||||
classes: query.classes,
|
||||
sources: query.sources.iter().map(|source| Source {
|
||||
source: source.to_string(),
|
||||
page: None
|
||||
}).collect(),
|
||||
sources: match serde_json::from_value(query.sources) {
|
||||
Ok(sources) => sources,
|
||||
Err(err) => {
|
||||
log::error!("Failed to parse spell sources: {}", err);
|
||||
Vec::new()
|
||||
}
|
||||
},
|
||||
tags: Some(query.tags),
|
||||
description: match serde_json::from_value(query.description) {
|
||||
Ok(description) => description,
|
||||
@@ -708,9 +676,7 @@ impl Into<InsertSpell> for Spell {
|
||||
components_materials_needed: self.components.materials_needed,
|
||||
components_materials_cost: self.components.materials_cost,
|
||||
components_materials_consumed: self.components.materials_consumed,
|
||||
duration_type: self.duration.duration_type.to_string(),
|
||||
duration_amount: self.duration.amount,
|
||||
duration_unit: self.duration.unit,
|
||||
durations: serde_json::to_value(self.durations).unwrap(),
|
||||
classes: self.classes,
|
||||
sources: self.sources.iter().map(|source| match source.page { Some(page) => format!("{} {}", source.source, page), None => source.source.to_string() }).collect(),
|
||||
tags: match self.tags {
|
||||
|
||||
Reference in New Issue
Block a user