diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..c4d6b0d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,329 @@ +[root] +name = "rust-2048" +version = "0.0.0" +dependencies = [ + "piston 0.1.1 (git+https://github.com/pistondevelopers/piston)", + "piston2d-graphics 0.0.46 (git+https://github.com/pistondevelopers/graphics)", + "piston2d-opengl_graphics 0.0.16 (git+https://github.com/pistondevelopers/opengl_graphics)", + "pistoncore-sdl2_window 0.0.13 (git+https://github.com/pistondevelopers/sdl2_window)", + "rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bitflags" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "byteorder" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "clock_ticks" +version = "0.0.5" +source = "git+https://github.com/tomaka/clock_ticks#462848731d99ed2f800e2e5a19e2d8ca3b11c90c" +dependencies = [ + "libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "draw_state" +version = "0.0.7" +source = "git+https://github.com/gfx-rs/draw_state#44a0aed11abccbf970fc7efbe84b6482f0548248" +dependencies = [ + "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "enum_primitive" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "freetype-rs" +version = "0.0.9" +source = "git+https://github.com/PistonDevelopers/freetype-rs.git#686a4d7ff99eddfc64fbe7d2c3a19832ee564614" +dependencies = [ + "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "freetype-sys 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "freetype-sys" +version = "0.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libz-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "gl" +version = "0.0.12" +source = "git+https://github.com/bjz/gl-rs#62b66a85e4c2c0d88fb916040bc462702c8e0346" +dependencies = [ + "gl_common 0.0.4 (git+https://github.com/bjz/gl-rs)", + "gl_generator 0.0.25 (git+https://github.com/bjz/gl-rs)", + "khronos_api 0.0.5 (git+https://github.com/bjz/gl-rs)", + "libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "gl_common" +version = "0.0.4" +source = "git+https://github.com/bjz/gl-rs#62b66a85e4c2c0d88fb916040bc462702c8e0346" +dependencies = [ + "libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "gl_generator" +version = "0.0.25" +source = "git+https://github.com/bjz/gl-rs#62b66a85e4c2c0d88fb916040bc462702c8e0346" +dependencies = [ + "khronos_api 0.0.5 (git+https://github.com/bjz/gl-rs)", + "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "xml-rs 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "image" +version = "0.3.9" +source = "git+https://github.com/pistondevelopers/image#75f9b791d6b030bc975ec737e9a2d78de39331af" +dependencies = [ + "byteorder 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "enum_primitive 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "interpolation" +version = "0.0.5" +source = "git+https://github.com/PistonDevelopers/interpolation#c0c9e970e42a48402514285a5608e4729cf83298" + +[[package]] +name = "khronos_api" +version = "0.0.5" +source = "git+https://github.com/bjz/gl-rs#62b66a85e4c2c0d88fb916040bc462702c8e0346" + +[[package]] +name = "khronos_api" +version = "0.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libz-sys" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "log" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "piston" +version = "0.1.1" +source = "git+https://github.com/pistondevelopers/piston#e4b588cf22275acb230a4d6baace2567ea66391a" +dependencies = [ + "pistoncore-event 0.1.3 (git+https://github.com/pistondevelopers/event)", + "pistoncore-input 0.0.9 (git+https://github.com/pistondevelopers/input)", + "pistoncore-window 0.1.2 (git+https://github.com/pistondevelopers/window)", +] + +[[package]] +name = "piston-float" +version = "0.0.1" +source = "git+https://github.com/pistondevelopers/float#2c73a3e34c384c79e95b35c069d5a69dda3a0cc4" + +[[package]] +name = "piston-shaders_graphics2d" +version = "0.0.0" +source = "git+https://github.com/pistondevelopers/shaders#a2cbd6c63b5cb6852f2bef9e28e04301bca96efe" + +[[package]] +name = "piston-texture" +version = "0.0.1" +source = "git+https://github.com/pistondevelopers/texture#3cc4cddc3f8c51c36ea11dd2f63d70aa887f53fb" + +[[package]] +name = "piston-viewport" +version = "0.0.2" +source = "git+https://github.com/pistondevelopers/viewport#3819edeb0982d2552669e03ad9c0317e75340510" +dependencies = [ + "piston-float 0.0.1 (git+https://github.com/pistondevelopers/float)", +] + +[[package]] +name = "piston2d-graphics" +version = "0.0.46" +source = "git+https://github.com/pistondevelopers/graphics#e5885956fd49bafa968f85976b153b341a473389" +dependencies = [ + "draw_state 0.0.7 (git+https://github.com/gfx-rs/draw_state)", + "interpolation 0.0.5 (git+https://github.com/PistonDevelopers/interpolation)", + "piston-texture 0.0.1 (git+https://github.com/pistondevelopers/texture)", + "piston-viewport 0.0.2 (git+https://github.com/pistondevelopers/viewport)", + "read_color 0.0.2 (git+https://github.com/PistonDevelopers/read_color)", + "vecmath 0.0.22 (git+https://github.com/PistonDevelopers/vecmath)", +] + +[[package]] +name = "piston2d-opengl_graphics" +version = "0.0.16" +source = "git+https://github.com/pistondevelopers/opengl_graphics#c5d22694c53d58290b9e58e3411053d39250da89" +dependencies = [ + "freetype-rs 0.0.9 (git+https://github.com/PistonDevelopers/freetype-rs.git)", + "gl 0.0.12 (git+https://github.com/bjz/gl-rs)", + "image 0.3.9 (git+https://github.com/pistondevelopers/image)", + "khronos_api 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "piston-shaders_graphics2d 0.0.0 (git+https://github.com/pistondevelopers/shaders)", + "piston-texture 0.0.1 (git+https://github.com/pistondevelopers/texture)", + "piston2d-graphics 0.0.46 (git+https://github.com/pistondevelopers/graphics)", + "shader_version 0.0.6 (git+https://github.com/pistondevelopers/shader_version)", +] + +[[package]] +name = "pistoncore-event" +version = "0.1.3" +source = "git+https://github.com/pistondevelopers/event#c51e721f4b346fe7cc8a4c0e2658a70d257202ce" +dependencies = [ + "pistoncore-event_loop 0.1.5 (git+https://github.com/PistonDevelopers/event_loop)", + "pistoncore-input 0.0.9 (git+https://github.com/pistondevelopers/input)", + "pistoncore-window 0.1.2 (git+https://github.com/pistondevelopers/window)", +] + +[[package]] +name = "pistoncore-event_loop" +version = "0.1.5" +source = "git+https://github.com/PistonDevelopers/event_loop#d7541e44e33016b0584579e800879120cf982639" +dependencies = [ + "clock_ticks 0.0.5 (git+https://github.com/tomaka/clock_ticks)", + "piston-viewport 0.0.2 (git+https://github.com/pistondevelopers/viewport)", + "pistoncore-window 0.1.2 (git+https://github.com/pistondevelopers/window)", +] + +[[package]] +name = "pistoncore-input" +version = "0.0.9" +source = "git+https://github.com/pistondevelopers/input#cb0615041f0dd1e4cd1cfc6d4e0e4bae0a575a8e" +dependencies = [ + "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "pistoncore-sdl2_window" +version = "0.0.13" +source = "git+https://github.com/pistondevelopers/sdl2_window#d9dd95cadd5c8de09ddb163812761738b999b3f4" +dependencies = [ + "gl 0.0.12 (git+https://github.com/bjz/gl-rs)", + "num 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", + "piston 0.1.1 (git+https://github.com/pistondevelopers/piston)", + "sdl2 0.2.3 (git+https://github.com/AngryLawyer/rust-sdl2)", + "shader_version 0.0.6 (git+https://github.com/pistondevelopers/shader_version)", +] + +[[package]] +name = "pistoncore-window" +version = "0.1.2" +source = "git+https://github.com/pistondevelopers/window#73314c130ce0b8fc22e47fc636a4724b6e02a365" +dependencies = [ + "libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "pistoncore-input 0.0.9 (git+https://github.com/pistondevelopers/input)", +] + +[[package]] +name = "pkg-config" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "read_color" +version = "0.0.2" +source = "git+https://github.com/PistonDevelopers/read_color#568723fb7d9a69833e1d5a5ec79ded8ce9562920" + +[[package]] +name = "rustc-serialize" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "sdl2" +version = "0.2.3" +source = "git+https://github.com/AngryLawyer/rust-sdl2#f270e9879cd91324a3adc7c0367971e7cda27b9c" +dependencies = [ + "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sdl2-sys 0.2.2 (git+https://github.com/AngryLawyer/rust-sdl2)", +] + +[[package]] +name = "sdl2-sys" +version = "0.2.2" +source = "git+https://github.com/AngryLawyer/rust-sdl2#f270e9879cd91324a3adc7c0367971e7cda27b9c" +dependencies = [ + "libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "shader_version" +version = "0.0.6" +source = "git+https://github.com/pistondevelopers/shader_version#14aa73be33b6d23d6b3cb27f94426545372df287" + +[[package]] +name = "vecmath" +version = "0.0.22" +source = "git+https://github.com/PistonDevelopers/vecmath#d6bb5cf609b51cae8f296945e179bd42a74c9a51" +dependencies = [ + "piston-float 0.0.1 (git+https://github.com/pistondevelopers/float)", +] + +[[package]] +name = "xml-rs" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + diff --git a/src/app.rs b/src/app.rs index 9d391de..2ecaca1 100644 --- a/src/app.rs +++ b/src/app.rs @@ -100,7 +100,7 @@ impl<'a> App<'a> { let w_bg_col = self.window_background_color; let ref nr = self.number_renderer; - gl.draw([0,0,args.width as i32, args.height as i32], |_, gl| { + gl.draw(args.viewport(), |_, gl| { clear(w_bg_col, gl); self.render_ui(c, gl); self.board.render(nr.iter().next().unwrap(), c, gl); diff --git a/src/board.rs b/src/board.rs index 18ceb08..07b929f 100644 --- a/src/board.rs +++ b/src/board.rs @@ -1,10 +1,10 @@ use std::collections::HashSet; -use std::iter::range_step_inclusive; +// use std::iter::range_step_inclusive; use rand::random; use graphics::*; use opengl_graphics::{ - Gl, + GlGraphics, }; use number_renderer::NumberRenderer; use settings::Settings; @@ -18,7 +18,6 @@ fn rgb2rgba(c: [f32; 3]) -> [f32; 4] { [c[0], c[1], c[2], 1.0] } pub struct Board<'a> { tiles: Vec>, score: i32, - settings: &'a Settings, } @@ -53,7 +52,7 @@ impl<'a> Board<'a> { for tile in self.tiles.iter_mut() { tile.update(dt); } - + if self.is_locking() { return; } @@ -68,8 +67,8 @@ impl<'a> Board<'a> { for j in i+1..self.tiles.len() { let tile2 = &self.tiles[j]; if tile2.status != TileState::TileStatic - || tile1.tile_x != tile2.tile_x - || tile1.tile_y != tile2.tile_y { + || tile1.tile_x != tile2.tile_x + || tile1.tile_y != tile2.tile_y { continue; } @@ -88,19 +87,22 @@ impl<'a> Board<'a> { tiles.push(self.tiles[i].clone()); } } - tiles.append(&mut tiles_need_added); + // better but unstable: tiles.append(&mut tiles_need_added); + while let Some(tile_to_add) = tiles_need_added.pop() { + tiles.push(tile_to_add); + } self.tiles = tiles; self.add_score(score_to_added); } } - pub fn render(&self, number_renderer: &NumberRenderer, c: &Context, gl: &mut Gl) { + pub fn render(&self, number_renderer: &NumberRenderer, c: &Context, gl: &mut GlGraphics) { number_renderer.render( - self.score as u32, - self.settings.best_rect[0] + self.settings.best_rect[2] / 2.0, - self.settings.best_rect[1] + self.settings.best_rect[3] / 2.0, - self.settings.best_rect[2], - self.settings.text_light_color, c, gl); + self.score as u32, + self.settings.best_rect[0] + self.settings.best_rect[2] / 2.0, + self.settings.best_rect[1] + self.settings.best_rect[3] / 2.0, + self.settings.best_rect[2], + self.settings.text_light_color, c, gl); self.render_board(c, gl); self.render_tiles(number_renderer, c, gl); @@ -118,20 +120,28 @@ impl<'a> Board<'a> { fn merge_col(&mut self, y_start: i32, y_end: i32, y_step: i32) { if self.is_locking() { + println!("return"); return; } - let mut need_generate = false; + let mut steps: Vec = Vec::with_capacity(self.settings.tile_height as usize); + let mut next_step = y_start; + if y_step < 0 { + while next_step > y_end { steps.push(next_step); next_step += y_step } + } else { + while next_step < y_end { steps.push(next_step); next_step += y_step } + }; loop { // move all tiles to right place - for col in 0..self.settings.tile_width { - for row in range_step_inclusive(y_start, y_end, y_step) { + for col in 0 .. self.settings.tile_width { + // TODO: replace steps by (y_start .. y_end).step_by(y_step) if step_by becomes stable + for row in steps.to_vec() { match self.get_mut_tile(col, row) { None => { match self.get_mut_next_tile(col, row, 0, y_step) { Some(ref mut tile) => { println!("move ({}, {}) to ({}, {})", - tile.tile_x, tile.tile_y, col, row); + tile.tile_x, tile.tile_y, col, row); need_generate = true; tile.start_moving(col, row); }, @@ -150,13 +160,13 @@ impl<'a> Board<'a> { let mut sy = 0; let mut dx = 0; let mut dy = 0; - for row in range_step_inclusive(y_start, y_end, y_step) { + for row in steps.to_vec() { match self.get_tile(col, row) { Some(ref d_tile) => { match self.get_next_tile(col, row, 0, y_step) { Some(ref s_tile) if d_tile.score == s_tile.score - && self.get_tile_count(d_tile.tile_x, d_tile.tile_y) == 1 => { + && self.get_tile_count(d_tile.tile_x, d_tile.tile_y) == 1 => { found = true; dx = d_tile.tile_x; dy = d_tile.tile_y; @@ -206,10 +216,18 @@ impl<'a> Board<'a> { } let mut need_generate = false; + let mut steps: Vec = Vec::with_capacity(self.settings.tile_width as usize); + let mut next_step = x_start; + if x_step < 0 { + while next_step > x_end { steps.push(next_step); next_step += x_step } + } else { + while next_step < x_end { steps.push(next_step); next_step += x_step } + }; loop { // move all tiles to right place for row in 0..self.settings.tile_height { - for col in range_step_inclusive(x_start, x_end, x_step) { + for col in steps.to_vec() { + match self.get_mut_tile(col, row) { None => { match self.get_mut_next_tile(col, row, x_step, 0) { @@ -234,13 +252,13 @@ impl<'a> Board<'a> { let mut sy = 0; let mut dx = 0; let mut dy = 0; - for col in range_step_inclusive(x_start, x_end, x_step) { + for col in steps.to_vec() { match self.get_tile(col, row) { Some(ref d_tile) => { match self.get_next_tile(col, row, x_step, 0) { Some(ref s_tile) if d_tile.score == s_tile.score - && self.get_tile_count(d_tile.tile_x, d_tile.tile_y) == 1 => { + && self.get_tile_count(d_tile.tile_x, d_tile.tile_y) == 1 => { found = true; dx = d_tile.tile_x; dy = d_tile.tile_y; @@ -289,7 +307,7 @@ impl<'a> Board<'a> { let mut x = x + step_x; let mut y = y + step_y; while x >= 0 && x < self.settings.tile_width - && y >= 0 && y < self.settings.tile_height { + && y >= 0 && y < self.settings.tile_height { let tile = self.get_tile(x, y); if tile.is_some() { return tile; @@ -305,7 +323,7 @@ impl<'a> Board<'a> { let mut y = y + step_y; let mut found = false; while x >= 0 && x < self.settings.tile_width - && y >= 0 && y < self.settings.tile_height { + && y >= 0 && y < self.settings.tile_height { let tile = self.get_tile(x, y); if tile.is_some() { found = true; @@ -316,7 +334,7 @@ impl<'a> Board<'a> { } if found { - self.get_mut_tile(x, y) + self.get_mut_tile(x, y) } else { None } @@ -350,25 +368,25 @@ impl<'a> Board<'a> { count } - fn render_board(&self, c: &Context, gl: &mut Gl) { + fn render_board(&self, c: &Context, gl: &mut GlGraphics) { Rectangle::new(rgb2rgba(self.settings.label_color)) - .draw([self.settings.board_padding, - self.settings.board_padding + self.settings.board_offset_y, - self.settings.board_size[0], - self.settings.board_size[1]], - default_draw_state(), - c.transform, - gl); - + .draw([self.settings.board_padding, + self.settings.board_padding + self.settings.board_offset_y, + self.settings.board_size[0], + self.settings.board_size[1]], + default_draw_state(), + c.transform, + gl); + let mut x = self.settings.board_padding + self.settings.tile_padding; let mut y = self.settings.board_padding + self.settings.board_offset_y + self.settings.tile_padding; for _ in 0..self.settings.tile_height { for _ in 0..self.settings.tile_width { Rectangle::new(rgb2rgba(self.settings.tiles_colors[0])) - .draw([x, y, self.settings.tile_size, self.settings.tile_size], - default_draw_state(), - c.transform, - gl); + .draw([x, y, self.settings.tile_size, self.settings.tile_size], + default_draw_state(), + c.transform, + gl); x += self.settings.tile_padding + self.settings.tile_size; } @@ -377,7 +395,7 @@ impl<'a> Board<'a> { } } - fn render_tiles(&self, number_renderer: &NumberRenderer, c: &Context, gl: &mut Gl) { + fn render_tiles(&self, number_renderer: &NumberRenderer, c: &Context, gl: &mut GlGraphics) { for tile in self.tiles.iter() { tile.render(number_renderer, c, gl); } diff --git a/src/main.rs b/src/main.rs index db51236..cea4115 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,3 @@ - -#![feature(core,collections,path_ext)] - extern crate rustc_serialize; extern crate rand; @@ -45,19 +42,19 @@ fn main() { for e in window.events() { use piston::event::{ RenderEvent, PressEvent }; - if let Some(ref args) = e.render_args() { app.render(args, &mut gl); } - if let Some(ref args) = e.update_args() { - app.update(args); + if let Some(ref args) = e.update_args() { + // TODO: only update if necessary + // println!("update"); + app.update(args); } - if let Some(ref args) = e.press_args() { app.key_press(args); } - } +} /* for e in GameIterator::new(&mut window, &game_iter_settings) { diff --git a/src/number_renderer.rs b/src/number_renderer.rs index 13660c6..9057446 100644 --- a/src/number_renderer.rs +++ b/src/number_renderer.rs @@ -2,7 +2,7 @@ use std::path::Path; use graphics::*; use opengl_graphics::{ - Gl, + GlGraphics, Texture, }; @@ -21,7 +21,7 @@ impl NumberRenderer { } pub fn render(&self, number: u32, center_x: f64, center_y: f64, max_width: f64, - color: [f32; 3], c: &Context, gl: &mut Gl) { + color: [f32; 3], c: &Context, gl: &mut GlGraphics) { let digits = number_to_digits(number); let total_width = DIGITS_WIDTH * digits.len() as f64; let total_width = if total_width > max_width { @@ -36,7 +36,7 @@ impl NumberRenderer { for digit in digits.iter() { Image::new_colored([color[0], color[1], color[2], 1.0]) - .src_rect([(*digit * DIGITS_WIDTH as u32) as i32, 0, (*digit * DIGITS_WIDTH as u32) as i32 + DIGITS_WIDTH as i32, DIGITS_HEIGHT as i32]) + .src_rect([(*digit * DIGITS_WIDTH as u32) as i32, 0, DIGITS_WIDTH as i32, DIGITS_HEIGHT as i32]) .rect([x, y, width, height]) .draw(&self.image, default_draw_state(), diff --git a/src/settings.rs b/src/settings.rs index 55788e0..0f400ea 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -1,7 +1,7 @@ use std::env::current_exe; use std::io::{BufWriter, BufReader, Write}; -use std::fs::{File,PathExt}; +use std::fs::{File}; use std::path::Path; use rustc_serialize::{ json, @@ -219,7 +219,8 @@ impl SettingsInJson { let mut exe_path = exe_path.unwrap(); exe_path.pop(); let path = exe_path.join(Path::new(SETTING_FILENAME)); - if !path.as_path().exists() || !path.is_file() { +// FIXME: use this if possible (.exists() is unstable in Rust 1.0.0) +/* if !path.as_path().exists() || !path.is_file() { println!("Configuration file not found. Generating a default one."); let default = SettingsInJson::default_settings(); default.save(); @@ -227,6 +228,19 @@ impl SettingsInJson { } let file = File::open(&path).unwrap(); let mut reader = BufReader::new(file); +*/ + let file = File::open(&path); + match file { + Err(e) => { + println!("Configuration file can't be open ({}). Try to generate a default one.", e); + let default = SettingsInJson::default_settings(); + default.save(); + return default; + }, + _ => {} + } + let mut reader = BufReader::new(file.unwrap()); +// End FIXME let mut decoder = json::Decoder::new(json::Json::from_reader(&mut reader).unwrap()); Decodable::decode(&mut decoder).unwrap() } diff --git a/src/tile.rs b/src/tile.rs index f522550..6e2164b 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -1,6 +1,6 @@ use graphics::*; -use opengl_graphics::Gl; +use opengl_graphics::GlGraphics; use number_renderer::NumberRenderer; use settings::Settings; @@ -103,7 +103,7 @@ impl<'a> Tile<'a> { } } - pub fn render(&self, number_renderer: &NumberRenderer, c: &Context, gl: &mut Gl) { + pub fn render(&self, number_renderer: &NumberRenderer, c: &Context, gl: &mut GlGraphics) { let mut pos = self.tile_to_pos(self.tile_x, self.tile_y); let mut size = (self.settings.tile_size, self.settings.tile_size); match self.status {