Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter default properties in json middlewares instead of filter fn #6

Open
wants to merge 20 commits into
base: syncback-merge
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f635cdc
Filter default properties in json middlewares instead of filter fn
kennethloeffler Sep 11, 2024
6b9e515
Update ignore_trees_removing test, accept snaphot
kennethloeffler Sep 17, 2024
579f55c
Add remove_default_properties test
kennethloeffler Sep 18, 2024
b54eee1
Add comment explaining property map removals
kennethloeffler Sep 20, 2024
6eb04bf
Rename function, refactor so it produces attribute and prop maps
kennethloeffler Sep 21, 2024
b57f473
Remove `true` branch for default props, since it is now unnecessary
kennethloeffler Sep 21, 2024
e335caa
Add doc comment for populate_unresolved_properties
kennethloeffler Sep 21, 2024
ea4af65
Remove outdated comment
kennethloeffler Oct 11, 2024
09c4e2c
Fix project_node_should_reserialize
kennethloeffler Oct 11, 2024
7cdda8a
Do class descriptor lookup only once
kennethloeffler Oct 12, 2024
ca488ac
Make old property pass more robust against unknowns, add comments
kennethloeffler Oct 15, 2024
0d8a36d
Use iter instead of into_iter for json model prop buffer
kennethloeffler Oct 16, 2024
583666a
Fix some typos
kennethloeffler Oct 16, 2024
cae0c9b
Move should_reserialize fn to snapshot_middleware module
kennethloeffler Nov 13, 2024
bcfdc0c
Test whether json model should reserialize
kennethloeffler Nov 13, 2024
a854e8a
Remove println
kennethloeffler Nov 13, 2024
59d780c
Remove log::debugs
kennethloeffler Nov 13, 2024
3dd6856
Remove == true
kennethloeffler Nov 14, 2024
a4f10c6
Test if meta files should reserialize
kennethloeffler Nov 14, 2024
b2fd639
Run tests
kennethloeffler Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ added_files:
- src/dir/init_server_script/init.server.luau
- src/dir/module_script.luau
- src/dir/server_script.server.luau
- src/dir_with_meta/init.meta.json
- src/model_json.model.json
- src/project_json.project.json
- src/rbxm.rbxm
- src/rbxmx.rbxmx
- src/text.txt
added_dirs:
- src
- src/csv_init
- src/dir
- src/dir/init_client_script
- src/dir/init_module_script
- src/dir/init_server_script
- src/dir_with_meta
removed_files: []
removed_dirs: []
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
added_files:
- OnlyOneCopy/child_of_one.luau
- ReplicatedStorage/child_replicated_storage.luau
added_dirs: []
added_dirs:
- OnlyOneCopy
- ReplicatedStorage
removed_files: []
removed_dirs: []
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: tests/rojo_test/syncback_util.rs
assertion_line: 48
expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
---
added_files: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
added_files:
- src/IncludeMe/.gitkeep
added_dirs:
- src
- src/IncludeMe
removed_files: []
removed_dirs: []
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
source: tests/rojo_test/syncback_util.rs
assertion_line: 45
expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
---
added_files: []
added_dirs: []
added_dirs:
- src
removed_files: []
removed_dirs: []
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
added_files:
- src/modules/ClientModule.luau
- src/modules/ServerModule.luau
added_dirs: []
added_dirs:
- src/modules
removed_files: []
removed_dirs: []
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ added_files:
- src/text.txt
added_dirs:
- src/csv_init
- src/dir
- src/dir_with_meta
- src/init_client_script
- src/init_module_script
- src/init_server_script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ added_files:
- ReplicatedStorage/ChildWithDuplicates.rbxm
- ReplicatedStorage/ChildWithoutDuplicates/Child/.gitkeep
added_dirs:
- ReplicatedStorage
- ReplicatedStorage/ChildWithoutDuplicates
- ReplicatedStorage/ChildWithoutDuplicates/Child
removed_files: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
added_files:
- src/pointer.model.json
- src/target.model.json
added_dirs: []
added_dirs:
- src
removed_files: []
removed_dirs: []
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
added_files:
- src/pointer.model.json
- src/target.model.json
added_dirs: []
added_dirs:
- src
removed_files: []
removed_dirs: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
source: tests/rojo_test/syncback_util.rs
expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
---
added_files:
- AdjacentMetadataScript/AdjacentMetadataScript.meta.json
- AdjacentMetadataScript/AdjacentMetadataScript.server.lua
- DirectoryMetadataPart/Part/init.meta.json
- Part.model.json
- default.project.json
added_dirs:
- AdjacentMetadataScript
- DirectoryMetadataPart
- DirectoryMetadataPart/Part
removed_files: []
removed_dirs: []
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@
"$className": "DataModel",
"Workspace": {
"$properties": {
"CSGAsyncDynamicCollision": {
"Enum": 0
},
"DecreaseMinimumPartDensityMode": {
"Enum": 0
},
"MoverConstraintRootBehavior": {
"Enum": 0
},
"RenderingCacheOptimizations": {
"Enum": 0
},
kennethloeffler marked this conversation as resolved.
Show resolved Hide resolved
"SignalBehavior": "Deferred",
"StreamOutBehavior": "Opportunistic",
"StreamingEnabled": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"properties": {
"Disabled": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"properties": {
"Anchored": true
},
"className": "Part"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"className": "Part",
"properties": {
"Size": [
1.0,
2.0,
3.0
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "remove_default_props",
"tree": {
"$className": "DataModel",
"ReplicatedStorage": {
"AdjacentMetadataScript": {
"$path": "AdjacentMetadataScript"
},
"DirectoryMetadataPart": {
"$path": "DirectoryMetadataPart"
},
"JsonModelPart": {
"$path": "Part.model.json"
},
"ProjectFilePart": {
"$className": "Part",
"$properties": {
"Transparency": 1.0
}
}
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"properties": {
"Disabled": true,
"RunContext": "Client",
"Archivable": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"properties": {
"CanCollide": false,
"Massless": false,
"Anchored": true
},
"className": "Part"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"className": "Part",
"properties": {
"Size": [
1.0,
2.0,
3.0
],
"Anchored": true,
"Massless": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "remove_default_props",
"tree": {
"$className": "DataModel",
"ReplicatedStorage": {
"AdjacentMetadataScript": {
"$path": "AdjacentMetadataScript"
},
"DirectoryMetadataPart": {
"$path": "DirectoryMetadataPart"
},
"JsonModelPart": {
"$path": "Part.model.json"
},
"ProjectFilePart": {
"$className": "Part",
"$properties": {
"Size": [
1.0,
2.0,
3.0
],
"Transparency": 1.0,
"CanCollide": false
}
}
}
}
}
38 changes: 8 additions & 30 deletions src/snapshot_middleware/json_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use crate::{
RojoRef,
};

use super::populate_unresolved_properties;

pub fn snapshot_json_model(
context: &InstanceContext,
vfs: &Vfs,
Expand Down Expand Up @@ -94,36 +96,12 @@ fn json_model_from_pair<'sync>(

filter_properties_preallocated(snapshot.project(), new_inst, prop_buffer);

let mut properties = BTreeMap::new();
let mut attributes = BTreeMap::new();
for (name, value) in prop_buffer.drain(..) {
match value {
Variant::Attributes(attrs) => {
for (attr_name, attr_value) in attrs.iter() {
// We (probably) don't want to preserve internal attributes,
// only user defined ones.
if attr_name.starts_with("RBX") {
continue;
}
attributes.insert(
attr_name.clone(),
UnresolvedValue::from_variant_unambiguous(attr_value.clone()),
);
}
}
Variant::SharedString(_) => {
log::warn!(
"Rojo cannot serialize the property {}.{name} in model.json files.\n\
If this is not acceptable, resave the Instance at '{}' manually as an RBXM or RBXMX.", new_inst.class, snapshot.get_new_inst_path(new))
}
_ => {
properties.insert(
name.to_owned(),
UnresolvedValue::from_variant(value.clone(), &new_inst.class, name),
);
}
}
}
let (properties, attributes) = {
let prop_buffer: &_ = prop_buffer;
populate_unresolved_properties(snapshot, new_inst, prop_buffer.into_iter().copied())
};

prop_buffer.clear();

let mut children = Vec::with_capacity(new_inst.children().len());

Expand Down
Loading