-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.rs
36 lines (30 loc) · 1.22 KB
/
setup.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use bevy::{
prelude::*,
window::PrimaryWindow,
};
use bevy_persistent::prelude::*;
use bevy_persistent_windows::prelude::*;
use std::path::Path;
fn main() {
let mut app = App::new();
let window_plugin = WindowPlugin { primary_window: None, ..Default::default() };
app.add_plugins(DefaultPlugins.set(window_plugin).build());
let state_directory = dirs::data_dir()
.map(|platform_data_dir| platform_data_dir.join("bevy-persistent-windows").join("state"))
.unwrap_or(Path::new("session").join("data").join("state"))
.join("setup");
app.world_mut().spawn((PrimaryWindow, PersistentWindowBundle {
window: Window { title: "I persist!".to_owned(), ..Default::default() },
state: Persistent::<WindowState>::builder()
.name("primary window state")
.format(StorageFormat::Toml)
.path(state_directory.join("primary-window.toml"))
.default(WindowState::windowed(1280, 720))
.revertible(true)
.revert_to_default_on_deserialization_errors(true)
.build()
.expect("failed to create the persistent primary window state"),
}));
app.add_plugins(PersistentWindowsPlugin);
app.run();
}