aboutsummaryrefslogtreecommitdiff
path: root/src/object.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-03-11 15:52:03 +0100
committermetamuffin <metamuffin@disroot.org>2025-03-11 15:52:03 +0100
commit7250587f46ca51ad662a0895a51742669b9cbb8f (patch)
tree8744d452a085a3a9b593dac0a77e987eb70fc91f /src/object.rs
parent30bf5e07e52142a154a5660574213e59e0363ada (diff)
downloadunity-tools-7250587f46ca51ad662a0895a51742669b9cbb8f.tar
unity-tools-7250587f46ca51ad662a0895a51742669b9cbb8f.tar.bz2
unity-tools-7250587f46ca51ad662a0895a51742669b9cbb8f.tar.zst
more inspection tools
Diffstat (limited to 'src/object.rs')
-rw-r--r--src/object.rs31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/object.rs b/src/object.rs
index be76c18..061f58e 100644
--- a/src/object.rs
+++ b/src/object.rs
@@ -2,10 +2,11 @@ use crate::helper::{AlignExt, Endianness, ReadExt};
use crate::serialized_file::TypeTreeNode;
use anyhow::{Result, bail};
use log::trace;
+use serde::Serialize;
use std::io::Seek;
use std::{collections::BTreeMap, io::Read};
-#[derive(Debug)]
+#[derive(Debug, Clone, Serialize)]
pub enum Value {
Bool(bool),
U8(u8),
@@ -121,6 +122,34 @@ pub fn read_value(
}
impl Value {
+ pub fn as_class(self, name: &str) -> Option<BTreeMap<String, Value>> {
+ if let Value::Object { class, fields } = self {
+ if class == name { Some(fields) } else { None }
+ } else {
+ None
+ }
+ }
+ pub fn as_string(self) -> Option<String> {
+ if let Value::String(s) = self {
+ Some(s)
+ } else {
+ None
+ }
+ }
+ pub fn as_i64(&self) -> Option<i64> {
+ if let Value::I64(s) = self {
+ Some(*s)
+ } else {
+ None
+ }
+ }
+ pub fn as_i32(&self) -> Option<i32> {
+ if let Value::I32(s) = self {
+ Some(*s)
+ } else {
+ None
+ }
+ }
pub fn to_json(self) -> serde_json::Value {
match self {
Value::Bool(x) => serde_json::Value::Bool(x),