Skip to content

Commit

Permalink
Remove database shim now that UniqueId deserializes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekkonot committed Aug 29, 2024
1 parent 64f567a commit ba92d6d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 69 deletions.
50 changes: 8 additions & 42 deletions src/cli/syncback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use clap::Parser;
use fs_err::File;
use memofs::Vfs;
use rbx_dom_weak::{InstanceBuilder, WeakDom};
use rbx_reflection::ReflectionDatabase;
use termcolor::{BufferWriter, Color, ColorChoice, ColorSpec, WriteColor};

use crate::{
Expand Down Expand Up @@ -155,26 +154,18 @@ impl SyncbackCommand {
fn read_dom(path: &Path, file_kind: FileKind) -> anyhow::Result<WeakDom> {
let content = BufReader::new(File::open(path)?);
match file_kind {
FileKind::Rbxl => {
// HACK: A custom reflection database is used to deserialize UniqueId
let db = binary_db().expect("A custom ReflectionDatabase to deserialize UniqueId");
let binary_decoder = rbx_binary::Deserializer::new().reflection_database(&db);
binary_decoder.deserialize(content).with_context(|| {
format!(
"Could not deserialize binary place file at {}",
path.display()
)
})
}
FileKind::Rbxl => rbx_binary::from_reader(content).with_context(|| {
format!(
"Could not deserialize binary place file at {}",
path.display()
)
}),
FileKind::Rbxlx => rbx_xml::from_reader(content, xml_decode_config())
.with_context(|| format!("Could not deserialize XML place file at {}", path.display())),
FileKind::Rbxm => {
// HACK: A custom reflection database is used to deserialize UniqueId
let db = binary_db().expect("A custom ReflectionDatabase to deserialize UniqueId");
let binary_decoder = rbx_binary::Deserializer::new().reflection_database(&db);
let temp_tree = binary_decoder.deserialize(content).with_context(|| {
let temp_tree = rbx_binary::from_reader(content).with_context(|| {
format!(
"Could not deserialize binary model file at {}",
"Could not deserialize binary place file at {}",
path.display()
)
})?;
Expand Down Expand Up @@ -220,31 +211,6 @@ fn xml_decode_config() -> rbx_xml::DecodeOptions<'static> {
rbx_xml::DecodeOptions::new().property_behavior(rbx_xml::DecodePropertyBehavior::ReadUnknown)
}

fn binary_db() -> Option<ReflectionDatabase<'static>> {
// HACK: UniqueId does not deserialize right now, so we force it to
// Don't forget to change this in the syncback test when changing it here.
use rbx_reflection::{PropertyKind, PropertySerialization};
use std::borrow::Cow;

let mut unique_id = rbx_reflection_database::get()
.classes
.get("Instance")?
.properties
.get("UniqueId")?
.clone();
unique_id.kind = PropertyKind::Canonical {
serialization: PropertySerialization::Serializes,
};

let mut db = rbx_reflection_database::get().clone();
let instance = db.classes.get_mut("Instance")?;
instance
.properties
.insert(Cow::Borrowed("UniqueId"), unique_id);

Some(db)
}

/// The different kinds of input that Rojo can syncback.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum FileKind {
Expand Down
28 changes: 1 addition & 27 deletions tests/rojo_test/syncback_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ pub fn basic_syncback_test(name: &str) -> anyhow::Result<()> {
};
im_vfs.set_watch_enabled(false);

let database = database_shim().unwrap();
let deserializer = rbx_binary::Deserializer::new().reflection_database(&database);
let input_dom = deserializer.deserialize(std_vfs.read(input_path)?.as_slice())?;
let input_dom = rbx_binary::from_reader(std_vfs.read(input_path)?.as_slice())?;

let (mut output_dom, project) =
rojo_tree_from_path(&std_vfs, &output_path.join("default.project.json"))?;
Expand Down Expand Up @@ -142,30 +140,6 @@ fn to_vfs_snapshot(vfs: &Vfs, path: &Path) -> anyhow::Result<VfsSnapshot> {
}
}

fn database_shim() -> Option<ReflectionDatabase<'static>> {
// HACK: UniqueId does not deserialize right now, so we force it to
// Don't forget to change this in the syncback CLI when changing it here.
use rbx_reflection::{PropertyKind, PropertySerialization};

let mut unique_id = rbx_reflection_database::get()
.classes
.get("Instance")?
.properties
.get("UniqueId")?
.clone();
unique_id.kind = PropertyKind::Canonical {
serialization: PropertySerialization::Serializes,
};

let mut db = rbx_reflection_database::get().clone();
let instance = db.classes.get_mut("Instance")?;
instance
.properties
.insert(Cow::Borrowed("UniqueId"), unique_id);

Some(db)
}

/// Normalizes the line endings of a vector if it's user-readable.
/// If it isn't, the vector is returned unmodified.
fn normalize_line_endings(input: &Vec<u8>) -> Cow<Vec<u8>> {
Expand Down

0 comments on commit ba92d6d

Please sign in to comment.