From 48cb28245c76282ed9b1d39859ec8b12f18cac12 Mon Sep 17 00:00:00 2001 From: skye Date: Thu, 4 May 2023 13:49:30 +0300 Subject: [PATCH] feat(client): hardcoded test piles, better log --- client/src/plugins/game/ui/mod.rs | 102 +++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 8 deletions(-) diff --git a/client/src/plugins/game/ui/mod.rs b/client/src/plugins/game/ui/mod.rs index ef4a1fb..8e14c30 100644 --- a/client/src/plugins/game/ui/mod.rs +++ b/client/src/plugins/game/ui/mod.rs @@ -9,7 +9,7 @@ use bevy::prelude::*; use bevy_egui::{egui, EguiContexts}; -use crate::{plugins::GameDetailsCallEvent, Global}; +use crate::{plugins::{GameDetailsCallEvent, GameActionCreateCallEvent}, Global, api::game::{Action, Command, Game}, game_status::Card}; use super::GameData; @@ -19,6 +19,7 @@ pub fn ui( global: Res, mut game_data: ResMut, mut details_ev_w: EventWriter, + mut create_action_ev_w: EventWriter, ) { egui::Window::new("Game Details") .show(contexts.ctx_mut(), |ui| { @@ -42,6 +43,13 @@ pub fn ui( }); } + if status.actions.is_empty() && game.host_id == global.user.as_ref().unwrap().id { + if ui.button("Init Game").clicked() { + // NOTE/FIXME: hardcoded game init + hardcoded_piles(&game, &mut create_action_ev_w); + } + } + ui.separator(); egui::CollapsingHeader::new("Game") @@ -68,13 +76,91 @@ pub fn ui( egui::CollapsingHeader::new("Log") .default_open(false) .show(ui, |ui| { - for action in &status.actions { - ui.add( - egui::TextEdit::multiline(&mut serde_json::to_string_pretty(action).unwrap()) - .code_editor() - .interactive(false) - ); - } + 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) + ); + }); + } + }); }); }); } + +fn hardcoded_piles( + game: &Game, + create_action_ev_w: &mut EventWriter, +) { + create_action_ev_w.send(GameActionCreateCallEvent { + action: Action::new( + &game.id, + &game.host_id, + &game.host_id, + &Command::InitSupplyPile { + card: Card { + name: "Test Card".to_string(), + cost: 4, + actions: vec![] + }, + amount: 10 + }, + fastrand::u64(u64::MIN..=u64::MAX) + ), + }); + create_action_ev_w.send(GameActionCreateCallEvent { + action: Action::new( + &game.id, + &game.host_id, + &game.host_id, + &Command::InitSupplyPile { + card: Card { + name: "Test Card 2".to_string(), + cost: 4, + actions: vec![] + }, + amount: 10 + }, + fastrand::u64(u64::MIN..=u64::MAX) + ), + }); + create_action_ev_w.send(GameActionCreateCallEvent { + action: Action::new( + &game.id, + &game.host_id, + &game.host_id, + &Command::InitSupplyPile { + card: Card { + name: "Test Card 3".to_string(), + cost: 4, + actions: vec![] + }, + amount: 10 + }, + fastrand::u64(u64::MIN..=u64::MAX) + ), + }); + create_action_ev_w.send(GameActionCreateCallEvent { + action: Action::new( + &game.id, + &game.host_id, + &game.host_id, + &Command::InitSupplyPile { + card: Card { + name: "Test Card 4".to_string(), + cost: 4, + actions: vec![] + }, + amount: 10 + }, + fastrand::u64(u64::MIN..=u64::MAX) + ), + }); +} -- 2.44.1