diff --git a/index.html b/index.html index e56164b..cb0059b 100644 --- a/index.html +++ b/index.html @@ -28,6 +28,10 @@ label { margin-bottom: 8px; } +.ability-scores .field input { + width: 65px; +} + #character-class { width: 130px; } diff --git a/src/ability_scores.rs b/src/ability_scores.rs new file mode 100644 index 0000000..560ef71 --- /dev/null +++ b/src/ability_scores.rs @@ -0,0 +1,139 @@ +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), +} + +pub struct AbilityScores { + link: yew::ComponentLink, + + strength: i32, + dexterity: i32, + constitution: i32, + intelligence: i32, + wisdom: i32, + charisma: i32, +} + +impl yew::Component for AbilityScores { + type Message = Message; + type Properties = (); + + fn create(_props: Self::Properties, link: yew::ComponentLink) -> Self { + Self { + link, + strength: 10, + dexterity: 10, + constitution: 10, + intelligence: 10, + wisdom: 10, + charisma: 10, + } + } + + 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::Dexterity(yew::ChangeData::Value(dexterity)) => { + self.dexterity = dexterity.parse().unwrap_or(10); + } + Message::Constitution(yew::ChangeData::Value(constitution)) => { + self.constitution = constitution.parse().unwrap_or(10); + } + Message::Intelligence(yew::ChangeData::Value(intelligence)) => { + self.intelligence = intelligence.parse().unwrap_or(10); + } + Message::Wisdom(yew::ChangeData::Value(wisdom)) => { + self.wisdom = wisdom.parse().unwrap_or(10); + } + Message::Charisma(yew::ChangeData::Value(charisma)) => { + self.charisma = charisma.parse().unwrap_or(10); + } + _ => { + ConsoleService::log(&format!("{:?}", message)); + return false; + } + } + + true + } + + fn change(&mut self, _props: Self::Properties) -> yew::ShouldRender { + false + } + + fn view(&self) -> yew::Html { + yew::html! { +
+
+ + {(self.strength - 10) / 2} + +
+
+ + {(self.dexterity - 10) / 2} + +
+
+ + {(self.constitution - 10) / 2} + +
+
+ + {(self.intelligence - 10) / 2} + +
+
+ + {(self.wisdom - 10) / 2} + +
+
+ + {(self.charisma - 10) / 2} + +
+
+ } + } +} diff --git a/src/character_info.rs b/src/character_info.rs new file mode 100644 index 0000000..453e580 --- /dev/null +++ b/src/character_info.rs @@ -0,0 +1,79 @@ +pub enum Message {} + +pub struct CharacterInfo { + _link: yew::ComponentLink, +} + +impl yew::Component for CharacterInfo { + type Message = Message; + type Properties = (); + + fn create(_props: Self::Properties, link: yew::ComponentLink) -> Self { + Self { _link: link } + } + + fn update(&mut self, _msg: Self::Message) -> yew::ShouldRender { + false + } + + fn change(&mut self, _props: Self::Properties) -> yew::ShouldRender { + false + } + + fn view(&self) -> yew::Html { + yew::html! { +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ } + } +} diff --git a/src/main.rs b/src/main.rs index 53c5eec..e64f09c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,27 +1,23 @@ -enum Msg { - AddOne, +mod ability_scores; +mod character_info; + +use ability_scores::AbilityScores; +use character_info::CharacterInfo; + +struct Page { + _link: yew::ComponentLink, } -struct Model { - link: yew::ComponentLink, - value: i64, -} - -impl yew::Component for Model { - type Message = Msg; +impl yew::Component for Page { + type Message = (); type Properties = (); fn create(_props: Self::Properties, link: yew::ComponentLink) -> Self { - Self { link, value: 0 } + Self { _link: link } } - fn update(&mut self, msg: Self::Message) -> yew::ShouldRender { - match msg { - Msg::AddOne => { - self.value += 1; - true - } - } + fn update(&mut self, _msg: Self::Message) -> yew::ShouldRender { + false } fn change(&mut self, _props: Self::Properties) -> yew::ShouldRender { @@ -30,62 +26,14 @@ impl yew::Component for Model { fn view(&self) -> yew::Html { yew::html! { -
-
- - -
-
-
-
- - -
-
- - -
-
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
+
+ +
} } } fn main() { - yew::start_app::(); + yew::start_app::(); }