/*
* This file is part of laurelin_client
* Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
*
* Licensed under GPL-3.0-only.
* See LICENSE for licensing information.
*/
use crate::{
api::game::{Action, Command},
game_status::{GameStatus, LogEntry, LogSection},
};
pub fn action_to_log(action: &Action, game_status: &GameStatus) -> LogEntry {
let invoker_name = &game_status
.players
.get(&action.invoker)
.unwrap()
.display_name;
let target_name = &game_status
.players
.get(&action.target)
.unwrap()
.display_name;
match &action.command {
Command::InitSupplyPile { card, amount } => LogEntry::from_sections(vec![
LogSection::normal("Created supply pile of "),
LogSection::bold(&card.name),
LogSection::normal(" with "),
LogSection::bold(&amount.to_string()),
LogSection::normal(" cards"),
]),
Command::TakeFromPile { index, for_cost: _ } => {
let card_name = &game_status.supply_piles.get(*index).unwrap().card.name;
LogEntry::from_sections(vec![
LogSection::bold(invoker_name),
LogSection::normal(" bought "),
LogSection::bold(card_name),
])
}
Command::PlayCard { index } => {
let card_name = &game_status
.players
.get(&action.invoker)
.unwrap()
.hand
.get(*index)
.unwrap()
.name;
LogEntry::from_sections(vec![
LogSection::bold(invoker_name),
LogSection::normal(" played "),
LogSection::bold(card_name),
])
}
Command::Draw { amount } => LogEntry::from_sections(vec![
LogSection::bold(invoker_name),
LogSection::normal(" drew "),
LogSection::bold(&amount.to_string()),
LogSection::normal(" cards"),
]),
Command::Discard { index } => {
let card_name = &game_status
.players
.get(&action.invoker)
.unwrap()
.hand
.get(*index)
.unwrap()
.name;
LogEntry::from_sections(vec![
LogSection::bold(invoker_name),
LogSection::normal(" discarded "),
LogSection::bold(card_name),
])
}
Command::EndTurn {} => LogEntry::from_sections(vec![
LogSection::bold(invoker_name),
LogSection::normal(" ended their turn"),
]),
Command::StartTurn {} => LogEntry::from_sections(vec![
LogSection::bold(target_name),
LogSection::normal(" started their turn"),
]),
Command::ChangePlayerState { state } => LogEntry::from_sections(vec![
LogSection::bold(invoker_name),
LogSection::normal(" changed state to "),
LogSection::bold(&format!("{:?}", state)),
]),
Command::RollForCurrency { amount, sides } => LogEntry::from_sections(vec![
LogSection::bold(invoker_name),
LogSection::normal(" rolled "),
LogSection::bold(&format!("{}d{}", amount, sides)),
LogSection::normal(" for currency:"),
]),
Command::RollForCurrencyAdvanced { amount, sides, pairs: _ } => LogEntry::from_sections(vec![
LogSection::bold(invoker_name),
LogSection::normal(" rolled "),
LogSection::bold(&format!("{}d{}", amount, sides)),
LogSection::normal(" for currency:"),
]),
Command::RollForPlays { amount, sides } => LogEntry::from_sections(vec![
LogSection::bold(invoker_name),
LogSection::normal(" rolled "),
LogSection::bold(&format!("{}d{}", amount, sides)),
LogSection::normal(" for plays:"),
]),
#[allow(unreachable_patterns)]
_ => LogEntry {
sections: vec![LogSection::normal("No log configuration for this command")],
},
}
}