aex/src/components/sidebar/spell_slots.rs
yaroslav k 257f254b13 document every function, trait and struct in src/
Doc comments on all modules, components, entities, helpers and type
aliases; larger comments on the important entities (Dashboard, PlayerData,
Context, App, Numput, item data). No behavior changes.
2026-08-04 09:21:25 +03:00

47 lines
1.6 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use crate::prelude::*;
use leptos::prelude::*;
/// Spell slots for all nine levels: a row of clickable pips per level.
/// Clicking toggles a slot used/unused.
#[component]
pub fn SpellSlots () -> impl IntoView {
let state = expect_context::<Context>();
let player = state.player();
let slots = player.spell_slots();
// Toggles pip `slot_id` of `level` used/unused.
let process_spell_slot_click = move |level: usize, slot_id: u8| {
slots.update(|s| {
let l = &mut s.0[level];
if slot_id < l.used {
l.used = slot_id;
} else {
l.used = slot_id + 1;
}
})
};
view! {
<h6>spell slots/ячейки заклинаний:</h6>
<div class="slots">
<For
each=move || slots.get().0.into_iter().enumerate()
key=|(idx, ssl)| format!("{}-{}-{}", idx, ssl.used, ssl.total)
let((index, level))
>
<div class=move || format!("slot-level slot-level-{}", index + 1)>
<span class="slot-level-title">{move || index + 1}</span>
<For each=move || 0..level.total key=|i| i.clone() let(slot)>
<div
class=move || format!("spell-slot {}", if slot < level.used { "used" } else { "" })
on:click=move |_| process_spell_slot_click(index, slot)
>
</div>
</For>
</div>
</For>
</div>
}
}