@@ 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<Global>,
mut game_data: ResMut<GameData>,
mut details_ev_w: EventWriter<GameDetailsCallEvent>,
+ mut create_action_ev_w: EventWriter<GameActionCreateCallEvent>,
) {
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<GameActionCreateCallEvent>,
+) {
+ 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)
+ ),
+ });
+}