rpfm_lib/files/bmd/common/properties/
mod.rs

1//---------------------------------------------------------------------------//
2// Copyright (c) 2017-2024 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
11use getset::*;
12use serde_derive::{Serialize, Deserialize};
13
14use crate::binary::{ReadBytes, WriteBytes};
15use crate::error::{Result, RLibError};
16use crate::files::{Decodeable, EncodeableExtraData, Encodeable};
17
18use super::*;
19
20mod v4;
21mod v6;
22mod v7;
23mod v11;
24
25//---------------------------------------------------------------------------//
26//                              Enum & Structs
27//---------------------------------------------------------------------------//
28
29#[derive(Default, PartialEq, Clone, Debug, Getters, MutGetters, Setters, Serialize, Deserialize)]
30#[getset(get = "pub", get_mut = "pub", set = "pub")]
31pub struct Properties {
32    serialise_version: u16,
33    building_id: String,
34    starting_damage_unary: f32,
35    on_fire: bool,
36    start_disabled: bool,
37    weak_point: bool,
38    ai_breachable: bool,
39    indestructible: bool,
40    dockable: bool,
41    toggleable: bool,
42    lite: bool,
43    clamp_to_surface: bool,
44    cast_shadows: bool,
45    dont_merge_building: bool,
46    key_building: bool,
47    key_building_use_fort: bool,
48    is_prop_in_outfield: bool,
49    settlement_level_configurable: bool,
50    hide_tooltip: bool,
51    include_in_fog: bool,
52    tint_inherit_from_parent: bool,
53}
54
55//---------------------------------------------------------------------------//
56//                           Implementation of Properties
57//---------------------------------------------------------------------------//
58
59impl Decodeable for Properties {
60
61    fn decode<R: ReadBytes>(data: &mut R, extra_data: &Option<DecodeableExtraData>) -> Result<Self> {
62        let mut flags = Self::default();
63        flags.serialise_version = data.read_u16()?;
64
65        match flags.serialise_version {
66            4 => flags.read_v4(data, extra_data)?,
67            6 => flags.read_v6(data, extra_data)?,
68            7 => flags.read_v7(data, extra_data)?,
69            11 => flags.read_v11(data, extra_data)?,
70            _ => return Err(RLibError::DecodingFastBinUnsupportedVersion(String::from("Properties"), flags.serialise_version)),
71        }
72
73        Ok(flags)
74    }
75}
76
77impl Encodeable for Properties {
78
79    fn encode<W: WriteBytes>(&mut self, buffer: &mut W, extra_data: &Option<EncodeableExtraData>) -> Result<()> {
80        buffer.write_u16(self.serialise_version)?;
81
82        match self.serialise_version {
83            4 => self.write_v4(buffer, extra_data)?,
84            6 => self.write_v6(buffer, extra_data)?,
85            7 => self.write_v7(buffer, extra_data)?,
86            11 => self.write_v11(buffer, extra_data)?,
87            _ => return Err(RLibError::EncodingFastBinUnsupportedVersion(String::from("Properties"), self.serialise_version)),
88        }
89
90        Ok(())
91    }
92}