forked from rojo-rbx/rojo
Support implicit values in JSON models (#154)
* Support implicit values in JSON models * Update Changelog
This commit is contained in:
committed by
GitHub
parent
83a0ae673c
commit
f290e7b5b2
@@ -1,6 +1,7 @@
|
||||
# Rojo Changelog
|
||||
|
||||
## [Unreleased]
|
||||
* Added support for implicit property values in JSON model files ([#154](https://github.com/LPGhatguy/rojo/pull/154))
|
||||
|
||||
## [0.5.0 Alpha 9](https://github.com/LPGhatguy/rojo/releases/tag/v0.5.0-alpha.9) (April 4, 2019)
|
||||
* Changed `rojo build` to use buffered I/O, which can make it up to 2x faster in some cases.
|
||||
|
||||
@@ -13,7 +13,7 @@ use rlua::Lua;
|
||||
use failure::Fail;
|
||||
use log::info;
|
||||
use maplit::hashmap;
|
||||
use rbx_dom_weak::{RbxTree, RbxValue, RbxInstanceProperties};
|
||||
use rbx_dom_weak::{RbxTree, RbxValue, RbxInstanceProperties, UnresolvedRbxValue};
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
use rbx_reflection::{try_resolve_value, ValueResolveError};
|
||||
|
||||
@@ -602,7 +602,7 @@ fn snapshot_json_model_file<'source>(
|
||||
path: file.path.to_owned(),
|
||||
})?;
|
||||
|
||||
let mut snapshot = json_instance.into_snapshot();
|
||||
let mut snapshot = json_instance.into_snapshot()?;
|
||||
snapshot.metadata.source_path = Some(file.path.to_owned());
|
||||
|
||||
Ok(Some(snapshot))
|
||||
@@ -618,23 +618,31 @@ struct JsonModelInstance {
|
||||
children: Vec<JsonModelInstance>,
|
||||
|
||||
#[serde(default = "HashMap::new", skip_serializing_if = "HashMap::is_empty")]
|
||||
properties: HashMap<String, RbxValue>,
|
||||
properties: HashMap<String, UnresolvedRbxValue>,
|
||||
}
|
||||
|
||||
impl JsonModelInstance {
|
||||
fn into_snapshot(mut self) -> RbxSnapshotInstance<'static> {
|
||||
let children = self.children
|
||||
.drain(..)
|
||||
.map(JsonModelInstance::into_snapshot)
|
||||
.collect();
|
||||
fn into_snapshot(self) -> Result<RbxSnapshotInstance<'static>, SnapshotError> {
|
||||
let mut children = Vec::with_capacity(self.children.len());
|
||||
|
||||
RbxSnapshotInstance {
|
||||
for child in self.children {
|
||||
children.push(child.into_snapshot()?);
|
||||
}
|
||||
|
||||
let mut properties = HashMap::with_capacity(self.properties.len());
|
||||
|
||||
for (key, value) in self.properties {
|
||||
let resolved_value = try_resolve_value(&self.class_name, &key, &value)?;
|
||||
properties.insert(key, resolved_value);
|
||||
}
|
||||
|
||||
Ok(RbxSnapshotInstance {
|
||||
name: Cow::Owned(self.name),
|
||||
class_name: Cow::Owned(self.class_name),
|
||||
properties: self.properties,
|
||||
properties,
|
||||
children,
|
||||
metadata: Default::default(),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ macro_rules! generate_snapshot_tests {
|
||||
|
||||
generate_snapshot_tests!(
|
||||
empty,
|
||||
json_model,
|
||||
localization,
|
||||
multi_partition_game,
|
||||
nested_partitions,
|
||||
|
||||
6
test-projects/json_model/default.project.json
Normal file
6
test-projects/json_model/default.project.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "json_model",
|
||||
"tree": {
|
||||
"$path": "src"
|
||||
}
|
||||
}
|
||||
76
test-projects/json_model/expected-snapshot.json
Normal file
76
test-projects/json_model/expected-snapshot.json
Normal file
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"name": "json_model",
|
||||
"class_name": "Folder",
|
||||
"properties": {},
|
||||
"children": [
|
||||
{
|
||||
"name": "children",
|
||||
"class_name": "Folder",
|
||||
"properties": {},
|
||||
"children": [
|
||||
{
|
||||
"name": "The Child",
|
||||
"class_name": "StringValue",
|
||||
"properties": {},
|
||||
"children": [],
|
||||
"metadata": {
|
||||
"ignore_unknown_instances": false,
|
||||
"source_path": null,
|
||||
"project_definition": null
|
||||
}
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"ignore_unknown_instances": false,
|
||||
"source_path": "src/children.model.json",
|
||||
"project_definition": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "explicit",
|
||||
"class_name": "StringValue",
|
||||
"properties": {
|
||||
"Value": {
|
||||
"Type": "String",
|
||||
"Value": "Hello, world!"
|
||||
}
|
||||
},
|
||||
"children": [],
|
||||
"metadata": {
|
||||
"ignore_unknown_instances": false,
|
||||
"source_path": "src/explicit.model.json",
|
||||
"project_definition": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "implicit",
|
||||
"class_name": "StringValue",
|
||||
"properties": {
|
||||
"Value": {
|
||||
"Type": "String",
|
||||
"Value": "What's happenin', Earth?"
|
||||
}
|
||||
},
|
||||
"children": [],
|
||||
"metadata": {
|
||||
"ignore_unknown_instances": false,
|
||||
"source_path": "src/implicit.model.json",
|
||||
"project_definition": null
|
||||
}
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"ignore_unknown_instances": false,
|
||||
"source_path": "src",
|
||||
"project_definition": [
|
||||
"json_model",
|
||||
{
|
||||
"class_name": null,
|
||||
"children": {},
|
||||
"properties": {},
|
||||
"ignore_unknown_instances": null,
|
||||
"path": "src"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
10
test-projects/json_model/src/children.model.json
Normal file
10
test-projects/json_model/src/children.model.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"Name": "children",
|
||||
"ClassName": "Folder",
|
||||
"Children": [
|
||||
{
|
||||
"Name": "The Child",
|
||||
"ClassName": "StringValue"
|
||||
}
|
||||
]
|
||||
}
|
||||
11
test-projects/json_model/src/explicit.model.json
Normal file
11
test-projects/json_model/src/explicit.model.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"Name": "explicit",
|
||||
"ClassName": "StringValue",
|
||||
"Properties": {
|
||||
"Value": {
|
||||
"Type": "String",
|
||||
"Value": "Hello, world!"
|
||||
}
|
||||
},
|
||||
"Children": []
|
||||
}
|
||||
7
test-projects/json_model/src/implicit.model.json
Normal file
7
test-projects/json_model/src/implicit.model.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"Name": "implicit",
|
||||
"ClassName": "StringValue",
|
||||
"Properties": {
|
||||
"Value": "What's happenin', Earth?"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user