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 legacy and runContext script sync rule middlewares #909

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Added experimental setting for Auto Connect in playtests ([#840])
* Improved settings UI ([#886])
* `Open Scripts Externally` option can now be changed while syncing ([#911])
* Projects may now specify rules for syncing files as if they had a different file extension. ([#813])
* Projects may now specify rules for syncing files as if they had a different file extension. ([#813], [#909])
This is specified via a new field on project files, `syncRules`:

```json
Expand Down Expand Up @@ -37,7 +37,7 @@

Additionally, the `exclude` field allows files to be excluded from the sync rule if they match a pattern specified by it. If it's not present, all files that match `pattern` will be modified using the sync rule.

The `use` field corresponds to one of the potential file type that Rojo will currently include in a project. Files that match the provided pattern will be treated as if they had the file extension for that file type. A full list is below:
The `use` field corresponds to one of the potential file type that Rojo will currently include in a project. Files that match the provided pattern will be treated as if they had the file extension for that file type.

| `use` value | file extension |
|:---------------|:----------------|
Expand All @@ -54,6 +54,15 @@
| `project` | `.project.json` |
| `ignore` | None! |

Additionally, there are `use` values for specific script types:

| `use` value | script type |
|:-------------------------|:---------------------------------------|
| `legacyServerScript` | `Script` with `Enum.RunContext.Legacy` |
| `legactClientScript` | `LocalScript` |
| `runContextServerScript` | `Script` with `Enum.RunContext.Server` |
| `runContextClientScript` | `Script` with `Enum.RunContext.Client` |

**All** sync rules are reset between project files, so they must be specified in each one when nesting them. This is to ensure that nothing can break other projects by changing how files are synced!

[#813]: https://github.com/rojo-rbx/rojo/pull/813
Expand All @@ -64,6 +73,7 @@
[#886]: https://github.com/rojo-rbx/rojo/pull/886
[#893]: https://github.com/rojo-rbx/rojo/pull/893
[#903]: https://github.com/rojo-rbx/rojo/pull/903
[#909]: https://github.com/rojo-rbx/rojo/pull/909
[#911]: https://github.com/rojo-rbx/rojo/pull/911

## [7.4.1] - February 20, 2024
Expand Down
30 changes: 24 additions & 6 deletions src/snapshot_middleware/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ pub enum ScriptType {
Server,
Client,
Module,
LegacyServer,
LegacyClient,
RunContextServer,
RunContextClient,
}

/// Core routine for turning Lua files into snapshots.
Expand All @@ -31,12 +35,26 @@ pub fn snapshot_lua(
.expect("Unable to get RunContext enums!")
.items;

let (class_name, run_context) = match (context.emit_legacy_scripts, script_type) {
(false, ScriptType::Server) => ("Script", run_context_enums.get("Server")),
(false, ScriptType::Client) => ("Script", run_context_enums.get("Client")),
(true, ScriptType::Server) => ("Script", run_context_enums.get("Legacy")),
(true, ScriptType::Client) => ("LocalScript", None),
(_, ScriptType::Module) => ("ModuleScript", None),
let (class_name, run_context) = match script_type {
ScriptType::Server => {
if context.emit_legacy_scripts {
("Script", run_context_enums.get("Legacy"))
} else {
("Script", run_context_enums.get("Server"))
}
}
ScriptType::Client => {
if context.emit_legacy_scripts {
("LocalScript", None)
} else {
("Script", run_context_enums.get("Client"))
}
}
ScriptType::Module => ("ModuleScript", None),
ScriptType::LegacyServer => ("Script", run_context_enums.get("Legacy")),
ScriptType::LegacyClient => ("LocalScript", None),
ScriptType::RunContextServer => ("Script", run_context_enums.get("Server")),
ScriptType::RunContextClient => ("Script", run_context_enums.get("Client")),
};

let contents = vfs.read_to_string_lf_normalized(path)?;
Expand Down
16 changes: 16 additions & 0 deletions src/snapshot_middleware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ pub enum Middleware {
ServerScript,
ClientScript,
ModuleScript,
LegacyClientScript,
LegacyServerScript,
RunContextServerScript,
RunContextClientScript,
Project,
Rbxm,
Rbxmx,
Expand All @@ -224,6 +228,18 @@ impl Middleware {
Self::ServerScript => snapshot_lua(context, vfs, path, name, ScriptType::Server),
Self::ClientScript => snapshot_lua(context, vfs, path, name, ScriptType::Client),
Self::ModuleScript => snapshot_lua(context, vfs, path, name, ScriptType::Module),
Self::LegacyClientScript => {
snapshot_lua(context, vfs, path, name, ScriptType::LegacyClient)
}
Self::LegacyServerScript => {
snapshot_lua(context, vfs, path, name, ScriptType::LegacyServer)
}
Self::RunContextClientScript => {
snapshot_lua(context, vfs, path, name, ScriptType::RunContextClient)
}
Self::RunContextServerScript => {
snapshot_lua(context, vfs, path, name, ScriptType::RunContextServer)
}
Self::Project => snapshot_project(context, vfs, path, name),
Self::Rbxm => snapshot_rbxm(context, vfs, path, name),
Self::Rbxmx => snapshot_rbxmx(context, vfs, path, name),
Expand Down
Loading