Fix roblox builtin writing mysterious root instances

This commit is contained in:
Filip Tibell 2023-03-23 09:42:24 +01:00
parent bd38bf536c
commit 124c0d06b5
No known key found for this signature in database
3 changed files with 32 additions and 3 deletions

View file

@ -148,13 +148,18 @@ 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)
rbx_xml::to_writer(
&mut bytes,
&self.dom,
self.dom.root().children(),
xml_options,
)
.map_err(|err| DocumentError::WriteError(err.to_string()))
}
}?;

View file

@ -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")

View file

@ -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")