This commit is contained in:
yaroslav k 2026-08-16 14:33:11 +03:00
parent 5e7cd0e709
commit ae2fa1c723
4 changed files with 38 additions and 17 deletions

View File

@ -6,6 +6,7 @@ mod image;
mod names; mod names;
mod about; mod about;
mod hit_points; mod hit_points;
mod armor_class;
mod hit_dice; mod hit_dice;
mod death_saving_throws; mod death_saving_throws;
mod spell_slots; mod spell_slots;
@ -20,6 +21,7 @@ pub fn Sidebar () -> impl IntoView {
<names::Names /> <names::Names />
<about::About /> <about::About />
<hit_points::HitPoints /> <hit_points::HitPoints />
<armor_class::ArmorClass />
<hit_dice::HitDice /> <hit_dice::HitDice />
<death_saving_throws::DeathSavingThrows /> <death_saving_throws::DeathSavingThrows />
<spell_slots::SpellSlots /> <spell_slots::SpellSlots />

View File

@ -0,0 +1,22 @@
use crate::prelude::*;
use leptos::prelude::*;
/// AC counter: for now is to be set manually
#[component]
pub fn ArmorClass () -> impl IntoView {
let state = expect_context::<Context>();
let player = state.player();
let ac = player.ac();
let adjust_ac = move |ev: Targeted<Event, HtmlInputElement>| {
utils::adjust_checked(ev, ac);
};
view! {
<h6>"ac/кд:"</h6>
<div class="ac">
<input min=0 title="Класс доспеха (вручную)" id="ac" type="number" class="header-input" on:input:target=move |e| adjust_ac(e) prop:value=move || ac.get() />
</div>
}
}

View File

@ -2,17 +2,16 @@ use crate::prelude::*;
use leptos::prelude::*; use leptos::prelude::*;
/// Current/max HP with a fill bar, plus temp HP with its own bar. /// Current/max HP with a fill bar, plus temp HP with its own bar.
/// All three numbers are editable `type="number"` inputs; AC sits /// All three numbers are editable `type="number"` inputs
/// next to them and is set manually.
#[component] #[component]
pub fn HitPoints () -> impl IntoView { pub fn HitPoints() -> impl IntoView {
let state = expect_context::<Context>(); let state = expect_context::<Context>();
let player = state.player(); let player = state.player();
let hp = player.hp(); let hp = player.hp();
let max_hp = player.max_hp(); let max_hp = player.max_hp();
let temp_hp = player.temp_hp(); let temp_hp = player.temp_hp();
let ac = player.ac();
// All three inputs parse via `utils::adjust_checked`; invalid text // All three inputs parse via `utils::adjust_checked`; invalid text
// restores the previous value. // restores the previous value.
@ -28,16 +27,10 @@ pub fn HitPoints () -> impl IntoView {
utils::adjust_checked(ev, temp_hp); utils::adjust_checked(ev, temp_hp);
}; };
let adjust_ac = move |ev: Targeted<Event, HtmlInputElement>| { let pc_hp =
utils::adjust_checked(ev, ac); move |a: u16, b: u16| -> String { format!("width: {}%", utils::filled_pc(a, b).min(100.)) };
};
let pc_hp = move |a: u16, b: u16| -> String {
format!("width: {}%", utils::filled_pc(a, b).min(100.))
};
view! { view! {
<h6>"hp/оз, ac/КД:"</h6> <h6>"hp/оз:"</h6>
<div class="hp"> <div class="hp">
<div class="perm"> <div class="perm">
<div style=move || pc_hp(hp.get(), max_hp.get()) class="bar"></div> <div style=move || pc_hp(hp.get(), max_hp.get()) class="bar"></div>
@ -53,10 +46,6 @@ pub fn HitPoints () -> impl IntoView {
<input min=0 title="Временные хитпойнты" id="temp_hp" type="number" class="header-input" on:input:target=move |e| adjust_temp_hp(e) prop:value=move || temp_hp.get() /> <input min=0 title="Временные хитпойнты" id="temp_hp" type="number" class="header-input" on:input:target=move |e| adjust_temp_hp(e) prop:value=move || temp_hp.get() />
</div> </div>
</div> </div>
<div class="ac">
<span>"КД:"</span>
<input min=0 title="Класс доспеха (вручную)" id="ac" type="number" class="header-input" on:input:target=move |e| adjust_ac(e) prop:value=move || ac.get() />
</div>
</div> </div>
} }
} }

View File

@ -202,6 +202,14 @@ aside {
} }
} }
.ac {
margin-left: auto;
justify-content: flex-end;
text-align: right;
width: 20%;
background: rgba(green, 0.15);
}
.death-throws { .death-throws {
display: flex; display: flex;
justify-content: center; justify-content: center;