werewolves/werewolves/src/components/character.rs

88 lines
2.9 KiB
Rust
Raw Normal View History

// Copyright (C) 2025 Emilis Bliūdžius
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use convert_case::{Case, Casing};
use werewolves_proto::{character::Character, game::SetupRole, message::CharacterIdentity};
use yew::prelude::*;
use crate::components::{Icon, IconSource, IconType, PartialAssociatedIcon};
#[derive(Debug, Clone, PartialEq, Properties)]
pub struct CharacterCardProps {
pub char: Character,
#[prop_or_default]
pub dead: bool,
#[prop_or_default]
pub faint: bool,
}
#[function_component]
pub fn CharacterCard(CharacterCardProps { faint, char, dead }: &CharacterCardProps) -> Html {
let class = Into::<SetupRole>::into(char.role_title())
.category()
.class();
let role = char.role_title().to_string().to_case(Case::Title);
let ident = char.identity();
let pronouns = ident.pronouns.as_ref().map(|p| {
html! {
<span class="pronouns">{"("}{p}{")"}</span>
}
});
let name = ident.name.clone();
let source = char.role_title().icon().unwrap_or(if char.is_village() {
IconSource::Village
} else {
IconSource::Wolves
});
let dead = dead.then(|| {
html! {
<Icon source={IconSource::Skull} icon_type={IconType::Small}/>
}
});
let faint = faint.then_some("faint");
html! {
<span class={classes!("character-span", class, faint)}>
<span class={classes!("role", class, faint)}>
<div>
{dead}
<Icon source={source} icon_type={IconType::Small}/>
</div>
{role}
</span>
<span class={classes!("number")}><b>{ident.number.get()}</b></span>
<span class="name">{name}</span>
{pronouns}
</span>
}
}
#[derive(Debug, Clone, PartialEq, Properties)]
pub struct CharacterTargetCardProps {
pub ident: CharacterIdentity,
}
#[function_component]
pub fn CharacterTargetCard(CharacterTargetCardProps { ident }: &CharacterTargetCardProps) -> Html {
let name = ident.name.clone();
html! {
<span class={classes!("character-span")}>
<span class={classes!("number")}><b>{ident.number.get()}</b></span>
<span class="name">{name}</span>
</span>
}
}