tenebrous-sheets/src/models/proto/cofd.rs

99 lines
3.0 KiB
Rust

//! Contains the generated Chronicles of Darkness-related protocol
//! buffer types, as well as utilities and extensions for working with
//! them.
use crate::models::characters::CharacterDataType;
use std::collections::BTreeMap;
//Add the generated protobuf code into this module.
include!(concat!(env!("OUT_DIR"), "/models.proto.cofd.rs"));
//Add the API protobuf genreated code for the api module.
pub mod api {
include!(concat!(env!("OUT_DIR"), "/models.proto.cofd.api.rs"));
}
/// Default mental skill names for a regular Chronicles of Darkness
/// (or derivative system) game.
const MENTAL_SKILLS: &'static [&'static str] = &[
"Academics",
"Computer",
"Crafts",
"Investigation",
"Medicine",
"Occult",
"Politics",
"Science",
];
/// Default physical skill names for a regular Chronicles of Darkness
/// (or derivative system) game.
const PHYSICAL_SKILLS: &'static [&'static str] = &[
"Athletics",
"Brawl",
"Drive",
"Firearms",
"Larceny",
"Stealth",
"Survival",
"Weaponry",
];
/// Default social skill names for a regular Chronicles of Darkness
/// (or derivative system) game.
const SOCIAL_SKILLS: &'static [&'static str] = &[
"Animal Ken",
"Empathy",
"Expression",
"Intimidation",
"Persuasion",
"Socialize",
"Streetwise",
"Subterfuge",
];
/// Create a pre-populated skill list based on skill names given to
/// the function. The list of skill names is turned into a sorted Map
/// of skill name to default Skill protobuf instances.
fn create_skill_list(skill_names: &[&str]) -> BTreeMap<String, cofd_sheet::Skill> {
skill_names
.into_iter()
.map(|skill_name| (skill_name.to_string(), cofd_sheet::Skill::default()))
.collect()
}
impl CofdSheet {
/// Create the default (blank) character sheet for a Chronicles of
/// Darkness-based character. This fills in skills and other
/// information that needs to be pre-populated. System specifics
/// are set based on the given character data type (aka game
/// system).
pub fn default_sheet(system: CharacterDataType) -> CofdSheet {
let mut sheet = Self::default();
sheet.mental_skills = create_skill_list(&MENTAL_SKILLS);
sheet.physical_skills = create_skill_list(&PHYSICAL_SKILLS);
sheet.social_skills = create_skill_list(&SOCIAL_SKILLS);
use crate::models::proto::cofd::cofd_sheet::SystemFields;
let specifics: SystemFields = match system {
CharacterDataType::Changeling => SystemFields::Changeling(ChangelingFields::default()),
CharacterDataType::ChroniclesOfDarkness => SystemFields::Core(CoreFields::default()),
};
sheet.system_fields = Some(specifics);
sheet
}
}
// TODO these values are not available in tera templates, so how to
// handle?
pub(crate) trait DerivedStats {
fn speed(&self) -> i32;
}
impl DerivedStats for CofdSheet {
fn speed(&self) -> i32 {
self.size + self.stamina
}
}