mod base;
mod big_text;
mod breakdown;
mod context;
mod exclamation;
mod fireworks;
pub(crate) mod palette;
mod quotes;
pub(crate) mod stats;
mod style;
pub use context::RenderContext;
pub use palette::Palette;
use base::Base;
use big_text::BigText;
use breakdown::Breakdown;
use exclamation::Exclamation;
use fireworks::Fireworks;
use quotes::Quotes;
use stats::Stats;
use crate::{party::palette::ALL_PALETTES, state::PaletteSelection};
pub trait Party: Sync {
fn id(&self) -> &'static str;
fn name(&self) -> &'static str;
fn description(&self) -> &'static str;
fn cost(&self) -> u64;
fn supports_color(&self) -> bool;
fn render(&self, ctx: &RenderContext, palette: &Palette) -> bool;
}
pub static BASE: Base = Base;
static BIG_TEXT: BigText = BigText;
static BREAKDOWN: Breakdown = Breakdown;
static EXCLAMATION: Exclamation = Exclamation;
static QUOTES: Quotes = Quotes;
static STATS: Stats = Stats;
pub static FIREWORKS: Fireworks = Fireworks;
pub static ALL_PARTIES: &[&'static dyn Party] = &[
&BASE,
&BREAKDOWN,
&STATS,
&EXCLAMATION,
&BIG_TEXT,
"ES,
&FIREWORKS,
];
fn random_pick<T>(items: &[T]) -> &T {
use rand::prelude::IndexedRandom;
items
.choose(&mut rand::rng())
.expect("list must be nonempty")
}
pub fn display(ctx: &RenderContext) {
let enabled_parties = ALL_PARTIES
.iter()
.filter(|party| ctx.state.is_party_enabled(party.id()))
.copied();
println!();
for party in enabled_parties {
let palette_selection = ctx.state.selected_palette(party.id());
let palette_id = match palette_selection {
Some(PaletteSelection::Random) => {
let unlocked_palettes = ctx
.state
.unlocked_palettes(party.id())
.map(|set| set.iter().collect::<Vec<_>>())
.unwrap_or_default();
if unlocked_palettes.is_empty() {
Palette::WHITE_ANSI.id().to_string()
} else {
random_pick(&unlocked_palettes).to_string()
}
}
Some(PaletteSelection::Specific(color_name)) => color_name.to_string(),
None => Palette::WHITE_ANSI.id().to_string(),
};
let palette = ALL_PALETTES
.iter()
.find(|&&c| c.id() == palette_id)
.unwrap_or(&&Palette::WHITE_ANSI);
let printed_text = party.render(ctx, palette);
if printed_text {
println!();
}
}
}