Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RunContext support for script outputs #765

Merged
merged 24 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Added rich Source diffs in patch visualizer ([#748])
* Fix PatchTree performance issues ([#755])
* Don't override the initial enabled state for source diffing ([#760])
* A `$scriptType` field has been added to the project.json schema, allowing for scripts to be differentiated as lasses or through RunContext ([#765]).

[#761]: https://github.com/rojo-rbx/rojo/pull/761
[#745]: https://github.com/rojo-rbx/rojo/pull/745
Expand All @@ -50,6 +51,7 @@
[#748]: https://github.com/rojo-rbx/rojo/pull/748
[#755]: https://github.com/rojo-rbx/rojo/pull/755
[#760]: https://github.com/rojo-rbx/rojo/pull/760
[#765]: https://github.com/rojo-rbx/rojo/pull/765

## [7.3.0] - April 22, 2023
* Added `$attributes` to project format. ([#574])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ expression: contents
<Properties>
<string name="Name">hello</string>
<bool name="Disabled">true</bool>
<token name="RunContext">0</token>
<string name="Source">-- This script should be marked 'Disabled'</string>
</Properties>
</Item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ expression: contents
<Item class="Script" referent="1">
<Properties>
<string name="Name">serverScript</string>
<token name="RunContext">0</token>
<string name="Source">-- This is a Lua server script</string>
</Properties>
</Item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ expression: contents
<Item class="Script" referent="0">
<Properties>
<string name="Name">server_init</string>
<token name="RunContext">0</token>
<string name="Source">return "From folder/init.server.lua"</string>
</Properties>
</Item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ instances:
Name: bar
Parent: id-2
Properties:
RunContext:
Enum: 0
Source:
String: "-- Hello, from bar!"
id-4:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ instances:
Name: bar
Parent: id-2
Properties:
RunContext:
Enum: 0
Source:
String: "-- Hello, from bar!"
id-4:
Expand Down
8 changes: 7 additions & 1 deletion src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
use serde::{Deserialize, Serialize};
use thiserror::Error;

use crate::{glob::Glob, resolution::UnresolvedValue};
use crate::{glob::Glob, resolution::UnresolvedValue, snapshot_middleware::ScriptContextType};

static PROJECT_FILENAME: &str = "default.project.json";

Expand Down Expand Up @@ -73,6 +73,12 @@ pub struct Project {
#[serde(skip_serializing_if = "Option::is_none")]
pub serve_address: Option<IpAddr>,

/// The mode to use when mapping scripts into Roblox.
/// Can be either `Class` or `RunContext` and determines whether script
Dekkonot marked this conversation as resolved.
Show resolved Hide resolved
/// behavior is set using the `RunContext` property or the script's `ClassName`.
#[serde(default)]
pub script_type: ScriptContextType,
sasial-dev marked this conversation as resolved.
Show resolved Hide resolved

/// A list of globs, relative to the folder the project file is in, that
/// match files that should be excluded if Rojo encounters them.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
Expand Down
2 changes: 1 addition & 1 deletion src/serve_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl ServeSession {

let root_id = tree.get_root_id();

let instance_context = InstanceContext::default();
let instance_context = InstanceContext::from(root_project.script_type);

log::trace!("Generating snapshot of instances from VFS");
let snapshot = snapshot_from_vfs(&instance_context, &vfs, start_path)?;
Expand Down
44 changes: 32 additions & 12 deletions src/snapshot/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use std::{

use serde::{Deserialize, Serialize};

use crate::{glob::Glob, path_serializer, project::ProjectNode};
use crate::{
glob::Glob, path_serializer, project::ProjectNode, snapshot_middleware::ScriptContextType,
};

/// Rojo-specific metadata that can be associated with an instance or a snapshot
/// of an instance.
Expand Down Expand Up @@ -55,15 +57,6 @@ pub struct InstanceMetadata {
}

impl InstanceMetadata {
pub fn new() -> Self {
Self {
ignore_unknown_instances: false,
instigating_source: None,
relevant_paths: Vec::new(),
context: InstanceContext::default(),
}
}

sasial-dev marked this conversation as resolved.
Show resolved Hide resolved
pub fn ignore_unknown_instances(self, ignore_unknown_instances: bool) -> Self {
Self {
ignore_unknown_instances,
Expand Down Expand Up @@ -93,16 +86,33 @@ impl InstanceMetadata {
}
}

impl From<&InstanceContext> for InstanceMetadata {
fn from(context: &InstanceContext) -> Self {
Self {
ignore_unknown_instances: false,
instigating_source: None,
relevant_paths: Vec::new(),
context: context.to_owned(),
}
}
}
sasial-dev marked this conversation as resolved.
Show resolved Hide resolved

impl Default for InstanceMetadata {
fn default() -> Self {
Self::new()
Self {
ignore_unknown_instances: false,
instigating_source: None,
relevant_paths: Vec::new(),
context: InstanceContext::from(ScriptContextType::Class),
}
}
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct InstanceContext {
#[serde(skip_serializing_if = "Vec::is_empty")]
pub path_ignore_rules: Arc<Vec<PathIgnoreRule>>,
pub script_type: ScriptContextType,
}

impl InstanceContext {
Expand All @@ -125,10 +135,20 @@ impl InstanceContext {
}
}

impl From<ScriptContextType> for InstanceContext {
fn from(script_type: ScriptContextType) -> Self {
Self {
path_ignore_rules: Arc::new(Vec::new()),
script_type,
}
}
}

impl Default for InstanceContext {
fn default() -> Self {
InstanceContext {
Self {
path_ignore_rules: Arc::new(Vec::new()),
script_type: ScriptContextType::Class,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ properties:
metadata:
ignore_unknown_instances: false
relevant_paths: []
context: {}
context:
script_type: Class
children: []

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ properties: {}
metadata:
ignore_unknown_instances: false
relevant_paths: []
context: {}
context:
script_type: Class
children: []
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ properties:
metadata:
ignore_unknown_instances: false
relevant_paths: []
context: {}
context:
script_type: Class
children: []

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ properties: {}
metadata:
ignore_unknown_instances: false
relevant_paths: []
context: {}
context:
script_type: Class
children: []
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ added_instances:
metadata:
ignore_unknown_instances: false
relevant_paths: []
context: {}
context:
script_type: Class
name: New
class_name: Folder
properties: {}
Expand Down
2 changes: 1 addition & 1 deletion src/snapshot_middleware/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn snapshot_csv(
"Contents".to_owned() => table_contents.into(),
})
.metadata(
InstanceMetadata::new()
InstanceMetadata::default()
.instigating_source(path)
.relevant_paths(vec![path.to_path_buf(), meta_path.clone()]),
);
Expand Down
2 changes: 1 addition & 1 deletion src/snapshot_middleware/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn snapshot_dir_no_meta(
.class_name("Folder")
.children(snapshot_children)
.metadata(
InstanceMetadata::new()
InstanceMetadata::default()
.instigating_source(path)
.relevant_paths(relevant_paths)
.context(context),
Expand Down
2 changes: 1 addition & 1 deletion src/snapshot_middleware/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn snapshot_json(
.class_name("ModuleScript")
.properties(properties)
.metadata(
InstanceMetadata::new()
InstanceMetadata::default()
.instigating_source(path)
.relevant_paths(vec![path.to_path_buf(), meta_path.clone()])
.context(context),
Expand Down
Loading