decor.rs 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. use crate::map::util::extract_image_from_tileset;
  2. use ggez::graphics;
  3. use std::collections::HashMap;
  4. use std::path::Path;
  5. use tiled::{Image as TiledImage, Layer, Tileset};
  6. pub struct DecorTile {
  7. pub tileset_i: usize, // Used to rely tileset/sprite_batch in Decor
  8. pub tile_width: u32,
  9. pub tile_height: u32,
  10. pub relative_tile_width: f32,
  11. pub relative_tile_height: f32,
  12. pub tile_x: u32,
  13. pub tile_y: u32,
  14. }
  15. impl DecorTile {
  16. pub fn new(
  17. tileset_i: usize, // Used to rely tileset/sprite_batch in Decor
  18. tile_width: u32,
  19. tile_height: u32,
  20. relative_tile_width: f32,
  21. relative_tile_height: f32,
  22. tile_x: u32,
  23. tile_y: u32,
  24. ) -> Self {
  25. Self {
  26. tileset_i,
  27. tile_width,
  28. tile_height,
  29. relative_tile_width,
  30. relative_tile_height,
  31. tile_x,
  32. tile_y,
  33. }
  34. }
  35. }
  36. pub struct Decor {
  37. pub layer: Layer,
  38. pub tilesets: Vec<Tileset>,
  39. pub images: Vec<TiledImage>,
  40. // FIXME (u32, u32) -> GridPoint
  41. pub tiles: HashMap<(u32, u32), DecorTile>,
  42. }
  43. impl Decor {
  44. pub fn new(
  45. layer: Layer,
  46. tilesets: Vec<Tileset>,
  47. images: Vec<TiledImage>,
  48. tiles: HashMap<(u32, u32), DecorTile>,
  49. ) -> Self {
  50. Self {
  51. layer,
  52. tilesets,
  53. images,
  54. tiles,
  55. }
  56. }
  57. }