post-push-party 0.1.9

Push code, earn points, throw a party!
pub mod games;
pub mod pack_reveal;
pub mod packs;
pub mod party;
pub mod store;

use ratatui::prelude::*;

use crate::{game::GameRef, pack::Pack, state::State};

use super::action::{Action, Route};

pub enum MessageType {
    Success,
    Normal,
    Error,
}

/// result of handling an action in a view
pub enum ViewResult {
    /// nothing happened
    None,
    /// state changed, needs redraw
    Redraw,
    /// navigate to a different route
    Navigate(Route),
    /// open a pack of this type and go to the reveal screen for it
    OpenPack(Pack),
    /// correct the current point offset by the given amount (because a pack item was just revealed granting that amount)
    RevealPoints(u64),
    /// correct the current game offset by the given amount (because a pack item was just revealed with a game token)
    RevealGame,
    /// starts a game
    StartGame(GameRef),
    /// show a transient message
    Message(MessageType, String),
}

/// a renderable, interactive view
pub trait View {
    /// render the view's content (not header/footer, those are handled by App)
    fn render(&self, frame: &mut Frame, area: Rect, state: &State, tick: u32);

    /// handle an action, potentially mutating game state
    fn handle(&mut self, action: Action, state: &mut State) -> ViewResult;

    /// key hints for the footer, e.g. [("↑↓", "select"), ("enter", "confirm")]
    fn key_hints(&self) -> Vec<(&'static str, &'static str)>;
}