diff --git a/packages/lib-roblox/src/document/mod.rs b/packages/lib-roblox/src/document/mod.rs index 945f871..ca89453 100644 --- a/packages/lib-roblox/src/document/mod.rs +++ b/packages/lib-roblox/src/document/mod.rs @@ -148,14 +148,19 @@ impl Document { let mut bytes = Vec::new(); match format { DocumentFormat::Binary => { - rbx_binary::to_writer(&mut bytes, &self.dom, &[self.dom.root_ref()]) + rbx_binary::to_writer(&mut bytes, &self.dom, self.dom.root().children()) .map_err(|err| DocumentError::WriteError(err.to_string())) } DocumentFormat::Xml => { let xml_options = XmlEncodeOptions::new() .property_behavior(XmlEncodePropertyBehavior::WriteUnknown); - rbx_xml::to_writer(&mut bytes, &self.dom, &[self.dom.root_ref()], xml_options) - .map_err(|err| DocumentError::WriteError(err.to_string())) + rbx_xml::to_writer( + &mut bytes, + &self.dom, + self.dom.root().children(), + xml_options, + ) + .map_err(|err| DocumentError::WriteError(err.to_string())) } }?; Ok(bytes) diff --git a/tests/roblox/files/writeModelFile.luau b/tests/roblox/files/writeModelFile.luau index 2e35bfe..79bce09 100644 --- a/tests/roblox/files/writeModelFile.luau +++ b/tests/roblox/files/writeModelFile.luau @@ -8,3 +8,18 @@ local instances = { roblox.writeModelFile("bin/temp-model.rbxm", instances) roblox.writeModelFile("bin/temp-model.rbxmx", instances) + +local savedBinary = roblox.readModelFile("bin/temp-model.rbxm") +local savedXml = roblox.readModelFile("bin/temp-model.rbxmx") + +assert(savedBinary[1].Name ~= "ROOT") +assert(savedXml[1].Name ~= "ROOT") + +assert(savedBinary[1].Name ~= "DataModel") +assert(savedXml[1].Name ~= "DataModel") + +assert(savedBinary[1].ClassName == "Model") +assert(savedBinary[2].ClassName == "Part") + +assert(savedXml[1].ClassName == "Model") +assert(savedXml[2].ClassName == "Part") diff --git a/tests/roblox/files/writePlaceFile.luau b/tests/roblox/files/writePlaceFile.luau index 6e3d207..7ff9a38 100644 --- a/tests/roblox/files/writePlaceFile.luau +++ b/tests/roblox/files/writePlaceFile.luau @@ -13,3 +13,12 @@ model.Parent = workspace roblox.writePlaceFile("bin/temp-place.rbxl", game) roblox.writePlaceFile("bin/temp-place.rbxlx", game) + +local savedBinary = roblox.readPlaceFile("bin/temp-place.rbxl") +local savedXml = roblox.readPlaceFile("bin/temp-place.rbxlx") + +assert(savedBinary.Name ~= "ROOT") +assert(savedXml.Name ~= "ROOT") + +assert(savedBinary.ClassName == "DataModel") +assert(savedXml.ClassName == "DataModel")