Ability score stuff
This commit is contained in:
parent
89578e13b7
commit
418a2a7a3e
11
index.html
11
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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
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! {
|
||||
<div class="ability-scores">
|
||||
<div class="field">
|
||||
<input
|
||||
type="number"
|
||||
id="ability-strength"
|
||||
value={self.strength.to_string()}
|
||||
onchange=self.link.callback(|e| Message::Strength(e))
|
||||
/>
|
||||
{(self.strength - 10) / 2}
|
||||
<label for="ability-strength">{"Strength"}</label>
|
||||
<div class="columns">
|
||||
<div class="ability-scores">
|
||||
<div class="field">
|
||||
<input
|
||||
type="number"
|
||||
id="ability-strength"
|
||||
value={self.strength.to_string()}
|
||||
onchange=self.link.callback(Message::StrengthScore)
|
||||
/>
|
||||
{self.strength_modifier()}
|
||||
<label for="ability-strength">{"Strength"}</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="number"
|
||||
id="ability-dexterity"
|
||||
value={self.dexterity.to_string()}
|
||||
onchange=self.link.callback(Message::DexterityScore)
|
||||
/>
|
||||
{self.dexterity_modifier()}
|
||||
<label for="ability-dexterity">{"Dexterity"}</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="number"
|
||||
id="ability-constitution"
|
||||
value={self.constitution.to_string()}
|
||||
onchange=self.link.callback(Message::ConstitutionScore)
|
||||
/>
|
||||
{self.constitution_modifier()}
|
||||
<label for="ability-constitution">{"Constitution"}</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="number"
|
||||
id="ability-intelligence"
|
||||
value={self.intelligence.to_string()}
|
||||
onchange=self.link.callback(Message::IntelligenceScore)
|
||||
/>
|
||||
{self.intelligence_modifier()}
|
||||
<label for="ability-intelligence">{"Intelligence"}</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="number"
|
||||
id="ability-wisdom"
|
||||
value={self.wisdom.to_string()}
|
||||
onchange=self.link.callback(Message::WisdomScore)
|
||||
/>
|
||||
{self.wisdom_modifier()}
|
||||
<label for="ability-wisdom">{"Wisdom"}</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="number"
|
||||
id="ability-charisma"
|
||||
value={self.charisma.to_string()}
|
||||
onchange=self.link.callback(Message::CharismaScore)
|
||||
/>
|
||||
{self.charisma_modifier()}
|
||||
<label for="ability-charisma">{"Charisma"}</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="number"
|
||||
id="ability-dexterity"
|
||||
value={self.dexterity.to_string()}
|
||||
onchange=self.link.callback(|e| Message::Dexterity(e))
|
||||
/>
|
||||
{(self.dexterity - 10) / 2}
|
||||
<label for="ability-dexterity">{"Dexterity"}</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="number"
|
||||
id="ability-constitution"
|
||||
value={self.constitution.to_string()}
|
||||
onchange=self.link.callback(|e| Message::Constitution(e))
|
||||
/>
|
||||
{(self.constitution - 10) / 2}
|
||||
<label for="ability-constitution">{"Constitution"}</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="number"
|
||||
id="ability-intelligence"
|
||||
value={self.intelligence.to_string()}
|
||||
onchange=self.link.callback(|e| Message::Intelligence(e))
|
||||
/>
|
||||
{(self.intelligence - 10) / 2}
|
||||
<label for="ability-intelligence">{"Intelligence"}</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="number"
|
||||
id="ability-wisdom"
|
||||
value={self.wisdom.to_string()}
|
||||
onchange=self.link.callback(|e| Message::Wisdom(e))
|
||||
/>
|
||||
{(self.wisdom - 10) / 2}
|
||||
<label for="ability-wisdom">{"Wisdom"}</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="number"
|
||||
id="ability-charisma"
|
||||
value={self.charisma.to_string()}
|
||||
onchange=self.link.callback(|e| Message::Charisma(e))
|
||||
/>
|
||||
{(self.charisma - 10) / 2}
|
||||
<label for="ability-charisma">{"Charisma"}</label>
|
||||
<div>
|
||||
<div class="field">
|
||||
<input type="number" id="inspiration"/>
|
||||
<label class="label-inline" for="inspiration">
|
||||
{"Inspiration"}
|
||||
</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="number"
|
||||
id="proficiency-bonus"
|
||||
value={self.proficiency_bonus.to_string()}
|
||||
onchange=self.link.callback(Message::ProficiencyBonus)
|
||||
/>
|
||||
<label class="label-inline" for="proficiency-bonus">
|
||||
{"Proficiency Bonus"}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="proficiency-strength-saving"
|
||||
checked=self.proficiency_strength_saving
|
||||
onchange=self.link.callback(Message::ProficiencyStrengthSaving)
|
||||
/>
|
||||
<input
|
||||
type="number"
|
||||
disabled=true
|
||||
value=self.strength_saving().to_string()
|
||||
id="strength-saving"
|
||||
/>
|
||||
<label class="label-inline" for="proficiency-strength-saving">
|
||||
{"Strength"}
|
||||
</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="proficiency-dexterity-saving"
|
||||
checked=self.proficiency_dexterity_saving
|
||||
onchange=self.link.callback(Message::ProficiencyDexteritySaving)
|
||||
/>
|
||||
<input
|
||||
type="number"
|
||||
disabled=true
|
||||
value=self.dexterity_saving().to_string()
|
||||
id="dexterity-saving"
|
||||
/>
|
||||
<label class="label-inline" for="proficiency-dexterity-saving">
|
||||
{"Dexterity"}
|
||||
</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="proficiency-constitution-saving"
|
||||
checked=self.proficiency_constitution_saving
|
||||
onchange=self.link.callback(Message::ProficiencyConstitutionSaving)
|
||||
/>
|
||||
<input
|
||||
type="number"
|
||||
disabled=true
|
||||
value=self.constitution_saving().to_string()
|
||||
id="constitution-saving"
|
||||
/>
|
||||
<label class="label-inline" for="proficiency-constitution-saving">
|
||||
{"Constitution"}
|
||||
</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="proficiency-intelligence-saving"
|
||||
checked=self.proficiency_intelligence_saving
|
||||
onchange=self.link.callback(Message::ProficiencyIntelligenceSaving)
|
||||
/>
|
||||
<input
|
||||
type="number"
|
||||
disabled=true
|
||||
value=self.intelligence_saving().to_string()
|
||||
id="intelligence-saving"
|
||||
/>
|
||||
<label class="label-inline" for="proficiency-intelligence-saving">
|
||||
{"Intelligence"}
|
||||
</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="proficiency-wisdom-saving"
|
||||
checked=self.proficiency_wisdom_saving
|
||||
onchange=self.link.callback(Message::ProficiencyWisdomSaving)
|
||||
/>
|
||||
<input
|
||||
type="number"
|
||||
disabled=true
|
||||
value=self.wisdom_saving().to_string()
|
||||
id="wisdom-saving"
|
||||
/>
|
||||
<label class="label-inline" for="proficiency-wisdom-saving">
|
||||
{"Wisdom"}
|
||||
</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="proficiency-charisma-saving"
|
||||
checked=self.proficiency_charisma_saving
|
||||
onchange=self.link.callback(Message::ProficiencyCharismaSaving)
|
||||
/>
|
||||
<input
|
||||
type="number"
|
||||
disabled=true
|
||||
value=self.charisma_saving().to_string()
|
||||
id="charisma-saving"
|
||||
/>
|
||||
<label class="label-inline" for="proficiency-charisma-saving">
|
||||
{"Charisma"}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue