M Cargo.lock => Cargo.lock +1 -0
@@ 2033,6 2033,7 @@ dependencies = [
"futures-lite",
"reqwest",
"serde",
+ "serde_json",
"serde_repr",
]
M client/Cargo.toml => client/Cargo.toml +1 -0
@@ 16,6 16,7 @@ futures-lite = "1.13.0"
reqwest = { version = "0.11.16", features = [ "blocking", "json", "gzip" ] }
serde_repr = "0.1.12"
+serde_json = "1.0.96"
fastrand = "1.9.0"
M client/src/api/game/mod.rs => client/src/api/game/mod.rs +1 -1
@@ 42,7 42,7 @@ pub enum Command {
Discard { index: usize },
}
-#[derive(Deserialize, Clone)]
+#[derive(Deserialize, Serialize, Clone)]
pub struct Action {
pub id: String,
pub created_at: String,
M client/src/game_status/mod.rs => client/src/game_status/mod.rs +3 -0
@@ 46,6 46,9 @@ pub struct PlayerStatus {
/// constructed from a vector of [`Action`]s
pub struct GameStatus {
+ /// a modifiable Actions Vector, will be modified when parsing actions,
+ /// used for showing the log
+ pub actions: Vec<Action>,
pub supply_piles: Vec<SupplyPile>,
/// player ids mapped to statuses
pub players: HashMap<String, PlayerStatus>,
M client/src/game_status/parser.rs => client/src/game_status/parser.rs +2 -4
@@ 14,15 14,13 @@ use crate::{api::game::{Action, Command}, game_status::SupplyPile};
use super::{GameStatus, PlayerStatus, Card};
pub fn parse(actions_init: &Vec<Action>) -> Result<GameStatus, ()> {
- // as some actions can add more actions, we need a mutable
- // actions vector.
- let mut actions = actions_init;
let mut game_status = GameStatus {
+ actions: actions_init.to_vec(),
supply_piles: vec![],
players: HashMap::new(),
};
- for action in actions {
+ for action in &game_status.actions {
// the one who invoked the action
let invoker = game_status.players.get_mut(&action.invoker)
.unwrap_or_else(|| unreachable!());
M client/src/plugins/game/ui/mod.rs => client/src/plugins/game/ui/mod.rs +13 -1
@@ 54,7 54,7 @@ pub fn ui(
});
egui::CollapsingHeader::new("Supply Piles")
- .default_open(true)
+ .default_open(false)
.show(ui, |ui| {
for pile in &status.supply_piles {
egui::CollapsingHeader::new(&pile.card.name)
@@ 64,5 64,17 @@ 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)
+ );
+ }
+ });
});
}