-
Notifications
You must be signed in to change notification settings - Fork 177
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
init.meta.json support #183
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
06300af
A minimum viable product for init.meta.json
Kampfkarren 6e54639
Properties support
Kampfkarren e1812d0
Add ignoreUnknownChildren support
Kampfkarren e891ffd
Apply requested changes
Kampfkarren 1e7de8d
Use reflection guiding
Kampfkarren 62aa63d
Add a script to the test
Kampfkarren 80bc9aa
Change to ignoreUnknownInstances
Kampfkarren 55ba588
Apply requested changes
Kampfkarren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ use crate::{ | |
const INIT_MODULE_NAME: &str = "init.lua"; | ||
const INIT_SERVER_NAME: &str = "init.server.lua"; | ||
const INIT_CLIENT_NAME: &str = "init.client.lua"; | ||
const INIT_META_NAME: &str = "init.meta.json"; | ||
|
||
pub struct SnapshotContext { | ||
pub plugin_context: Option<SnapshotPluginContext>, | ||
|
@@ -105,6 +106,12 @@ pub enum SnapshotError { | |
path: PathBuf, | ||
}, | ||
|
||
InitMetaError { | ||
#[fail(cause)] | ||
inner: serde_json::Error, | ||
path: PathBuf, | ||
}, | ||
|
||
XmlModelDecodeError { | ||
#[fail(cause)] | ||
inner: rbx_xml::DecodeError, | ||
|
@@ -152,6 +159,9 @@ impl fmt::Display for SnapshotError { | |
SnapshotError::JsonModelDecodeError { inner, path } => { | ||
write!(output, "Malformed .model.json model: {} in path {}", inner, path.display()) | ||
}, | ||
SnapshotError::InitMetaError { inner, path } => { | ||
write!(output, "Malformed init.meta.json: {} in path {}", inner, path.display()) | ||
}, | ||
SnapshotError::XmlModelDecodeError { inner, path } => { | ||
write!(output, "Malformed rbxmx model: {} in path {}", inner, path.display()) | ||
}, | ||
|
@@ -299,6 +309,17 @@ fn snapshot_imfs_directory<'source>( | |
let init_path = directory.path.join(INIT_MODULE_NAME); | ||
let init_server_path = directory.path.join(INIT_SERVER_NAME); | ||
let init_client_path = directory.path.join(INIT_CLIENT_NAME); | ||
let init_meta_path = directory.path.join(INIT_META_NAME); | ||
|
||
let meta: InitMetaJson = if let Some(ImfsItem::File(file)) = imfs.get(&init_meta_path) { | ||
serde_json::from_slice(&file.contents) | ||
.map_err(|inner| SnapshotError::InitMetaError { | ||
inner, | ||
path: file.path.to_path_buf(), | ||
})? | ||
} else { | ||
InitMetaJson::default() | ||
}; | ||
|
||
let snapshot_name = instance_name | ||
.unwrap_or_else(|| { | ||
|
@@ -315,13 +336,13 @@ fn snapshot_imfs_directory<'source>( | |
snapshot_imfs_path(context, imfs, &init_client_path, Some(snapshot_name))?.unwrap() | ||
} else { | ||
RbxSnapshotInstance { | ||
class_name: Cow::Borrowed("Folder"), | ||
class_name: Cow::Owned(meta.class_name.unwrap_or_else(|| "Folder".to_owned())), | ||
name: snapshot_name, | ||
properties: HashMap::new(), | ||
properties: meta.properties, | ||
children: Vec::new(), | ||
metadata: MetadataPerInstance { | ||
source_path: None, | ||
ignore_unknown_instances: false, | ||
ignore_unknown_instances: meta.ignore_unknown_children.unwrap_or(false), | ||
project_definition: None, | ||
}, | ||
} | ||
LPGhatguy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -351,6 +372,20 @@ fn snapshot_imfs_directory<'source>( | |
Ok(Some(snapshot)) | ||
} | ||
|
||
#[derive(Debug, Default, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
struct InitMetaJson { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need the Since we don't serialize the struct, we might be able to drop the |
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
class_name: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
ignore_unknown_children: Option<bool>, | ||
#[serde( | ||
default = "HashMap::new", | ||
skip_serializing_if = "HashMap::is_empty", | ||
)] | ||
properties: HashMap<String, RbxValue>, | ||
LPGhatguy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
fn snapshot_imfs_file<'source>( | ||
context: &SnapshotContext, | ||
file: &'source ImfsFile, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "test-model", | ||
"tree": { | ||
"$path": "src" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "test-model", | ||
"class_name": "Tool", | ||
"properties": { | ||
"Enabled": { | ||
"Type": "Bool", | ||
"Value": true | ||
} | ||
}, | ||
"children": [ | ||
{ | ||
"name": "A", | ||
"class_name": "Folder", | ||
"properties": {}, | ||
"children": [], | ||
"metadata": { | ||
"ignore_unknown_instances": true, | ||
"source_path": "src/A", | ||
"project_definition": null | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"ignore_unknown_instances": false, | ||
"source_path": "src", | ||
"project_definition": [ | ||
"test-model", | ||
{ | ||
"class_name": null, | ||
"children": {}, | ||
"properties": {}, | ||
"ignore_unknown_instances": null, | ||
"path": "src" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ignoreUnknownChildren": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"className": "Tool", | ||
"properties": { | ||
"Enabled": { | ||
"Type": "Bool", | ||
"Value": true | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can fold this code down even further!
Instead of assigning the struct out here and defaulting to
InitMetaJson
, can we check for the existence of this file later, and then pull properties directly from it onto the snapshot?Then we can localize the changes to this function to exactly one region, and limit the impact in cases that don't use an
init.meta.json
file.