diff --git a/DESIGN.md b/DESIGN.md index 46ad11a0..f1877c39 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -6,12 +6,12 @@ This is a super rough draft that I'm trying to use to lay out some of my thought ### POST `/read` Accepts a `Vec` of items to read. -Returns `Vec>`, in the same order as the request. +Returns `Vec>`, in the same order as the request. ### POST `/write` -Accepts a `Vec<{ Route, RbxItem }>` of items to write. +Accepts a `Vec<{ Route, RbxInstance }>` of items to write. -I imagine that the `Name` attribute of the top-level `RbxItem` would be ignored in favor of the route name? +I imagine that the `Name` attribute of the top-level `RbxInstance` would be ignored in favor of the route name? ## CLI The `rojo serve` command uses three major components: @@ -21,7 +21,7 @@ The `rojo serve` command uses three major components: ### Transform Plugins Transform plugins (or filter plugins?) can interject in three places: -* Transform a `VfsItem` that's being read into an `RbxItem` in the VFS +* Transform a `VfsItem` that's being read into an `RbxInstance` in the VFS * Transform an `Rbxitem` that's being written into a `VfsItem` in the VFS * Transform a file change into paths that need to be updated in the VFS watcher diff --git a/src/plugin.rs b/src/plugin.rs index 5b80f084..3f18bcbe 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -1,10 +1,10 @@ -use rbx::RbxItem; +use rbx::RbxInstance; use vfs::VfsItem; use core::Route; // TODO: Add error case? pub enum TransformFileResult { - Value(Option), + Value(Option), Pass, } @@ -20,7 +20,7 @@ pub enum FileChangeResult { pub trait Plugin { fn transform_file(&self, plugins: &PluginChain, vfs_item: &VfsItem) -> TransformFileResult; - fn handle_rbx_change(&self, route: &Route, rbx_item: &RbxItem) -> RbxChangeResult; + fn handle_rbx_change(&self, route: &Route, rbx_item: &RbxInstance) -> RbxChangeResult; fn handle_file_change(&self, route: &Route) -> FileChangeResult; } @@ -35,7 +35,7 @@ impl PluginChain { } } - pub fn transform_file(&self, vfs_item: &VfsItem) -> Option { + pub fn transform_file(&self, vfs_item: &VfsItem) -> Option { for plugin in &self.plugins { match plugin.transform_file(self, vfs_item) { TransformFileResult::Value(rbx_item) => return rbx_item, @@ -46,7 +46,7 @@ impl PluginChain { None } - pub fn handle_rbx_change(&self, route: &Route, rbx_item: &RbxItem) -> Option { + pub fn handle_rbx_change(&self, route: &Route, rbx_item: &RbxInstance) -> Option { for plugin in &self.plugins { match plugin.handle_rbx_change(route, rbx_item) { RbxChangeResult::Write(vfs_item) => return vfs_item, diff --git a/src/plugins/default_plugin.rs b/src/plugins/default_plugin.rs index a870aa18..276aa50f 100644 --- a/src/plugins/default_plugin.rs +++ b/src/plugins/default_plugin.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use core::Route; use plugin::{Plugin, PluginChain, TransformFileResult, RbxChangeResult, FileChangeResult}; -use rbx::{RbxItem, RbxValue}; +use rbx::{RbxInstance, RbxValue}; use vfs::VfsItem; /// A plugin with simple transforms: @@ -26,7 +26,7 @@ impl Plugin for DefaultPlugin { value: contents.clone(), }); - TransformFileResult::Value(Some(RbxItem { + TransformFileResult::Value(Some(RbxInstance { name: vfs_item.name().clone(), class_name: "StringValue".to_string(), children: Vec::new(), @@ -45,7 +45,7 @@ impl Plugin for DefaultPlugin { } } - TransformFileResult::Value(Some(RbxItem { + TransformFileResult::Value(Some(RbxInstance { name: vfs_item.name().clone(), class_name: "Folder".to_string(), children: rbx_children, @@ -59,7 +59,7 @@ impl Plugin for DefaultPlugin { FileChangeResult::MarkChanged(Some(vec![route.clone()])) } - fn handle_rbx_change(&self, _route: &Route, _rbx_item: &RbxItem) -> RbxChangeResult { + fn handle_rbx_change(&self, _route: &Route, _rbx_item: &RbxInstance) -> RbxChangeResult { RbxChangeResult::Pass } } diff --git a/src/plugins/json_model_plugin.rs b/src/plugins/json_model_plugin.rs index 29be5b29..ed8178ca 100644 --- a/src/plugins/json_model_plugin.rs +++ b/src/plugins/json_model_plugin.rs @@ -3,7 +3,7 @@ use serde_json; use core::Route; use plugin::{Plugin, PluginChain, TransformFileResult, RbxChangeResult, FileChangeResult}; -use rbx::{RbxItem, RbxValue}; +use rbx::{RbxInstance, RbxValue}; use vfs::VfsItem; lazy_static! { @@ -27,7 +27,7 @@ impl Plugin for JsonModelPlugin { None => return TransformFileResult::Pass, }; - let mut rbx_item: RbxItem = match serde_json::from_str(contents) { + let mut rbx_item: RbxInstance = match serde_json::from_str(contents) { Ok(v) => v, Err(_) => { eprintln!("Unable to parse JSON Model File named {}", vfs_item.name()); @@ -50,7 +50,7 @@ impl Plugin for JsonModelPlugin { FileChangeResult::Pass } - fn handle_rbx_change(&self, _route: &Route, _rbx_item: &RbxItem) -> RbxChangeResult { + fn handle_rbx_change(&self, _route: &Route, _rbx_item: &RbxInstance) -> RbxChangeResult { RbxChangeResult::Pass } } diff --git a/src/plugins/script_plugin.rs b/src/plugins/script_plugin.rs index 183d5df8..86810be3 100644 --- a/src/plugins/script_plugin.rs +++ b/src/plugins/script_plugin.rs @@ -4,7 +4,7 @@ use regex::Regex; use core::Route; use plugin::{Plugin, PluginChain, TransformFileResult, RbxChangeResult, FileChangeResult}; -use rbx::{RbxItem, RbxValue}; +use rbx::{RbxInstance, RbxValue}; use vfs::VfsItem; lazy_static! { @@ -49,7 +49,7 @@ impl Plugin for ScriptPlugin { value: contents.clone(), }); - TransformFileResult::Value(Some(RbxItem { + TransformFileResult::Value(Some(RbxInstance { name: rbx_name, class_name: class_name, children: Vec::new(), @@ -117,7 +117,7 @@ impl Plugin for ScriptPlugin { } } - fn handle_rbx_change(&self, _route: &Route, _rbx_item: &RbxItem) -> RbxChangeResult { + fn handle_rbx_change(&self, _route: &Route, _rbx_item: &RbxInstance) -> RbxChangeResult { RbxChangeResult::Pass } } diff --git a/src/rbx.rs b/src/rbx.rs index 234529ca..151414e0 100644 --- a/src/rbx.rs +++ b/src/rbx.rs @@ -2,10 +2,10 @@ use std::collections::HashMap; #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct RbxItem { +pub struct RbxInstance { pub name: String, pub class_name: String, - pub children: Vec, + pub children: Vec, pub properties: HashMap, } diff --git a/src/web.rs b/src/web.rs index a91bcd38..c475bc6e 100644 --- a/src/web.rs +++ b/src/web.rs @@ -8,7 +8,7 @@ use serde_json; use core::Config; use project::Project; use vfs::{Vfs, VfsChange}; -use rbx::RbxItem; +use rbx::RbxInstance; use plugin::PluginChain; static MAX_BODY_SIZE: usize = 25 * 1024 * 1024; // 25 MiB @@ -26,7 +26,7 @@ struct ServerInfo<'a> { #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] struct ReadResult<'a> { - items: Vec>, + items: Vec>, server_id: &'a str, current_time: f64, } @@ -43,7 +43,7 @@ struct ChangesResult<'a> { #[serde(rename_all = "camelCase")] struct WriteSpecifier { route: String, - item: RbxItem, + item: RbxInstance, } fn json(value: T) -> rouille::Response {