DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

7ce88fae9680596019fc15be5ec510df7ea939b8 — Jonni Liljamo 1 year, 7 months ago 977e440
feat(client): sorta finished log ui, remove old

Though only one Command has a configured log format.
M client/src/plugins/game/ui/log.rs => client/src/plugins/game/ui/log.rs +24 -14
@@ 96,7 96,7 @@ fn setup_log(mut commands: Commands, asset_server: Res<AssetServer>) {
                    justify_content: JustifyContent::Center,
                    align_items: AlignItems::Center,
                    size: Size {
                        width: Val::Px(300.),
                        width: Val::Px(475.),
                        height: Val::Percent(75.),
                    },
                    position_type: PositionType::Absolute,


@@ 118,8 118,11 @@ fn setup_log(mut commands: Commands, asset_server: Res<AssetServer>) {
                .spawn(NodeBundle {
                    style: Style {
                        flex_direction: FlexDirection::Column,
                        align_self: AlignSelf::Stretch,
                        size: Size::all(Val::Percent(95.)),
                        //align_self: AlignSelf::Stretch,
                        size: Size {
                            width: Val::Px(450.),
                            height: Val::Percent(95.),
                        },
                        overflow: Overflow::Hidden,
                        ..Default::default()
                    },


@@ 220,20 223,27 @@ fn update_log(
        let index_spaces = status.actions.len().to_string().len();

        for (i, action) in status.actions.iter().enumerate() {
            let spaces = "".repeat(index_spaces - i.to_string().len());
            let spaces = " ".repeat(index_spaces - i.to_string().len());
            let index_text = TextSection {
                value: format!("{}{}. ", spaces, i),
                style: TextStyle {
                    font: font_bold.clone(),
                    ..style
                },
            };

            let mut sections = action_to_log(action, (font.clone(), font_bold.clone()), style.clone());
            sections.insert(0, index_text);

            commands.spawn((
                TextBundle::from_sections([[
                    TextSection {
                        value: format!("{}{}. ", spaces, i),
                        style: TextStyle {
                            font: font_bold.clone(),
                            ..style
                        },
                TextBundle::from_sections(sections)
                .with_style(Style {
                    max_size: Size {
                        width: Val::Px(450.),
                        height: Val::Undefined,
                    },
                ],
                    action_to_log(action, font, style).into_iter()
                ].concat()),
                    ..Default::default()
                }),
                AccessibilityNode(NodeBuilder::new(bevy::a11y::accesskit::Role::ListItem)),
                LogListEntry,
            ))

M client/src/plugins/game/ui/mod.rs => client/src/plugins/game/ui/mod.rs +1 -24
@@ 387,30 387,7 @@ pub fn dev_details_ui(
                        });
                }
            });

        egui::CollapsingHeader::new("Log")
            .default_open(false)
            .show(ui, |ui| {
                egui::ScrollArea::vertical()
                    .max_width(f32::INFINITY)
                    .show(ui, |ui| {
                        for (i, action) in status.actions.iter().enumerate() {
                            egui::CollapsingHeader::new(format!("{}", i))
                                .default_open(false)
                                .show(ui, |ui| {
                                    ui.add(
                                        egui::TextEdit::multiline(
                                            &mut serde_json::to_string_pretty(action).unwrap(),
                                        )
                                        .code_editor()
                                        .interactive(false)
                                        .desired_width(f32::INFINITY),
                                    );
                                });
                        }
                    });
            });
    });
        });
}

fn hardcoded_init(game: &Game, create_action_ev_w: &mut EventWriter<GameActionCreateCallEvent>) {

M client/src/util/action_to_log.rs => client/src/util/action_to_log.rs +35 -2
@@ 8,14 8,47 @@

use bevy::prelude::*;

use crate::api::game::Action;
use crate::api::game::{Action, Command};

macro_rules! section {
    ($value:expr, $style:ident) => {
        TextSection {
            value: $value,
            style: $style.clone(),
        }
    };

    ($value:expr, $style:expr) => {
        TextSection {
            value: $value,
            style: $style,
        }
    };
}

pub fn action_to_log(
    action: &Action,
    font: Handle<Font>,
    (font, font_bold): (Handle<Font>, Handle<Font>),
    style: TextStyle,
) -> Vec<TextSection> {
    match &action.command {
        Command::InitSupplyPile { card, amount } => {
            vec![
                section!(format!("Created supply pile of "), style),
                section!(format!("{}", card.name), TextStyle {
                    font: font_bold.clone(),
                    ..style.clone()
                }),
                section!(format!(" with "), style),
                section!(format!("{}", amount), TextStyle {
                    font: font_bold.clone(),
                    ..style.clone()
                }),
                section!(format!(" cards."), TextStyle {
                    ..style.clone()
                }),
            ]
        }
        _ => {
            vec![
                TextSection {