Skip to content

Commit

Permalink
Implement GameplayTagContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
trumank committed Jan 14, 2024
1 parent 1eae4ae commit 68442f1
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ pub enum StructType {
LinearColor,
Color,
SoftObjectPath,
GameplayTagContainer,
Struct(Option<String>),
}
impl From<&str> for StructType {
Expand All @@ -494,6 +495,7 @@ impl From<&str> for StructType {
"LinearColor" => StructType::LinearColor,
"Color" => StructType::Color,
"SoftObjectPath" => StructType::SoftObjectPath,
"GameplayTagContainer" => StructType::GameplayTagContainer,
"Struct" => StructType::Struct(None),
_ => StructType::Struct(Some(t.to_owned())),
}
Expand All @@ -514,6 +516,7 @@ impl From<String> for StructType {
"LinearColor" => StructType::LinearColor,
"Color" => StructType::Color,
"SoftObjectPath" => StructType::SoftObjectPath,
"GameplayTagContainer" => StructType::GameplayTagContainer,
"Struct" => StructType::Struct(None),
_ => StructType::Struct(Some(t)),
}
Expand All @@ -539,6 +542,7 @@ impl StructType {
StructType::LinearColor => "LinearColor",
StructType::Color => "Color",
StructType::SoftObjectPath => "SoftObjectPath",
StructType::GameplayTagContainer => "GameplayTagContainer",
StructType::Struct(Some(t)) => t,
_ => unreachable!(),
},
Expand Down Expand Up @@ -897,6 +901,41 @@ impl IntPoint {
}
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct GameplayTag {
pub name: String,
}
impl GameplayTag {
fn read<R: Read + Seek>(reader: &mut Context<R>) -> TResult<Self> {
Ok(Self {
name: read_string(reader)?,
})
}
fn write<W: Write>(&self, writer: &mut Context<W>) -> TResult<()> {
write_string(writer, &self.name)?;
Ok(())
}
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct GameplayTagContainer {
pub gameplay_tags: Vec<GameplayTag>,
}
impl GameplayTagContainer {
fn read<R: Read + Seek>(reader: &mut Context<R>) -> TResult<Self> {
Ok(Self {
gameplay_tags: read_array(reader.read_u32::<LE>()?, reader, GameplayTag::read)?,
})
}
fn write<W: Write>(&self, writer: &mut Context<W>) -> TResult<()> {
writer.write_u32::<LE>(self.gameplay_tags.len() as u32)?;
for entry in &self.gameplay_tags {
entry.write(writer)?;
}
Ok(())
}
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct FFormatArgumentData {
name: String,
Expand Down Expand Up @@ -1275,6 +1314,7 @@ pub enum StructValue {
Color(Color),
Rotator(Rotator),
SoftObjectPath(String, String),
GameplayTagContainer(GameplayTagContainer),
/// User defined struct which is simply a list of properties
Struct(Properties),
}
Expand Down Expand Up @@ -1401,6 +1441,10 @@ impl StructValue {
StructType::SoftObjectPath => {
StructValue::SoftObjectPath(read_string(reader)?, read_string(reader)?)
}
StructType::GameplayTagContainer => {
StructValue::GameplayTagContainer(GameplayTagContainer::read(reader)?)
}

StructType::Struct(_) => StructValue::Struct(read_properties_until_none(reader)?),
})
}
Expand All @@ -1421,6 +1465,7 @@ impl StructValue {
write_string(writer, a)?;
write_string(writer, b)?;
}
StructValue::GameplayTagContainer(v) => v.write(writer)?,
StructValue::Struct(v) => write_properties_none_terminated(writer, v)?,
}
Ok(())
Expand Down

0 comments on commit 68442f1

Please sign in to comment.