DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ea466a600aca8e1271271e1bca531edeb5c391e5 — Jonni Liljamo 1 year, 4 months ago 4a810b3
feat(client): RollForPlays, and some log stuff
3 files changed, 52 insertions(+), 1 deletions(-)

M client/src/api/game/mod.rs
M client/src/game_status/parser.rs
M client/src/util/action_to_log.rs
M client/src/api/game/mod.rs => client/src/api/game/mod.rs +4 -0
@@ 73,6 73,10 @@ pub enum Command {
    GivePlays {
        amount: usize,
    },
    RollForPlays {
        amount: usize,
        sides: usize,
    },
    GiveBuys {
        amount: usize,
    },

M client/src/game_status/parser.rs => client/src/game_status/parser.rs +42 -1
@@ 253,17 253,58 @@ fn parse_action(action: &Action, game: &Game, game_status: &mut GameStatus) {
            target.state = *state;
        }
        Command::RollForCurrency { amount, sides } => {
            let mut results: Vec<usize> = Vec::with_capacity(*amount);
            for _ in 0..*amount {
                let result = Rng::with_seed(action.seed.parse::<u64>().unwrap()).usize(1..=*sides);
                target.currency += result;

                results.push(result);
            }

            if *amount == 1 {
                game_status.log.push(LogEntry::from_sections([
                    LogSection::bold(&format!("  {}", result.to_string())),
                    LogSection::bold(&results.first().unwrap().to_string()),
                ]));
            } else {
                game_status.log.push(LogEntry::from_sections([
                    LogSection::bold(
                        &format!(
                            "   {} = {}",
                            results.iter().map(ToString::to_string).collect::<Vec<String>>().join(" "),
                            results.iter().sum::<usize>(),
                        )
                    ),
                ]));
            }
        }
        Command::GivePlays { amount } => {
            target.plays += amount;
        }
        Command::RollForPlays { amount, sides } => {
            let mut results: Vec<usize> = Vec::with_capacity(*amount);
            for _ in 0..*amount {
                let result = Rng::with_seed(action.seed.parse::<u64>().unwrap()).usize(1..=*sides);
                target.plays += result;

                results.push(result);
            }

            if *amount == 1 {
                game_status.log.push(LogEntry::from_sections([
                    LogSection::bold(&results.first().unwrap().to_string()),
                ]));
            } else {
                game_status.log.push(LogEntry::from_sections([
                    LogSection::bold(
                        &format!(
                            "   {} = {}",
                            results.iter().map(ToString::to_string).collect::<Vec<String>>().join(" "),
                            results.iter().sum::<usize>(),
                        )
                    ),
                ]));
            }
        }
        Command::GiveBuys { amount } => {
            target.buys += amount;
        }

M client/src/util/action_to_log.rs => client/src/util/action_to_log.rs +6 -0
@@ 94,6 94,12 @@ pub fn action_to_log(action: &Action, game_status: &GameStatus) -> LogEntry {
            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")],