Skip to content

Commit

Permalink
Support init.model.json
Browse files Browse the repository at this point in the history
Closes rojo-rbx#66.
  • Loading branch information
LPGhatguy committed Jun 2, 2018
1 parent d5d99a4 commit 50e4820
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
37 changes: 35 additions & 2 deletions server/src/plugins/json_model_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ lazy_static! {
static ref JSON_MODEL_PATTERN: Regex = Regex::new(r"^(.*?)\.model\.json$").unwrap();
}

static JSON_MODEL_INIT: &'static str = "init.model.json";

pub struct JsonModelPlugin;

impl JsonModelPlugin {
Expand All @@ -19,7 +21,7 @@ impl JsonModelPlugin {
}

impl Plugin for JsonModelPlugin {
fn transform_file(&self, _plugins: &PluginChain, vfs_item: &VfsItem) -> TransformFileResult {
fn transform_file(&self, plugins: &PluginChain, vfs_item: &VfsItem) -> TransformFileResult {
match vfs_item {
&VfsItem::File { ref contents, .. } => {
let rbx_name = match JSON_MODEL_PATTERN.captures(vfs_item.name()) {
Expand All @@ -41,7 +43,38 @@ impl Plugin for JsonModelPlugin {

TransformFileResult::Value(Some(rbx_item))
},
&VfsItem::Dir { .. } => TransformFileResult::Pass,
&VfsItem::Dir { ref children, .. } => {
let init_item = match children.get(JSON_MODEL_INIT) {
Some(v) => v,
None => return TransformFileResult::Pass,
};

let mut rbx_item = match self.transform_file(plugins, init_item) {
TransformFileResult::Value(Some(item)) => item,
TransformFileResult::Value(None) | TransformFileResult::Pass => {
eprintln!("Inconsistency detected in JsonModelPlugin!");
return TransformFileResult::Pass;
},
};

rbx_item.name.clear();
rbx_item.name.push_str(vfs_item.name());

for (child_name, child_item) in children {
if child_name == init_item.name() {
continue;
}

match plugins.transform_file(child_item) {
Some(child_rbx_item) => {
rbx_item.children.push(child_rbx_item);
},
_ => {},
}
}

TransformFileResult::Value(Some(rbx_item))
},
}
}

Expand Down
1 change: 1 addition & 0 deletions test-project/src/SomeTool/SomeTool.client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello, world, from my tool!")
4 changes: 4 additions & 0 deletions test-project/src/SomeTool/init.model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Name": "SomeTool",
"ClassName": "Tool"
}

0 comments on commit 50e4820

Please sign in to comment.