DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 7981ec061606d1d1fa65617ebc1173a7bc79c9eb deck-builder/client/src/util/action_to_log.rs -rw-r--r-- 2.4 KiB
7981ec06Jonni Liljamo feat(client): revamp log system 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
/*
 * 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;

    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),
            ])
        }
        _ => {
            LogEntry {
                sections: vec![
                    LogSection::normal("No log configuration for this command"),
                ]
            }
        }
    }
}