Use rbx_reflection to allow type inference on projects (#130)

* Start dependency on rbx_reflection

* Alive and working, all tests pass

* Update CHANGELOG
This commit is contained in:
Lucien Greathouse
2019-02-26 22:51:21 -08:00
committed by GitHub
parent be81de74cd
commit 93349ae2dc
7 changed files with 43 additions and 16 deletions

View File

@@ -5,6 +5,7 @@
* Types like `Color3` and `CFrame` can now be updated live!
* Fixed plugin assets flashing in on first load ([#121](https://github.com/LPGhatguy/rojo/issues/121))
* Changed Rojo's HTTP server from Rouille to Hyper, which reduced the release size by around a megabyte.
* Added property type inference to projects, which makes specifying services a lot easier ([#130](https://github.com/LPGhatguy/rojo/pull/130))
## [0.5.0 Alpha 4](https://github.com/LPGhatguy/rojo/releases/tag/v0.5.0-alpha.4) (February 8, 2019)
* Added support for nested partitions ([#102](https://github.com/LPGhatguy/rojo/issues/102))

22
Cargo.lock generated
View File

@@ -1029,12 +1029,12 @@ dependencies = [
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lz4 1.23.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rbx_dom_weak 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rbx_dom_weak 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rbx_dom_weak"
version = "0.3.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1042,6 +1042,16 @@ dependencies = [
"uuid 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rbx_reflection"
version = "1.0.373"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rbx_dom_weak 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rbx_xml"
version = "0.3.0"
@@ -1052,7 +1062,7 @@ dependencies = [
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rbx_dom_weak 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rbx_dom_weak 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1185,7 +1195,8 @@ dependencies = [
"pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rbx_binary 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rbx_dom_weak 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rbx_dom_weak 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rbx_reflection 1.0.373 (registry+https://github.com/rust-lang/crates.io-index)",
"rbx_xml 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1848,7 +1859,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "086bd09a33c7044e56bb44d5bdde5a60e7f119a9e95b0775f545de759a32fe05"
"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
"checksum rbx_binary 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c4d3bffbec1f20f66684448e46ef45dad2fbf1185c3d8f3e29018f027484ffc"
"checksum rbx_dom_weak 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a67bbec623f2f12992dbf2e647deb3fe38613d4f874a8feeae566a931bebe63a"
"checksum rbx_dom_weak 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "673606053dba942f6c4607661c423424711a60cb40481f1e20c55acc21f53a38"
"checksum rbx_reflection 1.0.373 (registry+https://github.com/rust-lang/crates.io-index)" = "b37499dc2e097063be0eff716f54fb060ef3beb732e5f699b56feb6d9aa2442b"
"checksum rbx_xml 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2b394e64979c52190e6462dd81d5b2258cdfb7e3891cefaff5d3c4af7cdc07b5"
"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85"

View File

@@ -31,8 +31,9 @@ maplit = "1.0.1"
notify = "4.0"
rand = "0.4"
rbx_binary = "0.3.0"
rbx_dom_weak = "0.3.0"
rbx_dom_weak = "0.3.1"
rbx_xml = "0.3.0"
rbx_reflection = "1.0.373"
regex = "1.0"
reqwest = "0.9.5"
rlua = "0.16"

View File

@@ -9,7 +9,7 @@ use std::{
use log::warn;
use failure::Fail;
use maplit::hashmap;
use rbx_dom_weak::RbxValue;
use rbx_dom_weak::{UnresolvedRbxValue, RbxValue};
use serde_derive::{Serialize, Deserialize};
pub static PROJECT_FILENAME: &'static str = "default.project.json";
@@ -64,7 +64,7 @@ struct SourceProjectNode {
class_name: Option<String>,
#[serde(rename = "$properties", default = "HashMap::new", skip_serializing_if = "HashMap::is_empty")]
properties: HashMap<String, RbxValue>,
properties: HashMap<String, UnresolvedRbxValue>,
#[serde(rename = "$ignoreUnknownInstances", skip_serializing_if = "Option::is_none")]
ignore_unknown_instances: Option<bool>,
@@ -188,7 +188,7 @@ pub enum ProjectSaveError {
pub struct ProjectNode {
pub class_name: Option<String>,
pub children: HashMap<String, ProjectNode>,
pub properties: HashMap<String, RbxValue>,
pub properties: HashMap<String, UnresolvedRbxValue>,
pub ignore_unknown_instances: Option<bool>,
#[serde(serialize_with = "crate::path_serializer::serialize_option")]
@@ -284,7 +284,7 @@ impl Project {
properties: hashmap! {
String::from("HttpEnabled") => RbxValue::Bool {
value: true,
},
}.into(),
},
..Default::default()
},

View File

@@ -15,6 +15,7 @@ use log::info;
use maplit::hashmap;
use rbx_dom_weak::{RbxTree, RbxValue, RbxInstanceProperties};
use serde_derive::{Serialize, Deserialize};
use rbx_reflection::{try_resolve_value, ValueResolveError};
use crate::{
imfs::{
@@ -119,6 +120,19 @@ pub enum SnapshotError {
ProjectNodeInvalidTransmute {
partition_path: PathBuf,
},
PropertyResolveError {
#[fail(cause)]
inner: ValueResolveError,
},
}
impl From<ValueResolveError> for SnapshotError {
fn from(inner: ValueResolveError) -> SnapshotError {
SnapshotError::PropertyResolveError {
inner,
}
}
}
impl fmt::Display for SnapshotError {
@@ -147,6 +161,7 @@ impl fmt::Display for SnapshotError {
writeln!(output, "")?;
writeln!(output, "Partition target ($path): {}", partition_path.display())
},
SnapshotError::PropertyResolveError { inner } => write!(output, "{}", inner),
}
}
}
@@ -226,7 +241,8 @@ pub fn snapshot_project_node<'source>(
}
for (key, value) in &node.properties {
snapshot.properties.insert(key.clone(), value.clone());
let resolved_value = try_resolve_value(&snapshot.class_name, key, value)?;
snapshot.properties.insert(key.clone(), resolved_value);
}
if let Some(ignore_unknown_instances) = node.ignore_unknown_instances {

View File

@@ -65,7 +65,7 @@ fn single_partition_game() {
let mut http_service_properties = HashMap::new();
http_service_properties.insert("HttpEnabled".to_string(), RbxValue::Bool {
value: true,
});
}.into());
let http_service = ProjectNode {
class_name: Some(String::from("HttpService")),

View File

@@ -11,10 +11,7 @@
"HttpService": {
"$className": "HttpService",
"$properties": {
"HttpEnabled": {
"Type": "Bool",
"Value": true
}
"HttpEnabled": true
}
}
}