mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-23 22:25:26 +00:00
Add RunContext support for script outputs (#765)
Resolves #667 This PR: - Introduces a new field in the project file: `scriptType` which has the default value of `Class` (in parity with previous versions), but can also be `RunContext`. - This is then passed to `InstanceContext` from the `Project` struct. - This then changes the RunContext in the lua `snapshot_middleware` --------- Co-authored-by: Micah <dekkonot@rocketmail.com>
This commit is contained in:
@@ -6,7 +6,10 @@ use std::{
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{glob::Glob, path_serializer, project::ProjectNode};
|
||||
use crate::{
|
||||
glob::Glob, path_serializer, project::ProjectNode,
|
||||
snapshot_middleware::emit_legacy_scripts_default,
|
||||
};
|
||||
|
||||
/// Rojo-specific metadata that can be associated with an instance or a snapshot
|
||||
/// of an instance.
|
||||
@@ -103,9 +106,26 @@ impl Default for InstanceMetadata {
|
||||
pub struct InstanceContext {
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub path_ignore_rules: Arc<Vec<PathIgnoreRule>>,
|
||||
pub emit_legacy_scripts: bool,
|
||||
}
|
||||
|
||||
impl InstanceContext {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
path_ignore_rules: Arc::new(Vec::new()),
|
||||
emit_legacy_scripts: emit_legacy_scripts_default().unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_emit_legacy_scripts(emit_legacy_scripts: Option<bool>) -> Self {
|
||||
Self {
|
||||
emit_legacy_scripts: emit_legacy_scripts
|
||||
.or_else(emit_legacy_scripts_default)
|
||||
.unwrap(),
|
||||
..Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// Extend the list of ignore rules in the context with the given new rules.
|
||||
pub fn add_path_ignore_rules<I>(&mut self, new_rules: I)
|
||||
where
|
||||
@@ -123,13 +143,15 @@ impl InstanceContext {
|
||||
let rules = Arc::make_mut(&mut self.path_ignore_rules);
|
||||
rules.extend(new_rules);
|
||||
}
|
||||
|
||||
pub fn set_emit_legacy_scripts(&mut self, emit_legacy_scripts: bool) {
|
||||
self.emit_legacy_scripts = emit_legacy_scripts;
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InstanceContext {
|
||||
fn default() -> Self {
|
||||
InstanceContext {
|
||||
path_ignore_rules: Arc::new(Vec::new()),
|
||||
}
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
---
|
||||
source: src/snapshot/tests/apply.rs
|
||||
expression: tree_view
|
||||
|
||||
---
|
||||
id: id-1
|
||||
name: ROOT
|
||||
@@ -12,6 +11,7 @@ properties:
|
||||
metadata:
|
||||
ignore_unknown_instances: false
|
||||
relevant_paths: []
|
||||
context: {}
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
children: []
|
||||
|
||||
|
||||
@@ -9,5 +9,7 @@ properties: {}
|
||||
metadata:
|
||||
ignore_unknown_instances: false
|
||||
relevant_paths: []
|
||||
context: {}
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
children: []
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
---
|
||||
source: src/snapshot/tests/apply.rs
|
||||
expression: tree_view
|
||||
|
||||
---
|
||||
id: id-1
|
||||
name: ROOT
|
||||
@@ -12,6 +11,7 @@ properties:
|
||||
metadata:
|
||||
ignore_unknown_instances: false
|
||||
relevant_paths: []
|
||||
context: {}
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
children: []
|
||||
|
||||
|
||||
@@ -9,5 +9,7 @@ properties: {}
|
||||
metadata:
|
||||
ignore_unknown_instances: false
|
||||
relevant_paths: []
|
||||
context: {}
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
children: []
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ added_instances:
|
||||
metadata:
|
||||
ignore_unknown_instances: false
|
||||
relevant_paths: []
|
||||
context: {}
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
name: New
|
||||
class_name: Folder
|
||||
properties: {}
|
||||
|
||||
Reference in New Issue
Block a user