Compare commits

..

No commits in common. "877d300a5c4247082cd89116a71a13449512e921" and "542923ccef5678d88969816ec661206786ee9549" have entirely different histories.

2 changed files with 15 additions and 10 deletions

View file

@ -1,4 +1,5 @@
use eframe::egui;
use std::io::Write as _;
use billy_sheet::gui::SheetGui;
@ -40,9 +41,20 @@ impl eframe::App for Gui {
_frame.close();
}
if ui.button("Save in json").clicked() {
let path = std::path::Path::new("./sheet.json");
if let Err(error) = billy_sheet::sheet::write_sheet(path, &self.sheet) {
println!("{error}");
let result = serde_json::to_string_pretty(&self.sheet);
match result {
Ok(sheet_str) => {
let path = std::path::Path::new("./sheet.json");
match std::fs::File::create(path) {
Ok(mut file) => {
if let Err(err) = write!(file, "{}", sheet_str) {
println!("{err}");
}
}
Err(error) => println!("{error}"),
}
}
Err(error) => println!("{error}"),
}
}
});

View file

@ -1,7 +1,6 @@
use eframe::egui::widgets::DragValue;
use eframe::egui::Ui;
use serde::{Deserialize, Serialize};
use std::io::Write as _;
use crate::gui::SheetGui;
@ -37,12 +36,6 @@ pub struct CharacterSheet {
money: u32,
}
pub fn write_sheet(path: &std::path::Path, sheet: &CharacterSheet) -> std::io::Result<()> {
let sheet_str = serde_json::to_string_pretty(&sheet)?;
let mut file = std::fs::File::create(path)?;
write!(file, "{}", sheet_str)
}
impl CharacterSheet {
pub fn character_class(&self) -> &Classe {
&self.character_class