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:
Sasial
2023-09-24 06:28:09 +10:00
committed by GitHub
parent 539cd0d418
commit bb8dd1402d
56 changed files with 602 additions and 95 deletions

View File

@@ -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()
}
}

View File

@@ -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: []

View File

@@ -9,5 +9,7 @@ properties: {}
metadata:
ignore_unknown_instances: false
relevant_paths: []
context: {}
context:
emit_legacy_scripts: true
children: []

View File

@@ -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: []

View File

@@ -9,5 +9,7 @@ properties: {}
metadata:
ignore_unknown_instances: false
relevant_paths: []
context: {}
context:
emit_legacy_scripts: true
children: []

View File

@@ -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: {}