Skip to content

Commit 24c27c6

Browse files
committed
Moving saved state to a more sensible location
1 parent 8b5e4dc commit 24c27c6

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

src/app/main.rs

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::path;
2-
32
use frontend::render;
43
use frontend::input::EventMapper;
54
use frontend::input::GamepadEventLoop;
@@ -11,6 +10,7 @@ use frontend::gfx_window_glutin;
1110
use conrod;
1211

1312
use core::resource::filesystem::ResourceLoaderBuilder;
13+
use core::resource::filesystem::ResourceLoader;
1414
use core::math::Directional;
1515
use core::clock::{seconds, SecondsValue, Hourglass, SystemTimer};
1616
use ctrlc;
@@ -22,7 +22,19 @@ use winit::{self, WindowEvent, VirtualKeyCode, KeyboardInput};
2222
use glutin;
2323
use glutin::GlContext;
2424

25-
pub fn main_loop(minion_gene_pool: &str, world_file: Option<String>, fullscreen: Option<usize>, width: Option<u32>, height: Option<u32>, audio_device: Option<usize>) {
25+
pub fn make_resource_loader(config_home: &path::Path) -> ResourceLoader {
26+
let res = ResourceLoaderBuilder::new()
27+
.add(path::Path::new("./resources"))
28+
.add(config_home.join("resources").as_path())
29+
.add(config_home.join("saved_state").as_path())
30+
.add(path::Path::new("/usr/local/share/rust-oids/resources"))
31+
.add(path::Path::new("/usr/share/rust-oids/resources"))
32+
.build();
33+
34+
res
35+
}
36+
37+
pub fn main_loop(minion_gene_pool: &str, config_home: path::PathBuf, world_file: Option<String>, fullscreen: Option<usize>, width: Option<u32>, height: Option<u32>, audio_device: Option<usize>) {
2638
const WIDTH: u32 = 1280;
2739
const HEIGHT: u32 = 1024;
2840

@@ -56,15 +68,13 @@ pub fn main_loop(minion_gene_pool: &str, world_file: Option<String>, fullscreen:
5668

5769
let mut encoder = factory.create_command_buffer().into();
5870

59-
let res = ResourceLoaderBuilder::new()
60-
.add(path::Path::new("resources"))
61-
.build();
71+
let res = make_resource_loader(&config_home);
6272

6373
let renderer = &mut render::ForwardRenderer::new(&mut factory, &mut encoder, &res, &frame_buffer).unwrap();
6474
let mapper = app::WinitEventMapper::new();
6575

6676
// Create a new game and run it.
67-
let mut app = app::App::new(w as u32, h as u32, 100.0, &res, minion_gene_pool, world_file);
77+
let mut app = app::App::new(w as u32, h as u32, 100.0, config_home, &res, minion_gene_pool, world_file);
6878

6979
let mut ui = ui::conrod_ui::Ui::new(&res,
7080
&mut factory,
@@ -163,14 +173,12 @@ pub fn main_loop(minion_gene_pool: &str, world_file: Option<String>, fullscreen:
163173
};
164174
}
165175

166-
pub fn main_loop_headless(minion_gene_pool: &str, world_file: Option<String>) {
176+
pub fn main_loop_headless(minion_gene_pool: &str, config_home: path::PathBuf, world_file: Option<String>) {
167177
const WIDTH: u32 = 1024;
168178
const HEIGHT: u32 = 1024;
169-
let res = ResourceLoaderBuilder::new()
170-
.add(path::Path::new("resources"))
171-
.build();
179+
let res = make_resource_loader(&config_home);
172180

173-
let mut app = app::App::new(WIDTH, HEIGHT, 100.0, &res, minion_gene_pool, world_file);
181+
let mut app = app::App::new(WIDTH, HEIGHT, 100.0, config_home, &res, minion_gene_pool, world_file);
174182
let mut no_audio = ui::NullAlertPlayer::new();
175183
app.init(app::SystemMode::Batch);
176184

src/app/mod.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use core::view::WorldTransform;
2222
use frontend::input;
2323
use frontend::ui;
2424
use std::fs;
25+
use std::env;
26+
use std::path;
2527
use getopts::Options;
2628
use num;
2729
use rayon::prelude::*;
@@ -51,7 +53,7 @@ pub fn run(args: &[OsString]) {
5153
let mut opt = Options::new();
5254
opt.optflag("t", "terminal", "Headless mode");
5355
opt.optopt("f", "fullscreen", "Fullscreen mode on monitor X", "0");
54-
opt.optopt("i", "initial", "Start from specific snapshot", "resources/20180423_234300.json");
56+
opt.optopt("i", "initial", "Start from specific snapshot", ".config/rust-oids/saved_state/20180423_234300.json");
5557
opt.optflag("n", "new", "Ignore last snapshot, start from new population");
5658
opt.optopt("w", "width", "Window width", "1024");
5759
opt.optopt("h", "height", "Window height", "1024");
@@ -63,10 +65,13 @@ pub fn run(args: &[OsString]) {
6365
);
6466
let mut world_file = options.opt_str("i");
6567

68+
let user_home = env::home_dir().unwrap_or(path::PathBuf::from("."));
69+
let config_home = user_home.join(".config/rust-oids");
70+
6671
// TODO: tidy up
6772
if !options.opt_present("n") && world_file.is_none() {
6873
let mut max_path = "".to_owned();
69-
if let Ok(dir) = fs::read_dir("resources") {
74+
if let Ok(dir) = fs::read_dir(config_home.join("saved_state")) {
7075
for entry in dir {
7176
let path_name = entry
7277
.unwrap().path()
@@ -85,14 +90,14 @@ pub fn run(args: &[OsString]) {
8590
}
8691

8792
if options.opt_present("t") {
88-
main::main_loop_headless(pool_file_name, world_file);
93+
main::main_loop_headless(pool_file_name, config_home, world_file);
8994
} else {
9095
let fullscreen = options.opt_default("f", "0").and_then(|v| v.parse::<usize>().ok());
9196
let width = options.opt_default("w", "1024").and_then(|v| v.parse::<u32>().ok());
9297
let height = options.opt_default("h", "1024").and_then(|v| v.parse::<u32>().ok());
9398
let audio_device = options.opt_default("a", "0").and_then(|v| v.parse::<usize>().ok());
9499

95-
main::main_loop(pool_file_name, world_file, fullscreen, width, height, audio_device);
100+
main::main_loop(pool_file_name, config_home, world_file, fullscreen, width, height, audio_device);
96101
}
97102
}
98103
Err(message) => {
@@ -297,7 +302,7 @@ pub struct FrameUpdate {
297302
}
298303

299304
impl App {
300-
pub fn new<R>(w: u32, h: u32, scale: f32, resource_loader: &R, minion_gene_pool: &str, world_file: Option<String>) -> Self
305+
pub fn new<R>(w: u32, h: u32, scale: f32, config_home: path::PathBuf, resource_loader: &R, minion_gene_pool: &str, world_file: Option<String>) -> Self
301306
where
302307
R: ResourceLoader<u8>, {
303308
let system_timer = SystemTimer::new();

0 commit comments

Comments
 (0)