save on exit
Some checks failed
build / Create Release (push) Successful in 5s
build / publish (zip, x86_64-pc-windows-msvc, windows-2022, windows-x86_64) (push) Successful in 7m50s
build / publish (tar.gz, x86_64-unknown-linux-gnu, ubuntu-latest, linux-x86_64) (push) Failing after 13m55s

This commit is contained in:
2024-07-12 21:06:39 +02:00
parent e32e790ad1
commit 3666b80dca

View File

@@ -3,8 +3,8 @@
mod utils; mod utils;
use bevy::prelude::*; use bevy::window::{ClosingWindow, WindowResolution};
use bevy::window::WindowResolution; use bevy::{prelude::*, window::WindowCloseRequested};
use helpers::grid::{Flag, GridPlugin, Revealed, Tile, TileClickEvent, TileOffset, TileType}; use helpers::grid::{Flag, GridPlugin, Revealed, Tile, TileClickEvent, TileOffset, TileType};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -249,14 +249,13 @@ fn load_game(mut commands: Commands, asset_server: Res<AssetServer>) {
}); });
} }
fn save_and_exit( fn save_on_exit(
input: Res<ButtonInput<KeyCode>>,
world: &World, world: &World,
type_registry: Res<AppTypeRegistry>, type_registry: Res<AppTypeRegistry>,
mut close_request: EventReader<WindowCloseRequested>,
) { ) {
if !input.just_pressed(KeyCode::Escape) { for _ in close_request.read() {
return; println!("Saving");
}
let type_registry = type_registry.read(); let type_registry = type_registry.read();
@@ -293,6 +292,7 @@ fn save_and_exit(
if let Err(e) = std::fs::write("./assets/save.sav", serialized) { if let Err(e) = std::fs::write("./assets/save.sav", serialized) {
eprintln!("Unable to write save file: {:?}", e); eprintln!("Unable to write save file: {:?}", e);
} }
}
} }
fn main() { fn main() {
@@ -338,7 +338,8 @@ fn main() {
resolution: WindowResolution::new(1280.0, 720.0), resolution: WindowResolution::new(1280.0, 720.0),
..Default::default() ..Default::default()
}), }),
..default() exit_condition: bevy::window::ExitCondition::OnAllClosed,
close_when_requested: true,
}), }),
// bevy_inspector_egui::quick::WorldInspectorPlugin::new(), // bevy_inspector_egui::quick::WorldInspectorPlugin::new(),
)) ))
@@ -349,6 +350,6 @@ fn main() {
.init_resource::<FontHandle>() .init_resource::<FontHandle>()
.add_plugins(GridPlugin) .add_plugins(GridPlugin)
.add_systems(Startup, (load_game, setup_camera)) .add_systems(Startup, (load_game, setup_camera))
.add_systems(Update, (tile_clicked, save_and_exit)) .add_systems(Update, (tile_clicked, save_on_exit))
.run(); .run();
} }