DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: cbfbc57d1ca8db12bd08bccdc24c62b62ff34b09 deck-builder/client/src/util/action_to_log.rs -rw-r--r-- 3.4 KiB
cbfbc57dJonni Liljamo feat(client): add more log configurations 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * 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 { min: _, max: _ } => {
            LogEntry::from_sections(vec![
                LogSection::bold(invoker_name),
                LogSection::normal(" rolled for currency (log borked)"),
            ])
        }
        #[allow(unreachable_patterns)]
        _ => {
            LogEntry {
                sections: vec![
                    LogSection::normal("No log configuration for this command"),
                ]
            }
        }
    }
}