save on exit
Some checks failed
Some checks failed
This commit is contained in:
19
src/main.rs
19
src/main.rs
@@ -3,8 +3,8 @@
|
||||
|
||||
mod utils;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy::window::WindowResolution;
|
||||
use bevy::window::{ClosingWindow, WindowResolution};
|
||||
use bevy::{prelude::*, window::WindowCloseRequested};
|
||||
use helpers::grid::{Flag, GridPlugin, Revealed, Tile, TileClickEvent, TileOffset, TileType};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -249,14 +249,13 @@ fn load_game(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
});
|
||||
}
|
||||
|
||||
fn save_and_exit(
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
fn save_on_exit(
|
||||
world: &World,
|
||||
type_registry: Res<AppTypeRegistry>,
|
||||
mut close_request: EventReader<WindowCloseRequested>,
|
||||
) {
|
||||
if !input.just_pressed(KeyCode::Escape) {
|
||||
return;
|
||||
}
|
||||
for _ in close_request.read() {
|
||||
println!("Saving");
|
||||
|
||||
let type_registry = type_registry.read();
|
||||
|
||||
@@ -294,6 +293,7 @@ fn save_and_exit(
|
||||
eprintln!("Unable to write save file: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// use imageproc::drawing::Canvas;
|
||||
@@ -338,7 +338,8 @@ fn main() {
|
||||
resolution: WindowResolution::new(1280.0, 720.0),
|
||||
..Default::default()
|
||||
}),
|
||||
..default()
|
||||
exit_condition: bevy::window::ExitCondition::OnAllClosed,
|
||||
close_when_requested: true,
|
||||
}),
|
||||
// bevy_inspector_egui::quick::WorldInspectorPlugin::new(),
|
||||
))
|
||||
@@ -349,6 +350,6 @@ fn main() {
|
||||
.init_resource::<FontHandle>()
|
||||
.add_plugins(GridPlugin)
|
||||
.add_systems(Startup, (load_game, setup_camera))
|
||||
.add_systems(Update, (tile_clicked, save_and_exit))
|
||||
.add_systems(Update, (tile_clicked, save_on_exit))
|
||||
.run();
|
||||
}
|
||||
|
Reference in New Issue
Block a user