rust/mapgen/src/theme.rs
branchtransitional_engine
changeset 16004 2146cb7be36f
parent 15944 c571d4b8879c
parent 15957 0710feb75c99
equal deleted inserted replaced
15958:772a43d88e6b 16004:2146cb7be36f
       
     1 use integral_geometry::{Point, Rect};
     1 use png::{ColorType, Decoder, DecodingError};
     2 use png::{ColorType, Decoder, DecodingError};
     2 use std::{
     3 use std::{
     3     fs::{read_dir, File},
     4     fs::{read_dir, File},
     4     io,
     5     io,
     5     io::BufReader,
     6     io::BufReader,
   107     pub fn get_pixel(&self, x: usize, y: usize) -> u32 {
   108     pub fn get_pixel(&self, x: usize, y: usize) -> u32 {
   108         self.pixels[get_tiled_index(x, y, self.tile_width_shift)]
   109         self.pixels[get_tiled_index(x, y, self.tile_width_shift)]
   109     }
   110     }
   110 }
   111 }
   111 
   112 
       
   113 #[derive(Default)]
       
   114 struct Color(u8, u8, u8, u8);
       
   115 
       
   116 pub struct LandObjectOverlay {
       
   117     texture: ThemeSprite,
       
   118     offset: Point,
       
   119 }
       
   120 
       
   121 pub struct LandObject {
       
   122     texture: ThemeSprite,
       
   123     inland_rects: Vec<Rect>,
       
   124     outland_rects: Vec<Rect>,
       
   125     anchors: Vec<Rect>,
       
   126     overlays: Vec<LandObjectOverlay>,
       
   127 }
       
   128 
       
   129 pub struct LandSpray {
       
   130     texture: ThemeSprite,
       
   131     count: u16,
       
   132 }
       
   133 
       
   134 #[derive(Default)]
       
   135 pub struct ThemeColors {
       
   136     border: Color,
       
   137 }
       
   138 
       
   139 pub struct Flakes {
       
   140     texture: ThemeSprite,
       
   141     frames_count: u16,
       
   142     frame_ticks: u16,
       
   143     velocity: u16,
       
   144     fall_speed: u16,
       
   145 }
       
   146 
       
   147 #[derive(Default)]
       
   148 pub struct Water {
       
   149     top_color: Color,
       
   150     bottom_color: Color,
       
   151     opacity: u8,
       
   152 }
       
   153 
       
   154 #[derive(Default)]
       
   155 pub struct ThemeParts {
       
   156     water: Water,
       
   157     flakes: Option<Flakes>,
       
   158     music: String,
       
   159     sky: Color,
       
   160     tint: Color,
       
   161 }
       
   162 
       
   163 #[derive(Default)]
   112 pub struct Theme {
   164 pub struct Theme {
       
   165     border_color: Color,
       
   166     clouds_count: u16,
       
   167     flatten_flakes: bool,
   113     land_texture: Option<ThemeSprite>,
   168     land_texture: Option<ThemeSprite>,
   114     border_texture: Option<ThemeSprite>,
   169     border_texture: Option<ThemeSprite>,
       
   170     land_objects: Vec<LandObject>,
       
   171     spays: Vec<LandSpray>,
       
   172     use_ice: bool,
       
   173     use_snow: bool,
       
   174     music: String,
       
   175     normal_parts: ThemeParts,
       
   176     sd_parts: ThemeParts,
   115 }
   177 }
   116 
   178 
   117 impl Theme {
   179 impl Theme {
   118     pub fn land_texture(&self) -> Option<&ThemeSprite> {
   180     pub fn land_texture(&self) -> Option<&ThemeSprite> {
   119         self.land_texture.as_ref()
   181         self.land_texture.as_ref()
   143     }
   205     }
   144 }
   206 }
   145 
   207 
   146 impl Theme {
   208 impl Theme {
   147     pub fn new() -> Self {
   209     pub fn new() -> Self {
   148         Theme {
   210         Default::default()
   149             land_texture: None,
       
   150             border_texture: None,
       
   151         }
       
   152     }
   211     }
   153 
   212 
   154     pub fn load(path: &Path) -> Result<Theme, ThemeLoadError> {
   213     pub fn load(path: &Path) -> Result<Theme, ThemeLoadError> {
   155         let mut theme = Self::new();
   214         let mut theme = Self::new();
   156 
   215