From bfe8dcd2246bf8b0cca9c1f215bcf5cc05eb14ff Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Mon, 2 Jul 2018 18:34:12 -0700 Subject: [PATCH] Try out some nonsense with services being special-ish cased --- server/src/rbx_session.rs | 58 ++++++++++++++++--- .../test-projects/partition-to-file/foo.lua | 0 .../test-projects/partition-to-file/rojo.json | 10 ++++ server/tests/web.rs | 5 +- 4 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 server/test-projects/partition-to-file/foo.lua create mode 100644 server/test-projects/partition-to-file/rojo.json diff --git a/server/src/rbx_session.rs b/server/src/rbx_session.rs index 198fd52d..74514678 100644 --- a/server/src/rbx_session.rs +++ b/server/src/rbx_session.rs @@ -9,6 +9,43 @@ use project::Project; use rbx::{RbxInstance, RbxTree, RbxValue}; use vfs_session::{VfsSession, FileItem, FileChange}; +static SERVICES: &'static [&'static str] = &[ + "Chat", + "Lighting", + "LocalizationService", + "Players", + "ReplicatedFirst", + "ReplicatedStorage", + "ServerScriptService", + "ServerStorage", + "SoundService", + "StarterGui", + "StarterPack", + "StarterPlayer", + "TestService", + "Workspace", +]; + +fn get_partition_target_class_name(target: &[String]) -> &'static str { + match target.len() { + 1 => { + let target_name = &target[0]; + + for &service in SERVICES { + if service == target_name { + return service; + } + } + + "Folder" + }, + 2 => { + "Folder" + }, + _ => "Folder", + } +} + // TODO: Rethink data structure and insertion/update behavior. Maybe break some // pieces off into a new object? fn file_to_instances( @@ -32,10 +69,13 @@ fn file_to_instances( // This is placeholder logic; this whole function is! let (class_name, property_key, name) = { - let file_name = route.route.last().unwrap_or(&route.partition); + let file_name = match route.route.last() { + Some(v) => v.to_string(), + None => partition.path.file_name().unwrap().to_str().unwrap().to_string() + }; - fn strip_suffix<'a>(source: &'a str, suffix: &'static str) -> &'a str { - &source[..source.len() - suffix.len()] + fn strip_suffix<'a>(source: &'a str, suffix: &'static str) -> String { + source[..source.len() - suffix.len()].to_string() } if file_name.ends_with(".client.lua") { @@ -46,7 +86,7 @@ fn file_to_instances( ("ModuleScript", "Source", strip_suffix(&file_name, ".lua")) } else { // TODO: Error/warn/skip instead of falling back - ("StringValue", "Value", file_name.as_str()) + ("StringValue", "Value", file_name) } }; @@ -54,7 +94,7 @@ fn file_to_instances( properties.insert(property_key.to_string(), RbxValue::String { value: contents.clone() }); tree.insert_instance(primary_id, RbxInstance { - name: name.to_string(), + name, class_name: class_name.to_string(), properties, children: Vec::new(), @@ -90,9 +130,13 @@ fn file_to_instances( } } + let class_name = get_partition_target_class_name(&route.route).to_string(); + + let name = route.name(partition); + tree.insert_instance(primary_id, RbxInstance { - name: route.name(partition).to_string(), - class_name: "Folder".to_string(), + name, + class_name, properties: HashMap::new(), children: child_ids, parent: parent_id, diff --git a/server/test-projects/partition-to-file/foo.lua b/server/test-projects/partition-to-file/foo.lua new file mode 100644 index 00000000..e69de29b diff --git a/server/test-projects/partition-to-file/rojo.json b/server/test-projects/partition-to-file/rojo.json new file mode 100644 index 00000000..5592e29f --- /dev/null +++ b/server/test-projects/partition-to-file/rojo.json @@ -0,0 +1,10 @@ +{ + "name": "partition-to-file", + "servePort": 23456, + "partitions": { + "lib": { + "path": "foo.lua", + "target": "ReplicatedStorage.foo" + } + } +} \ No newline at end of file diff --git a/server/tests/web.rs b/server/tests/web.rs index f37295a4..733382be 100644 --- a/server/tests/web.rs +++ b/server/tests/web.rs @@ -194,7 +194,9 @@ fn one_partition() { assert_eq!(single_instance, &Cow::Borrowed(instance)); }, - _ => {}, + _ => { + panic!("Unexpected instance named {} of class {}", instance.name, instance.class_name); + }, } } @@ -388,5 +390,4 @@ fn one_partition() { } // TODO: Test to change existing instance - // TODO: Copy each project into temp dir before using them } \ No newline at end of file