Skip to content
This repository has been archived by the owner on Jul 22, 2023. It is now read-only.

Commit

Permalink
Fix Remodel droppiung unknown properties
Browse files Browse the repository at this point in the history
  • Loading branch information
LPGhatguy committed Sep 26, 2019
1 parent 3b1bc6a commit 8889f52
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* **Breaking:** `Instance.new` now only works for instances that actually exist.
* Added `Instance:Clone()` for copying instances all over the place, as is Roblox tradition. ([#12](https://github.com/rojo-rbx/remodel/issues/12))
* Added `DataModel:GetService()` for finding services and creating them if they don't exist, like Roblox does. ([#10](https://github.com/rojo-rbx/remodel/issues/10))
* Fixed Remodel dropping unknown properties when reading/writing XML models. This should make Remodel's behavior line up with Rojo.
* Improved error messages in preparation for [#7](https://github.com/rojo-rbx/remodel/issues/7) to be fixed upstream.

## 0.5.0 (2019-09-21)
Expand Down
43 changes: 33 additions & 10 deletions src/remodel_api/remodel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ use rlua::{Context, UserData, UserDataMethods};
use super::LuaInstance;
use crate::remodel_context::RemodelContext;

fn xml_encode_options() -> rbx_xml::EncodeOptions {
rbx_xml::EncodeOptions::new().property_behavior(rbx_xml::EncodePropertyBehavior::WriteUnknown)
}

fn xml_decode_options() -> rbx_xml::DecodeOptions {
rbx_xml::DecodeOptions::new().property_behavior(rbx_xml::DecodePropertyBehavior::ReadUnknown)
}

pub struct Remodel;

impl Remodel {
fn read_xml_place_file<'lua>(context: Context<'lua>, path: &Path) -> rlua::Result<LuaInstance> {
let file = BufReader::new(File::open(path).map_err(rlua::Error::external)?);
let source_tree = rbx_xml::from_reader_default(file).map_err(rlua::Error::external)?;
let source_tree =
rbx_xml::from_reader(file, xml_decode_options()).map_err(rlua::Error::external)?;

Remodel::import_place_tree(context, source_tree)
}
Expand All @@ -29,7 +38,8 @@ impl Remodel {
path: &Path,
) -> rlua::Result<Vec<LuaInstance>> {
let file = BufReader::new(File::open(path).map_err(rlua::Error::external)?);
let source_tree = rbx_xml::from_reader_default(file).map_err(rlua::Error::external)?;
let source_tree =
rbx_xml::from_reader(file, xml_decode_options()).map_err(rlua::Error::external)?;

Remodel::import_model_tree(context, source_tree)
}
Expand Down Expand Up @@ -113,8 +123,13 @@ impl Remodel {
));
}

rbx_xml::to_writer_default(file, &tree, instance.get_children_ids())
.map_err(rlua::Error::external)?;
rbx_xml::to_writer(
file,
&tree,
instance.get_children_ids(),
xml_encode_options(),
)
.map_err(rlua::Error::external)?;

Ok(())
}
Expand All @@ -133,7 +148,8 @@ impl Remodel {
));
}

rbx_xml::to_writer_default(file, &tree, &[lua_instance.id]).map_err(rlua::Error::external)
rbx_xml::to_writer(file, &tree, &[lua_instance.id], xml_encode_options())
.map_err(rlua::Error::external)
}

fn write_binary_model_file(lua_instance: LuaInstance, path: &Path) -> rlua::Result<()> {
Expand Down Expand Up @@ -170,7 +186,8 @@ impl Remodel {

let response = request.send().map_err(rlua::Error::external)?;

let source_tree = rbx_xml::from_reader_default(response).map_err(rlua::Error::external)?;
let source_tree =
rbx_xml::from_reader(response, xml_decode_options()).map_err(rlua::Error::external)?;

Remodel::import_model_tree(context, source_tree)
}
Expand All @@ -191,7 +208,8 @@ impl Remodel {

let response = request.send().map_err(rlua::Error::external)?;

let source_tree = rbx_xml::from_reader_default(response).map_err(rlua::Error::external)?;
let source_tree =
rbx_xml::from_reader(response, xml_decode_options()).map_err(rlua::Error::external)?;

Remodel::import_place_tree(context, source_tree)
}
Expand All @@ -213,7 +231,7 @@ impl Remodel {
}

let mut buffer = Vec::new();
rbx_xml::to_writer_default(&mut buffer, &tree, &[lua_instance.id])
rbx_xml::to_writer(&mut buffer, &tree, &[lua_instance.id], xml_encode_options())
.map_err(rlua::Error::external)?;

Remodel::upload_asset(context, buffer, asset_id)
Expand All @@ -236,8 +254,13 @@ impl Remodel {
}

let mut buffer = Vec::new();
rbx_xml::to_writer_default(&mut buffer, &tree, instance.get_children_ids())
.map_err(rlua::Error::external)?;
rbx_xml::to_writer(
&mut buffer,
&tree,
instance.get_children_ids(),
xml_encode_options(),
)
.map_err(rlua::Error::external)?;

Remodel::upload_asset(context, buffer, asset_id)
}
Expand Down

0 comments on commit 8889f52

Please sign in to comment.