Skip to main content

rpfm_lib/files/tile_database/tile/
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//! Individual terrain tile definitions.
12//!
13//! A tile is a square or rectangular battle map that gets placed at a specific
14//! position in the tile map. When a battle occurs at that position on the campaign
15//! map, the corresponding tile is loaded as the battle terrain.
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::{*, tile_link::TileLink, tile_link_target::TileLinkTarget, tile_variation::TileVariation};
24
25mod v3;
26
27//---------------------------------------------------------------------------//
28//                              Enum & Structs
29//---------------------------------------------------------------------------//
30
31/// A single terrain tile definition.
32///
33/// Contains all properties for a terrain tile including dimensions, textures,
34/// rendering flags, and connection rules.
35#[derive(Default, PartialEq, Clone, Debug, Getters, MutGetters, Setters, Serialize, Deserialize)]
36#[getset(get = "pub", get_mut = "pub", set = "pub")]
37pub struct Tile {
38    /// Serialisation format version.
39    serialise_version: u16,
40
41    /// File path or location identifier.
42    location: String,
43    /// Parent tile set name.
44    tile_set: String,
45    /// Mask texture path.
46    mask: String,
47    /// Tile width in units.
48    width: u32,
49    /// Tile height in units.
50    height: u32,
51    /// Red colour component (0.0-1.0).
52    red: f32,
53    /// Green colour component (0.0-1.0).
54    green: f32,
55    /// Blue colour component (0.0-1.0).
56    blue: f32,
57    /// Whether tile requires in-field LOD processing.
58    requires_infield_lodding: bool,
59    /// Whether tile can be randomly rotated during placement.
60    random_rotatable: bool,
61    /// Custom alpha blend texture path.
62    custom_alpha_blend_texture: String,
63    /// Whether tile can be scaled.
64    scalable: bool,
65    /// Whether units can encamp on this tile.
66    encampable: bool,
67    /// Custom blend tile reference.
68    custom_blend_tile: String,
69
70    /// Red channel texture path.
71    texture_red: String,
72    /// Green channel texture path.
73    texture_green: String,
74    /// Blue channel texture path.
75    texture_blue: String,
76    /// Alpha channel texture path.
77    texture_alpha: String,
78
79    /// Visual variations of this tile.
80    variations: Vec<TileVariation>,
81    /// Targets for tile linking.
82    link_targets: Vec<TileLinkTarget>,
83    /// Links to other tiles.
84    links: Vec<TileLink>,
85}
86
87//---------------------------------------------------------------------------//
88//                      Implementation of TileSet
89//---------------------------------------------------------------------------//
90
91impl Decodeable for Tile {
92
93    fn decode<R: ReadBytes>(data: &mut R, extra_data: &Option<DecodeableExtraData>) -> Result<Self> {
94        let mut decoded = Self::default();
95        decoded.serialise_version = data.read_u16()?;
96
97        match decoded.serialise_version {
98            3 => decoded.read_v3(data, extra_data)?,
99            _ => return Err(RLibError::DecodingFastBinUnsupportedVersion(String::from("Tile"), decoded.serialise_version)),
100        }
101
102        Ok(decoded)
103    }
104}
105
106impl Encodeable for Tile {
107
108    fn encode<W: WriteBytes>(&mut self, buffer: &mut W, extra_data: &Option<EncodeableExtraData>) -> Result<()> {
109        buffer.write_u16(self.serialise_version)?;
110
111        match self.serialise_version {
112            3 => self.write_v3(buffer, extra_data)?,
113            _ => return Err(RLibError::EncodingFastBinUnsupportedVersion(String::from("Tile"), self.serialise_version)),
114        }
115
116        Ok(())
117    }
118}