aboutsummaryrefslogtreecommitdiff
path: root/src/classes/pptr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/pptr.rs')
-rw-r--r--src/classes/pptr.rs60
1 files changed, 35 insertions, 25 deletions
diff --git a/src/classes/pptr.rs b/src/classes/pptr.rs
index 366e17c..0e66b5f 100644
--- a/src/classes/pptr.rs
+++ b/src/classes/pptr.rs
@@ -15,13 +15,19 @@ pub struct PPtr<T = Value> {
#[serde(skip, default)]
pub(crate) _class: PhantomData<T>,
pub class: String,
+ pub source_file: usize,
pub file_id: i32,
pub path_id: i64,
}
impl<T> FromValue for PPtr<T> {
fn from_value(v: Value) -> Result<Self> {
- let Value::Object { class, fields } = v else {
+ let Value::Object {
+ class,
+ fields,
+ file,
+ } = v
+ else {
bail!("PPtr expected but not an object")
};
let inner = class
@@ -32,6 +38,7 @@ impl<T> FromValue for PPtr<T> {
Ok(PPtr {
class: inner.to_owned(),
_class: PhantomData,
+ source_file: file,
file_id: fields["m_FileID"]
.as_i32()
.ok_or(anyhow!("PPtr m_FileID is not i32"))?,
@@ -47,6 +54,7 @@ impl<T: FromValue> PPtr<T> {
PPtr {
_class: PhantomData,
class: self.class,
+ source_file: self.source_file,
file_id: self.file_id,
path_id: self.path_id,
}
@@ -59,30 +67,32 @@ impl<T: FromValue> PPtr<T> {
"loading PPtr<{}> file_id={} path_id={}",
self.class, self.file_id, self.path_id
);
- match self.file_id {
- 0 => {
- let ob = bundle
- .main
- .objects
- .iter()
- .find(|o| o.path_id == self.path_id)
- .ok_or(anyhow!("object with path id {} not found", self.path_id))?
- .to_owned();
- bundle.main.read_object(ob)?.parse()
- }
- 1 => {
- let file = bundle.shared_assets.as_mut().ok_or(anyhow!(
- "shared assets referenced but not included in bundle"
- ))?;
- let ob = file
- .objects
- .iter()
- .find(|o| o.path_id == self.path_id)
- .ok_or(anyhow!("object with path id {} not found", self.path_id))?
- .to_owned();
- file.read_object(ob)?.parse()
- }
- _ => unimplemented!(),
+ let main_file = match (self.source_file, self.file_id) {
+ (0, 0) => true,
+ (0, 1) => false,
+ (1, 0) => false,
+ _ => unreachable!(),
+ };
+ if main_file {
+ let ob = bundle
+ .main
+ .objects
+ .iter()
+ .find(|o| o.path_id == self.path_id)
+ .ok_or(anyhow!("object with path id {} not found", self.path_id))?
+ .to_owned();
+ bundle.main.read_object(ob)?.parse()
+ } else {
+ let file = bundle.shared_assets.as_mut().ok_or(anyhow!(
+ "shared assets referenced but not included in bundle"
+ ))?;
+ let ob = file
+ .objects
+ .iter()
+ .find(|o| o.path_id == self.path_id)
+ .ok_or(anyhow!("object with path id {} not found", self.path_id))?
+ .to_owned();
+ file.read_object(ob)?.parse()
}
}
}