DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

c48f91ee4ef66fbecbcfd08a803a745b1f5c323b — Jonni Liljamo 1 year, 7 months ago 60c55b1
chore(client): fmt, clippy
M client/src/game_status/parser.rs => client/src/game_status/parser.rs +42 -29
@@ 16,7 16,7 @@ use crate::{
    util::action_to_log,
};

use super::{GameStatus, PlayerState, PlayerStatus, LogSection, LogEntry};
use super::{GameStatus, LogEntry, LogSection, PlayerState, PlayerStatus};

/// funny unsafe wrapper
fn get_invoker_target_next<'a>(


@@ 36,8 36,7 @@ fn get_invoker_target_next<'a>(
        let invoker_ref: *mut PlayerStatus = players.get_mut(invoker).unwrap() as *mut _;
        let target_ref: *mut PlayerStatus = players.get_mut(target).unwrap() as *mut _;

        let next_turn_n: usize = if ((*invoker_ref).turn_n + 1) > (players.len() - 1)
        {
        let next_turn_n: usize = if ((*invoker_ref).turn_n + 1) > (players.len() - 1) {
            0
        } else {
            (*invoker_ref).turn_n + 1


@@ 262,19 261,23 @@ fn parse_action(action: &Action, game: &Game, game_status: &mut GameStatus) {
            }

            if *amount == 1 {
                game_status.log.push(LogEntry::from_sections([
                    LogSection::bold(&results.first().unwrap().to_string()),
                ]));
                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>(),
                        )
                    ),
                ]));
                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 } => {


@@ 290,19 293,23 @@ fn parse_action(action: &Action, game: &Game, game_status: &mut GameStatus) {
            }

            if *amount == 1 {
                game_status.log.push(LogEntry::from_sections([
                    LogSection::bold(&results.first().unwrap().to_string()),
                ]));
                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>(),
                        )
                    ),
                ]));
                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 } => {


@@ 312,7 319,7 @@ fn parse_action(action: &Action, game: &Game, game_status: &mut GameStatus) {
            target.vp += amount;
        }
        Command::MarkCardInDeckToBeTrashed { index } => {
            if target.deck.len() == 0 {
            if target.deck.is_empty() {
                return;
            }
            match index {


@@ 321,7 328,13 @@ fn parse_action(action: &Action, game: &Game, game_status: &mut GameStatus) {
                }
                None => {
                    let deck_len = target.deck.len();
                    target.deck.get_mut(Rng::with_seed(action.seed.parse::<u64>().unwrap()).usize(0..deck_len)).unwrap().to_be_trashed = true;
                    target
                        .deck
                        .get_mut(
                            Rng::with_seed(action.seed.parse::<u64>().unwrap()).usize(0..deck_len),
                        )
                        .unwrap()
                        .to_be_trashed = true;
                }
            }
        }

M client/src/main.rs => client/src/main.rs +8 -2
@@ 130,7 130,9 @@ fn setup(
    asset_server: Res<AssetServer>,
    mut lcm_ev_w: EventWriter<LoadCardManifestEvent>,
) {
    commands.insert_resource(CardManifestHandle { handle: asset_server.load("card_manifest.yaml") });
    commands.insert_resource(CardManifestHandle {
        handle: asset_server.load("card_manifest.yaml"),
    });
    lcm_ev_w.send(LoadCardManifestEvent);

    commands


@@ 155,7 157,11 @@ fn load_card_manifest(
    yaml_assets: Res<Assets<util::YamlAsset>>,
    card_manifest_handle: Res<CardManifestHandle>,
) {
    let card_manifest_yaml: String = yaml_assets.get(&card_manifest_handle.handle).unwrap().0.clone();
    let card_manifest_yaml: String = yaml_assets
        .get(&card_manifest_handle.handle)
        .unwrap()
        .0
        .clone();
    let card_manifest: CardManifest = serde_yaml::from_str(&card_manifest_yaml).unwrap();
    commands.insert_resource(card_manifest);
}

M client/src/plugins/game/ui/mod.rs => client/src/plugins/game/ui/mod.rs +1 -1
@@ 13,7 13,7 @@ use crate::{
    api::game::{Action, Command, Game},
    game_status::PlayerState,
    plugins::GameActionCreateCallEvent,
    AppState, Global, CardManifest,
    AppState, CardManifest, Global,
};

use super::{GameData, RefreshGameEvent};

M client/src/plugins/game/ui/state_button.rs => client/src/plugins/game/ui/state_button.rs +3 -2
@@ 12,7 12,8 @@ use crate::{
    api::game::{Action, Command},
    game_status::PlayerState,
    plugins::{GameActionCreateCallEvent, GameData},
    AppState, Global, util::get_next_player,
    util::get_next_player,
    AppState, Global,
};

pub struct StateButtonPlugin;


@@ 168,7 169,7 @@ fn interact_state_button(
                            action: Action::new(
                                &game.id,
                                &user.id,
                                &next_player.0,
                                next_player.0,
                                &Command::EndTurn {},
                                None,
                            ),

M client/src/util/mod.rs => client/src/util/mod.rs +13 -8
@@ 6,7 6,10 @@
 * See LICENSE for licensing information.
 */

use bevy::{asset::{AssetLoader, LoadedAsset}, reflect::TypeUuid};
use bevy::{
    asset::{AssetLoader, LoadedAsset},
    reflect::TypeUuid,
};

pub mod egui;



@@ 15,9 18,11 @@ pub use action_to_log::action_to_log;

use crate::game_status::{GameStatus, PlayerStatus};

pub fn get_next_player<'a>(player: &'a PlayerStatus, game_status: &'a GameStatus) -> (&'a String, &'a PlayerStatus) {
    let next_turn_n: usize = if (player.turn_n + 1) > (game_status.players.len() - 1)
    {
pub fn get_next_player<'a>(
    player: &'a PlayerStatus,
    game_status: &'a GameStatus,
) -> (&'a String, &'a PlayerStatus) {
    let next_turn_n: usize = if (player.turn_n + 1) > (game_status.players.len() - 1) {
        0
    } else {
        player.turn_n + 1


@@ 39,10 44,10 @@ pub struct YamlLoader;

impl AssetLoader for YamlLoader {
    fn load<'a>(
            &'a self,
            bytes: &'a [u8],
            load_context: &'a mut bevy::asset::LoadContext,
        ) -> bevy::utils::BoxedFuture<'a, Result<(), bevy::asset::Error>> {
        &'a self,
        bytes: &'a [u8],
        load_context: &'a mut bevy::asset::LoadContext,
    ) -> bevy::utils::BoxedFuture<'a, Result<(), bevy::asset::Error>> {
        Box::pin(async move {
            let yaml_str = std::str::from_utf8(bytes)?;
            let asset = YamlAsset(yaml_str.into());