rpfm_lib/files/tile_database/tile_variation/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//! Tile variation definitions for the tile database.
12//!
13//! This module contains the [`TileVariation`] struct, which defines visual and rendering
14//! variations for tiles. Variations allow the terrain system to add diversity to terrain
15//! appearance through different textures, colors, and rendering parameters.
16
17use serde_derive::{Serialize, Deserialize};
18
19use crate::binary::{ReadBytes, WriteBytes};
20use crate::error::{Result, RLibError};
21use crate::files::{Decodeable, EncodeableExtraData, Encodeable};
22
23use super::*;
24
25mod v2;
26
27//---------------------------------------------------------------------------//
28// Enum & Structs
29//---------------------------------------------------------------------------//
30
31/// A visual variation for terrain tiles.
32///
33/// Tile variations define different appearances for tiles, including height,
34/// scale, normal mapping, blending, and color tinting. This allows for more
35/// diverse and natural-looking terrain.
36#[derive(Default, PartialEq, Clone, Debug, Getters, MutGetters, Setters, Serialize, Deserialize)]
37#[getset(get = "pub", get_mut = "pub", set = "pub")]
38pub struct TileVariation {
39 /// Serialization version for this structure.
40 serialise_version: u16,
41
42 /// Path or identifier for this variation's location.
43 location: String,
44 /// Minimum height at which this variation appears.
45 min_height: f32,
46 /// Scale factor for this variation.
47 scale: f32,
48 /// Strength of normal mapping for surface detail.
49 normal_strength: f32,
50 /// Size of the overlap border for blending with adjacent tiles.
51 overlap_border_size: f32,
52 /// Triangle density for raw terrain data.
53 raw_data_tri_density: u32,
54 /// Path to the common blend texture.
55 blend_common: String,
56 /// Path to the common index texture.
57 index_common: String,
58 /// Path to the common normal map texture.
59 normal_common: String,
60 /// Red component of the color tint (0.0-1.0).
61 red: f32,
62 /// Green component of the color tint (0.0-1.0).
63 green: f32,
64 /// Blue component of the color tint (0.0-1.0).
65 blue: f32,
66 /// Whether this variation uses the "barbarian" terrain style.
67 barbarian: bool,
68}
69
70//---------------------------------------------------------------------------//
71// Implementation of TileVariation
72//---------------------------------------------------------------------------//
73
74impl Decodeable for TileVariation {
75
76 fn decode<R: ReadBytes>(data: &mut R, extra_data: &Option<DecodeableExtraData>) -> Result<Self> {
77 let mut decoded = Self::default();
78 decoded.serialise_version = data.read_u16()?;
79
80 match decoded.serialise_version {
81 2 => decoded.read_v2(data, extra_data)?,
82 _ => return Err(RLibError::DecodingFastBinUnsupportedVersion(String::from("TileVariation"), decoded.serialise_version)),
83 }
84
85 Ok(decoded)
86 }
87}
88
89impl Encodeable for TileVariation {
90
91 fn encode<W: WriteBytes>(&mut self, buffer: &mut W, extra_data: &Option<EncodeableExtraData>) -> Result<()> {
92 buffer.write_u16(self.serialise_version)?;
93
94 match self.serialise_version {
95 2 => self.write_v2(buffer, extra_data)?,
96 _ => return Err(RLibError::EncodingFastBinUnsupportedVersion(String::from("TileVariation"), self.serialise_version)),
97 }
98
99 Ok(())
100 }
101}