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;
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();
}