Clearer function names in new character flow.
This commit is contained in:
parent
7b4ffc3a02
commit
f34383d0c0
|
@ -39,7 +39,7 @@ pub(crate) trait Visibility {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(DbEnum, Debug, Serialize, PartialEq)]
|
||||
#[derive(DbEnum, Debug, Serialize, PartialEq, Clone, Copy)]
|
||||
pub enum CharacterDataType {
|
||||
ChroniclesOfDarknessV1,
|
||||
ChangelingV1,
|
||||
|
|
|
@ -10,8 +10,8 @@ mod new;
|
|||
pub(crate) fn routes() -> Vec<rocket::Route> {
|
||||
routes![
|
||||
view_character,
|
||||
new::new_character,
|
||||
new::create_new_character,
|
||||
new::new_character_page,
|
||||
new::new_character_submit,
|
||||
new::new_character_not_logged_in,
|
||||
edit_character
|
||||
]
|
||||
|
|
|
@ -37,36 +37,20 @@ impl<'v> FromFormValue<'v> for CharacterDataType {
|
|||
}
|
||||
}
|
||||
|
||||
#[get("/new")]
|
||||
pub(super) fn new_character(
|
||||
logged_in_user: &User,
|
||||
conn: TenebrousDbConn,
|
||||
) -> Result<Template, Error> {
|
||||
let mut context = HashMap::new();
|
||||
let form = NewCharacterForm {
|
||||
name: "".to_string(),
|
||||
system: CharacterDataType::ChroniclesOfDarknessV1,
|
||||
};
|
||||
|
||||
context.insert("form", form);
|
||||
Ok(Template::render("characters/new_character", context))
|
||||
}
|
||||
|
||||
fn new_sheet(system: &CharacterDataType) -> Result<BytesMut, Error> {
|
||||
let sheet = match system {
|
||||
CharacterDataType::ChroniclesOfDarknessV1 => {
|
||||
let mut new_character = CofdSheet::default();
|
||||
new_character.strength = 100;
|
||||
let mut buf = BytesMut::with_capacity(std::mem::size_of_val(&new_character));
|
||||
new_character.encode(&mut buf)?;
|
||||
fn create_new_sheet(system: &CharacterDataType) -> Result<BytesMut, Error> {
|
||||
use CharacterDataType::*;
|
||||
let sheet: BytesMut = match system {
|
||||
ChroniclesOfDarknessV1 => {
|
||||
let sheet = CofdSheet::default();
|
||||
let mut buf = BytesMut::with_capacity(std::mem::size_of_val(&sheet));
|
||||
sheet.encode(&mut buf)?;
|
||||
buf
|
||||
}
|
||||
CharacterDataType::ChangelingV1 => {
|
||||
let mut new_character = ChangelingSheet::default();
|
||||
new_character.base = Some(CofdSheet::default());
|
||||
new_character.base.as_mut().unwrap().strength = 100;
|
||||
let mut buf = BytesMut::with_capacity(std::mem::size_of_val(&new_character));
|
||||
new_character.encode(&mut buf)?;
|
||||
ChangelingV1 => {
|
||||
let mut sheet = ChangelingSheet::default();
|
||||
sheet.base = Some(CofdSheet::default());
|
||||
let mut buf = BytesMut::with_capacity(std::mem::size_of_val(&sheet));
|
||||
sheet.encode(&mut buf)?;
|
||||
buf
|
||||
}
|
||||
};
|
||||
|
@ -74,12 +58,12 @@ fn new_sheet(system: &CharacterDataType) -> Result<BytesMut, Error> {
|
|||
Ok(sheet)
|
||||
}
|
||||
|
||||
fn do_new_character(
|
||||
fn create_new_character(
|
||||
form: Form<NewCharacterForm>,
|
||||
user_id: i32,
|
||||
conn: TenebrousDbConn,
|
||||
) -> Result<(), Error> {
|
||||
let sheet = new_sheet(&form.system)?;
|
||||
let sheet = create_new_sheet(&form.system)?;
|
||||
|
||||
let insert = NewCharacter {
|
||||
user_id: user_id,
|
||||
|
@ -94,8 +78,23 @@ fn do_new_character(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[get("/new")]
|
||||
pub(super) fn new_character_page(
|
||||
logged_in_user: &User,
|
||||
conn: TenebrousDbConn,
|
||||
) -> Result<Template, Error> {
|
||||
let mut context = HashMap::new();
|
||||
let form = NewCharacterForm {
|
||||
name: "".to_string(),
|
||||
system: CharacterDataType::ChroniclesOfDarknessV1,
|
||||
};
|
||||
|
||||
context.insert("form", form);
|
||||
Ok(Template::render("characters/new_character", context))
|
||||
}
|
||||
|
||||
#[post("/new", data = "<form>")]
|
||||
pub(super) fn create_new_character(
|
||||
pub(super) fn new_character_submit(
|
||||
form: Result<Form<NewCharacterForm>, FormError>,
|
||||
logged_in_user: &User,
|
||||
conn: TenebrousDbConn,
|
||||
|
@ -113,7 +112,7 @@ pub(super) fn create_new_character(
|
|||
return Err(Template::render("characters/new_character", context));
|
||||
}
|
||||
|
||||
match do_new_character(form.unwrap(), logged_in_user.id, conn) {
|
||||
match create_new_character(form.unwrap(), logged_in_user.id, conn) {
|
||||
Ok(_) => Ok(crate::routes::common::redirect_to_index()),
|
||||
Err(e) => {
|
||||
let context = HashMap::<String, String>::new();
|
||||
|
|
Loading…
Reference in New Issue