DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 7d5486e5144305656353cbfcdfd8a177c99cb88b deck-builder/client/src/util/action_to_log.rs -rw-r--r-- 4.9 KiB
7d5486e5Jonni Liljamo feat(client): advanced roll action, log configs 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * 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::GiveCurrency { amount } => LogEntry::from_sections(vec![
            LogSection::bold(target_name),
            LogSection::bold(&format!("+{}", amount)),
            LogSection::normal(" currency"),
        ]),
        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::GivePlays { amount } => LogEntry::from_sections(vec![
            LogSection::bold(target_name),
            LogSection::bold(&format!("+{}", amount)),
            LogSection::normal(" plays"),
        ]),
        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:"),
        ]),
        Command::GiveBuys { amount } => LogEntry::from_sections(vec![
            LogSection::bold(target_name),
            LogSection::bold(&format!(" +{}", amount)),
            LogSection::normal(" buys"),
        ]),
        Command::GiveVP { amount } => LogEntry::from_sections(vec![
            LogSection::bold(target_name),
            LogSection::bold(&format!(" +{}", amount)),
            LogSection::normal(" VP"),
        ]),
        Command::RemoveVP { amount } => LogEntry::from_sections(vec![
            LogSection::bold(target_name),
            LogSection::bold(&format!(" -{}", amount)),
            LogSection::normal(" VP"),
        ]),
        #[allow(unreachable_patterns)]
        _ => LogEntry {
            sections: vec![LogSection::normal("No log configuration for this command")],
        },
    }
}