rpfm_lib/files/tile_database/climate/mod.rs
1//---------------------------------------------------------------------------//
2// Copyright (c) 2017-2026 Ismael Gutiérrez González. All rights reserved.
3//
4// This file is part of the Rusted PackFile Manager (RPFM) project,
5// which can be found here: https://github.com/Frodo45127/rpfm.
6//
7// This file is licensed under the MIT license, which can be found here:
8// https://github.com/Frodo45127/rpfm/blob/master/LICENSE.
9//---------------------------------------------------------------------------//
10
11//! Climate definitions for terrain tiles.
12//!
13//! Climates define environmental variations for terrain (e.g., temperate, desert, snow).
14//! Each climate has associated textures and colour modifiers that affect how tiles appear.
15
16use serde_derive::{Serialize, Deserialize};
17
18use crate::binary::{ReadBytes, WriteBytes};
19use crate::error::{Result, RLibError};
20use crate::files::{Decodeable, EncodeableExtraData, Encodeable};
21
22use super::{*, texture::Texture};
23
24mod v3;
25
26//---------------------------------------------------------------------------//
27// Enum & Structs
28//---------------------------------------------------------------------------//
29
30/// A climate definition with textures and colour modifiers.
31///
32/// Climates affect the visual appearance of terrain tiles by providing
33/// texture sets and colour adjustments for different environmental conditions.
34#[derive(Default, PartialEq, Clone, Debug, Getters, MutGetters, Setters, Serialize, Deserialize)]
35#[getset(get = "pub", get_mut = "pub", set = "pub")]
36pub struct Climate {
37 /// Serialisation format version.
38 serialise_version: u16,
39
40 /// Climate identifier name.
41 name: String,
42 /// Associated texture set name.
43 texture_set: String,
44 /// Red colour modifier (0.0-1.0).
45 red: f32,
46 /// Green colour modifier (0.0-1.0).
47 green: f32,
48 /// Blue colour modifier (0.0-1.0).
49 blue: f32,
50
51 /// Textures used by this climate.
52 textures: Vec<Texture>,
53
54 /// Additive grass alpha adjustment.
55 grass_alpha_add: f32,
56 /// Multiplicative grass alpha adjustment.
57 grass_alpha_mul: f32,
58 /// Climate to use for destruction effects.
59 destruction_climate: String,
60}
61
62//---------------------------------------------------------------------------//
63// Implementation of Climate
64//---------------------------------------------------------------------------//
65
66impl Decodeable for Climate {
67
68 fn decode<R: ReadBytes>(data: &mut R, extra_data: &Option<DecodeableExtraData>) -> Result<Self> {
69 let mut decoded = Self::default();
70 decoded.serialise_version = data.read_u16()?;
71
72 match decoded.serialise_version {
73 3 => decoded.read_v3(data, extra_data)?,
74 _ => return Err(RLibError::DecodingFastBinUnsupportedVersion(String::from("Climate"), decoded.serialise_version)),
75 }
76
77 Ok(decoded)
78 }
79}
80
81impl Encodeable for Climate {
82
83 fn encode<W: WriteBytes>(&mut self, buffer: &mut W, extra_data: &Option<EncodeableExtraData>) -> Result<()> {
84 buffer.write_u16(self.serialise_version)?;
85
86 match self.serialise_version {
87 3 => self.write_v3(buffer, extra_data)?,
88 _ => return Err(RLibError::EncodingFastBinUnsupportedVersion(String::from("Climate"), self.serialise_version)),
89 }
90
91 Ok(())
92 }
93}