rpfm_lib/files/tile_database/tile_link/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 link definitions for the tile database.
12//!
13//! This module contains the [`TileLink`] struct, which defines connections between
14//! tiles within the terrain system. Links allow tiles to reference and blend with
15//! other tiles, creating seamless transitions across terrain boundaries.
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 v1;
26
27//---------------------------------------------------------------------------//
28// Enum & Structs
29//---------------------------------------------------------------------------//
30
31/// A link definition connecting tiles within the terrain system.
32///
33/// Tile links define how tiles connect to and blend with other tiles in link sets.
34/// They specify position, blending parameters, and entry points for tile transitions.
35#[derive(Default, PartialEq, Clone, Debug, Getters, MutGetters, Setters, Serialize, Deserialize)]
36#[getset(get = "pub", get_mut = "pub", set = "pub")]
37pub struct TileLink {
38 /// Serialization version for this structure.
39 serialise_version: u16,
40
41 /// Name of the link set this tile link belongs to.
42 link_set: String,
43 /// X coordinate of this link.
44 x: i32,
45 /// Y coordinate of this link.
46 y: i32,
47 /// Base X coordinate for the link origin.
48 base_x: i32,
49 /// Base Y coordinate for the link origin.
50 base_y: i32,
51 /// Whether this link serves as an entry point.
52 is_entry: bool,
53 /// Blend quad indices for texture blending.
54 blend_quads: Vec<u32>,
55 /// Size of the blend area.
56 blend_size: u32,
57 /// If true, disables offline blending for this link.
58 no_offline_blend: bool,
59 /// Test string field (purpose unclear).
60 test: String,
61}
62
63//---------------------------------------------------------------------------//
64// Implementation of TileLink
65//---------------------------------------------------------------------------//
66
67impl Decodeable for TileLink {
68
69 fn decode<R: ReadBytes>(data: &mut R, extra_data: &Option<DecodeableExtraData>) -> Result<Self> {
70 let mut decoded = Self::default();
71 decoded.serialise_version = data.read_u16()?;
72
73 match decoded.serialise_version {
74 1 => decoded.read_v1(data, extra_data)?,
75 _ => return Err(RLibError::DecodingFastBinUnsupportedVersion(String::from("TileLink"), decoded.serialise_version)),
76 }
77
78 Ok(decoded)
79 }
80}
81
82impl Encodeable for TileLink {
83
84 fn encode<W: WriteBytes>(&mut self, buffer: &mut W, extra_data: &Option<EncodeableExtraData>) -> Result<()> {
85 buffer.write_u16(self.serialise_version)?;
86
87 match self.serialise_version {
88 1 => self.write_v1(buffer, extra_data)?,
89 _ => return Err(RLibError::EncodingFastBinUnsupportedVersion(String::from("TileLink"), self.serialise_version)),
90 }
91
92 Ok(())
93 }
94}