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;
|
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();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user