Skip to content

Commit

Permalink
Merge branch 'syncback-merge' into syncback-internal-release-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekkonot committed Dec 5, 2024
2 parents 579baf7 + c788bbf commit fda1c9d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 58 deletions.
111 changes: 60 additions & 51 deletions src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,62 +41,71 @@ impl UnresolvedValue {
/// Creates an `UnresolvedValue` from a variant, using a class and property
/// name to potentially allow for ambiguous Enum variants.
pub fn from_variant(variant: Variant, class_name: &str, prop_name: &str) -> Self {
Self::Ambiguous(match variant {
Variant::Enum(rbx_enum) => {
if let Some(property) = find_descriptor(class_name, prop_name) {
if let DataType::Enum(enum_name) = &property.data_type {
let database = rbx_reflection_database::get();
if let Some(enum_descriptor) = database.enums.get(enum_name) {
for (variant_name, id) in &enum_descriptor.items {
if *id == rbx_enum.to_u32() {
return Self::Ambiguous(AmbiguousValue::String(
variant_name.to_string(),
));
let descriptor = find_descriptor(class_name, prop_name);
if descriptor.is_some() {
// We can only use an ambiguous syntax if the property is known
// to the reflection database.
Self::Ambiguous(match variant {
Variant::Enum(rbx_enum) => {
if let Some(property) = descriptor {
if let DataType::Enum(enum_name) = &property.data_type {
let database = rbx_reflection_database::get();
if let Some(enum_descriptor) = database.enums.get(enum_name) {
for (variant_name, id) in &enum_descriptor.items {
if *id == rbx_enum.to_u32() {
return Self::Ambiguous(AmbiguousValue::String(
variant_name.to_string(),
));
}
}
}
}
}
return Self::FullyQualified(variant);
}
return Self::FullyQualified(variant);
}
Variant::Bool(bool) => AmbiguousValue::Bool(bool),
Variant::Float32(n) => AmbiguousValue::Number(n as f64),
Variant::Float64(n) => AmbiguousValue::Number(n),
Variant::Int32(n) => AmbiguousValue::Number(n as f64),
Variant::Int64(n) => AmbiguousValue::Number(n as f64),
Variant::String(str) => AmbiguousValue::String(str),
Variant::Tags(tags) => {
AmbiguousValue::StringArray(tags.iter().map(|s| s.to_string()).collect())
}
Variant::Content(content) => AmbiguousValue::String(content.into_string()),
Variant::Vector2(vector) => AmbiguousValue::Array2([vector.x as f64, vector.y as f64]),
Variant::Vector3(vector) => {
AmbiguousValue::Array3([vector.x as f64, vector.y as f64, vector.z as f64])
}
Variant::Color3(color) => {
AmbiguousValue::Array3([color.r as f64, color.g as f64, color.b as f64])
}
Variant::CFrame(cf) => AmbiguousValue::Array12([
cf.position.x as f64,
cf.position.y as f64,
cf.position.z as f64,
cf.orientation.x.x as f64,
cf.orientation.x.y as f64,
cf.orientation.x.z as f64,
cf.orientation.y.x as f64,
cf.orientation.y.y as f64,
cf.orientation.y.z as f64,
cf.orientation.z.x as f64,
cf.orientation.z.y as f64,
cf.orientation.z.z as f64,
]),
Variant::Attributes(attr) => AmbiguousValue::Attributes(attr),
Variant::Font(font) => AmbiguousValue::Font(font),
Variant::MaterialColors(colors) => AmbiguousValue::MaterialColors(colors),
_ => {
return Self::FullyQualified(variant);
}
})
Variant::Bool(bool) => AmbiguousValue::Bool(bool),
Variant::Float32(n) => AmbiguousValue::Number(n as f64),
Variant::Float64(n) => AmbiguousValue::Number(n),
Variant::Int32(n) => AmbiguousValue::Number(n as f64),
Variant::Int64(n) => AmbiguousValue::Number(n as f64),
Variant::String(str) => AmbiguousValue::String(str),
Variant::Tags(tags) => {
AmbiguousValue::StringArray(tags.iter().map(|s| s.to_string()).collect())
}
Variant::Content(content) => AmbiguousValue::String(content.into_string()),
Variant::Vector2(vector) => {
AmbiguousValue::Array2([vector.x as f64, vector.y as f64])
}
Variant::Vector3(vector) => {
AmbiguousValue::Array3([vector.x as f64, vector.y as f64, vector.z as f64])
}
Variant::Color3(color) => {
AmbiguousValue::Array3([color.r as f64, color.g as f64, color.b as f64])
}
Variant::CFrame(cf) => AmbiguousValue::Array12([
cf.position.x as f64,
cf.position.y as f64,
cf.position.z as f64,
cf.orientation.x.x as f64,
cf.orientation.x.y as f64,
cf.orientation.x.z as f64,
cf.orientation.y.x as f64,
cf.orientation.y.y as f64,
cf.orientation.y.z as f64,
cf.orientation.z.x as f64,
cf.orientation.z.y as f64,
cf.orientation.z.z as f64,
]),
Variant::Attributes(attr) => AmbiguousValue::Attributes(attr),
Variant::Font(font) => AmbiguousValue::Font(font),
Variant::MaterialColors(colors) => AmbiguousValue::MaterialColors(colors),
_ => {
return Self::FullyQualified(variant);
}
})
} else {
Self::FullyQualified(variant)
}
}

/// Creates an `UnresolvedValue` from a variant, only returning ambiguous
Expand Down
15 changes: 8 additions & 7 deletions src/syncback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,6 @@ pub fn syncback_loop(
let syncback = match middleware.syncback(&snapshot) {
Ok(syncback) => syncback,
Err(err) if middleware == Middleware::Dir => {
if snapshot.old_inst().is_some() {
// We need to remove the old FS representation if we're
// reserializing it as an rbxm.
fs_snapshot.remove_dir(&snapshot.path);
}
let new_middleware = match env::var(DEBUG_MODEL_FORMAT_VAR) {
Ok(value) if value == "1" => Middleware::Rbxmx,
Ok(value) if value == "2" => Middleware::JsonModel,
Expand All @@ -225,9 +220,15 @@ pub fn syncback_loop(
"Could not syncback {inst_path} as a Directory because: {err}.\n\
It will instead be synced back as a {new_middleware:?}."
);
new_middleware
let new_syncback_result = new_middleware
.syncback(&new_snapshot)
.with_context(|| format!("Failed to syncback {inst_path}"))?
.with_context(|| format!("Failed to syncback {inst_path}"));
if new_syncback_result.is_ok() && snapshot.old_inst().is_some() {
// We need to remove the old FS representation if we're
// reserializing it as an rbxm.
fs_snapshot.remove_dir(&snapshot.path);
}
new_syncback_result?
}
Err(err) => anyhow::bail!("Failed to syncback {inst_path} because {err}"),
};
Expand Down

0 comments on commit fda1c9d

Please sign in to comment.