From 3aac7e87ab1ff21f66eb8a5dd547a3a96fec1219 Mon Sep 17 00:00:00 2001 From: dani Date: Mon, 3 Jul 2023 14:52:13 +0000 Subject: [PATCH] cleanup --- src/hexmap.rs | 2 -- src/image.rs | 10 ++++------ src/lib.rs | 1 - src/tileset.rs | 4 ++++ src/vec2.rs | 4 +--- src/window.rs | 6 +++--- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/hexmap.rs b/src/hexmap.rs index f221522..97e6cc7 100644 --- a/src/hexmap.rs +++ b/src/hexmap.rs @@ -1,5 +1,4 @@ use crate::{Image, Tileset, Vec2}; -use num::complex::ComplexFloat; use std::rc::Rc; //odd-q vertical layout https://www.redblobgames.com/grids/hexagons @@ -49,7 +48,6 @@ impl HexMap { } y -= x % 2; } - let slice = xrepeat / (tilesize.x / 4); Vec2 { x, y } } diff --git a/src/image.rs b/src/image.rs index 3c02521..e385daa 100644 --- a/src/image.rs +++ b/src/image.rs @@ -1,7 +1,6 @@ use crate::vec2::Vec2; use crate::{HexMap, Rect, Tileset}; use std::fs; -use std::fs::File; use std::rc::Rc; //todo: make dynamically different bitdepths @@ -57,9 +56,7 @@ impl Image { pub fn draw_hexmap(&mut self, pos: Vec2, hexmap: &HexMap) { for i in hexmap.size().to_rect().iter() { - if i.x % 1 == 0 { - hexmap.draw_tile_to_image(self, i, pos); - } + hexmap.draw_tile_to_image(self, i, pos); } } @@ -117,13 +114,14 @@ impl Image { pub fn draw_string(&mut self, pos: Vec2, str: &str, font: &Tileset) { assert!(str.is_ascii()); let array = str.as_bytes(); - for i in 0..array.len() { + //for i in 0..array.len() + for (i, idx) in array.iter().enumerate() { self.draw_image( Vec2 { x: pos.x + font.tile_size().x * i as i32, y: pos.y, }, - font.get(array[i] as i32), + font.get(*idx as i32), ); } } diff --git a/src/lib.rs b/src/lib.rs index f039597..4ace6ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,6 @@ mod tileset; mod vec2; mod window; -pub use console::*; pub use hexmap::*; pub use image::*; pub use rect::*; diff --git a/src/tileset.rs b/src/tileset.rs index c5055d6..ae8864e 100644 --- a/src/tileset.rs +++ b/src/tileset.rs @@ -47,6 +47,10 @@ impl Tileset { &self.images[idx as usize] } + pub fn count(&self) -> i32 { + self.count + } + pub fn tile_size(&self) -> Vec2 { self.size } diff --git a/src/vec2.rs b/src/vec2.rs index 1f2522b..c9c6a6c 100644 --- a/src/vec2.rs +++ b/src/vec2.rs @@ -1,9 +1,7 @@ use crate::Rect; use num::{Num, ToPrimitive}; use std::cmp::Ordering; -use std::cmp::Ordering::{Greater, Less}; -use std::ops::{Add, AddAssign, Range, Sub, SubAssign}; -use Ordering::Equal; +use std::ops::{Add, AddAssign, Sub, SubAssign}; #[derive(Copy, Clone)] pub struct Vec2 { diff --git a/src/window.rs b/src/window.rs index 8d3e4c7..3ef8514 100644 --- a/src/window.rs +++ b/src/window.rs @@ -117,9 +117,9 @@ pub fn run(width: i32, height: i32) { let mut off_y = 0usize; event_loop.run_return(move |event, _, control_flow| { - let mut scale = &mut scale; - let mut off_x = &mut off_x; - let mut off_y = &mut off_y; + let scale = &mut scale; + let off_x = &mut off_x; + let off_y = &mut off_y; if Instant::now() - last_second > Duration::from_secs(1) { println!("fps: {}", frames_since_last_second); frames_since_last_second = 0;