diff --git a/index.html b/index.html index cb0059b..0dfb1e7 100644 --- a/index.html +++ b/index.html @@ -13,21 +13,22 @@ body { font-family: "Ubuntu", sans-serif; } -label { - display: block; - font-weight: bold; -} - .field { margin: 0 8px; } .field label { + display: block; + font-weight: bold; font-size: 0.8em; font-variant: small-caps; margin-bottom: 8px; } +.field label.label-inline { + display: inline; +} + .ability-scores .field input { width: 65px; } diff --git a/src/ability_scores.rs b/src/ability_scores.rs index 560ef71..5510085 100644 --- a/src/ability_scores.rs +++ b/src/ability_scores.rs @@ -2,12 +2,21 @@ use yew::services::console::ConsoleService; #[derive(Debug)] pub enum Message { - Strength(yew::ChangeData), - Dexterity(yew::ChangeData), - Constitution(yew::ChangeData), - Intelligence(yew::ChangeData), - Wisdom(yew::ChangeData), - Charisma(yew::ChangeData), + StrengthScore(yew::ChangeData), + DexterityScore(yew::ChangeData), + ConstitutionScore(yew::ChangeData), + IntelligenceScore(yew::ChangeData), + WisdomScore(yew::ChangeData), + CharismaScore(yew::ChangeData), + + ProficiencyBonus(yew::ChangeData), + + ProficiencyStrengthSaving(yew::ChangeData), + ProficiencyDexteritySaving(yew::ChangeData), + ProficiencyConstitutionSaving(yew::ChangeData), + ProficiencyIntelligenceSaving(yew::ChangeData), + ProficiencyWisdomSaving(yew::ChangeData), + ProficiencyCharismaSaving(yew::ChangeData), } pub struct AbilityScores { @@ -19,6 +28,99 @@ pub struct AbilityScores { intelligence: i32, wisdom: i32, charisma: i32, + + proficiency_bonus: i32, + + proficiency_strength_saving: bool, + proficiency_dexterity_saving: bool, + proficiency_constitution_saving: bool, + proficiency_intelligence_saving: bool, + proficiency_wisdom_saving: bool, + proficiency_charisma_saving: bool, +} + +impl AbilityScores { + fn score_to_modifier(score: i32) -> i32 { + (score - 10) / 2 + } + + pub fn strength_modifier(&self) -> i32 { + Self::score_to_modifier(self.strength) + } + + pub fn dexterity_modifier(&self) -> i32 { + Self::score_to_modifier(self.dexterity) + } + + pub fn constitution_modifier(&self) -> i32 { + Self::score_to_modifier(self.constitution) + } + + pub fn intelligence_modifier(&self) -> i32 { + Self::score_to_modifier(self.intelligence) + } + + pub fn wisdom_modifier(&self) -> i32 { + Self::score_to_modifier(self.wisdom) + } + + pub fn charisma_modifier(&self) -> i32 { + Self::score_to_modifier(self.charisma) + } + + pub fn strength_saving(&self) -> i32 { + Self::score_to_modifier(self.strength) + + if self.proficiency_strength_saving { + self.proficiency_bonus + } else { + 0 + } + } + + pub fn dexterity_saving(&self) -> i32 { + Self::score_to_modifier(self.dexterity) + + if self.proficiency_dexterity_saving { + self.proficiency_bonus + } else { + 0 + } + } + + pub fn constitution_saving(&self) -> i32 { + Self::score_to_modifier(self.constitution) + + if self.proficiency_constitution_saving { + self.proficiency_bonus + } else { + 0 + } + } + + pub fn intelligence_saving(&self) -> i32 { + Self::score_to_modifier(self.intelligence) + + if self.proficiency_intelligence_saving { + self.proficiency_bonus + } else { + 0 + } + } + + pub fn wisdom_saving(&self) -> i32 { + Self::score_to_modifier(self.wisdom) + + if self.proficiency_wisdom_saving { + self.proficiency_bonus + } else { + 0 + } + } + + pub fn charisma_saving(&self) -> i32 { + Self::score_to_modifier(self.charisma) + + if self.proficiency_charisma_saving { + self.proficiency_bonus + } else { + 0 + } + } } impl yew::Component for AbilityScores { @@ -28,37 +130,68 @@ impl yew::Component for AbilityScores { fn create(_props: Self::Properties, link: yew::ComponentLink) -> Self { Self { link, + strength: 10, dexterity: 10, constitution: 10, intelligence: 10, wisdom: 10, charisma: 10, + + proficiency_bonus: 2, + + proficiency_strength_saving: false, + proficiency_dexterity_saving: false, + proficiency_constitution_saving: false, + proficiency_intelligence_saving: false, + proficiency_wisdom_saving: false, + proficiency_charisma_saving: false, } } fn update(&mut self, message: Self::Message) -> yew::ShouldRender { match message { - Message::Strength(yew::ChangeData::Value(strength)) => { - self.strength = strength.parse().unwrap_or(10); + Message::StrengthScore(yew::ChangeData::Value(value)) => { + self.strength = value.parse().unwrap_or(10); } - Message::Dexterity(yew::ChangeData::Value(dexterity)) => { - self.dexterity = dexterity.parse().unwrap_or(10); + Message::DexterityScore(yew::ChangeData::Value(value)) => { + self.dexterity = value.parse().unwrap_or(10); } - Message::Constitution(yew::ChangeData::Value(constitution)) => { - self.constitution = constitution.parse().unwrap_or(10); + Message::ConstitutionScore(yew::ChangeData::Value(value)) => { + self.constitution = value.parse().unwrap_or(10); } - Message::Intelligence(yew::ChangeData::Value(intelligence)) => { - self.intelligence = intelligence.parse().unwrap_or(10); + Message::IntelligenceScore(yew::ChangeData::Value(value)) => { + self.intelligence = value.parse().unwrap_or(10); } - Message::Wisdom(yew::ChangeData::Value(wisdom)) => { - self.wisdom = wisdom.parse().unwrap_or(10); + Message::WisdomScore(yew::ChangeData::Value(value)) => { + self.wisdom = value.parse().unwrap_or(10); } - Message::Charisma(yew::ChangeData::Value(charisma)) => { - self.charisma = charisma.parse().unwrap_or(10); + Message::CharismaScore(yew::ChangeData::Value(value)) => { + self.charisma = value.parse().unwrap_or(10); + } + Message::ProficiencyBonus(yew::ChangeData::Value(value)) => { + self.proficiency_bonus = value.parse().unwrap_or(2); + } + Message::ProficiencyStrengthSaving(_) => { + self.proficiency_strength_saving = !self.proficiency_strength_saving; + } + Message::ProficiencyDexteritySaving(_) => { + self.proficiency_dexterity_saving = !self.proficiency_dexterity_saving; + } + Message::ProficiencyConstitutionSaving(_) => { + self.proficiency_constitution_saving = !self.proficiency_constitution_saving; + } + Message::ProficiencyIntelligenceSaving(_) => { + self.proficiency_intelligence_saving = !self.proficiency_intelligence_saving; + } + Message::ProficiencyWisdomSaving(_) => { + self.proficiency_wisdom_saving = !self.proficiency_wisdom_saving; + } + Message::ProficiencyCharismaSaving(_) => { + self.proficiency_charisma_saving = !self.proficiency_charisma_saving; } _ => { - ConsoleService::log(&format!("{:?}", message)); + ConsoleService::error(&format!("{:?}", message)); return false; } } @@ -72,66 +205,192 @@ impl yew::Component for AbilityScores { fn view(&self) -> yew::Html { yew::html! { -
-
- - {(self.strength - 10) / 2} - +
+
+
+ + {self.strength_modifier()} + +
+
+ + {self.dexterity_modifier()} + +
+
+ + {self.constitution_modifier()} + +
+
+ + {self.intelligence_modifier()} + +
+
+ + {self.wisdom_modifier()} + +
+
+ + {self.charisma_modifier()} + +
-
- - {(self.dexterity - 10) / 2} - -
-
- - {(self.constitution - 10) / 2} - -
-
- - {(self.intelligence - 10) / 2} - -
-
- - {(self.wisdom - 10) / 2} - -
-
- - {(self.charisma - 10) / 2} - +
+
+ + +
+
+ + +
+ +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
}