Make most metadata structs immutable again

This commit is contained in:
Oliver Hamlet
2025-04-24 20:03:23 +01:00
parent 2ef0cc8083
commit a08d53ea52
12 changed files with 223 additions and 502 deletions
+14 -88
View File
@@ -24,11 +24,11 @@ impl Group {
let mut group = libloot::metadata::Group::new(name);
if let Some(description) = description {
group.set_description(description);
group = group.with_description(description);
}
if let Some(after_groups) = after_groups {
group.set_after_groups(after_groups);
group = group.with_after_groups(after_groups);
}
Self(group)
@@ -44,20 +44,10 @@ impl Group {
self.0.description()
}
#[napi(setter)]
pub fn set_description(&mut self, description: String) {
self.0.set_description(description);
}
#[napi(getter)]
pub fn after_groups(&self) -> Vec<String> {
self.0.after_groups().to_vec()
}
#[napi(setter)]
pub fn set_after_groups(&mut self, after_groups: Vec<String>) {
self.0.set_after_groups(after_groups);
}
}
impl From<libloot::metadata::Group> for Group {
@@ -89,7 +79,7 @@ impl MessageContent {
let mut content = libloot::metadata::MessageContent::new(text);
if let Some(language) = language {
content.set_language(language);
content = content.with_language(language);
}
Self(content)
@@ -104,11 +94,6 @@ impl MessageContent {
pub fn language(&self) -> &str {
self.0.language()
}
#[napi(setter)]
pub fn set_language(&mut self, language: String) {
self.0.set_language(language);
}
}
impl From<libloot::metadata::MessageContent> for MessageContent {
@@ -184,7 +169,7 @@ impl Message {
};
if let Some(condition) = condition {
message.set_condition(condition);
message = message.with_condition(condition);
}
Ok(Self(message))
@@ -204,11 +189,6 @@ impl Message {
pub fn condition(&self) -> Option<&str> {
self.0.condition()
}
#[napi(setter)]
pub fn set_condition(&mut self, condition: String) {
self.0.set_condition(condition);
}
}
impl From<libloot::metadata::Message> for Message {
@@ -241,20 +221,20 @@ impl File {
let mut file = libloot::metadata::File::new(name);
if let Some(display_name) = display_name {
file.set_display_name(display_name);
file = file.with_display_name(display_name);
}
if let Some(detail) = detail {
let detail = detail.into_iter().cloned().map(Into::into).collect();
file.set_detail(detail)?;
file = file.with_detail(detail)?;
}
if let Some(condition) = condition {
file.set_condition(condition);
file = file.with_condition(condition);
}
if let Some(constraint) = constraint {
file.set_constraint(constraint);
file = file.with_constraint(constraint);
}
Ok(Self(file))
@@ -270,42 +250,20 @@ impl File {
self.0.display_name()
}
#[napi(setter)]
pub fn set_display_name(&mut self, description: String) {
self.0.set_display_name(description);
}
#[napi(getter)]
pub fn detail(&self) -> Vec<MessageContent> {
self.0.detail().iter().cloned().map(Into::into).collect()
}
#[napi(setter)]
pub fn set_detail(&mut self, detail: Vec<&MessageContent>) -> Result<(), VerboseError> {
let detail = detail.into_iter().cloned().map(Into::into).collect();
self.0.set_detail(detail)?;
Ok(())
}
#[napi(getter)]
pub fn condition(&self) -> Option<&str> {
self.0.condition()
}
#[napi(setter)]
pub fn set_condition(&mut self, condition: String) {
self.0.set_condition(condition);
}
#[napi(getter)]
pub fn constraint(&self) -> Option<&str> {
self.0.constraint()
}
#[napi(setter)]
pub fn set_constraint(&mut self, constraint: String) {
self.0.set_constraint(constraint);
}
}
impl From<libloot::metadata::File> for File {
@@ -363,20 +321,20 @@ impl PluginCleaningData {
let mut data = libloot::metadata::PluginCleaningData::new(crc, cleaning_utility);
if let Some(count) = itm_count {
data.set_itm_count(count);
data = data.with_itm_count(count);
}
if let Some(count) = deleted_reference_count {
data.set_deleted_reference_count(count);
data = data.with_deleted_reference_count(count);
}
if let Some(count) = deleted_navmesh_count {
data.set_deleted_navmesh_count(count);
data = data.with_deleted_navmesh_count(count);
}
if let Some(detail) = detail {
let detail = detail.into_iter().cloned().map(Into::into).collect();
data.set_detail(detail)?;
data = data.with_detail(detail)?;
}
Ok(Self(data))
@@ -392,31 +350,16 @@ impl PluginCleaningData {
self.0.itm_count()
}
#[napi(setter)]
pub fn set_itm_count(&mut self, count: u32) {
self.0.set_itm_count(count);
}
#[napi(getter)]
pub fn deleted_reference_count(&self) -> u32 {
self.0.deleted_reference_count()
}
#[napi(setter)]
pub fn set_deleted_reference_count(&mut self, count: u32) {
self.0.set_deleted_reference_count(count);
}
#[napi(getter)]
pub fn deleted_navmesh_count(&self) -> u32 {
self.0.deleted_navmesh_count()
}
#[napi(setter)]
pub fn set_deleted_navmesh_count(&mut self, count: u32) {
self.0.set_deleted_navmesh_count(count);
}
#[napi(getter)]
pub fn cleaning_utility(&self) -> &str {
self.0.cleaning_utility()
@@ -426,13 +369,6 @@ impl PluginCleaningData {
pub fn detail(&self) -> Vec<MessageContent> {
self.0.detail().iter().cloned().map(Into::into).collect()
}
#[napi(setter)]
pub fn set_detail(&mut self, detail: Vec<&MessageContent>) -> Result<(), VerboseError> {
let detail = detail.into_iter().cloned().map(Into::into).collect();
self.0.set_detail(detail)?;
Ok(())
}
}
impl From<libloot::metadata::PluginCleaningData> for PluginCleaningData {
@@ -475,7 +411,7 @@ impl Tag {
let mut tag = libloot::metadata::Tag::new(name, suggestion.into());
if let Some(condition) = condition {
tag.set_condition(condition);
tag = tag.with_condition(condition);
}
Self(tag)
@@ -495,11 +431,6 @@ impl Tag {
pub fn condition(&self) -> Option<&str> {
self.0.condition()
}
#[napi(setter)]
pub fn set_condition(&mut self, condition: String) {
self.0.set_condition(condition);
}
}
impl From<libloot::metadata::Tag> for Tag {
@@ -526,7 +457,7 @@ impl Location {
let mut location = libloot::metadata::Location::new(url);
if let Some(name) = name {
location.set_name(name);
location = location.with_name(name);
}
Self(location)
@@ -541,11 +472,6 @@ impl Location {
pub fn name(&self) -> Option<&str> {
self.0.name()
}
#[napi(setter)]
pub fn set_name(&mut self, name: String) {
self.0.set_name(name);
}
}
impl From<libloot::metadata::Location> for Location {