Skip to content

Commit

Permalink
Add support for remote folders
Browse files Browse the repository at this point in the history
  • Loading branch information
sasial-dev committed Aug 13, 2024
1 parent 43112fb commit 523d15f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 7 deletions.
4 changes: 3 additions & 1 deletion docs/.vitepress/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const beforeMount = (monaco: Monaco) => {
const Calls = ["SingleSync", "SingleAsync", "ManySync", "ManyAsync"] as const;
const Options = ["write_checks", "typescript", "typescript_max_tuple_length", "manual_event_loop", "remote_scope", "server_output", "client_output", "casing", "yield_type", "async_lib", "tooling", "tooling_output", "tooling_show_internal_data"] as const;
const Options = ["write_checks", "typescript", "typescript_max_tuple_length", "manual_event_loop", "remote_scope", "remote_folder", "server_output", "client_output", "casing", "yield_type", "async_lib", "tooling", "tooling_output", "tooling_show_internal_data"] as const;
const Casing = ["PascalCase", "camelCase", "snake_case"].map((value) => `"${value}"`);
const YieldType = ["yield", "future", "promise"].map((value) => `"${value}"`);
Expand Down Expand Up @@ -161,7 +161,9 @@ const beforeMount = (monaco: Monaco) => {
write_checks: Operators,
manual_event_loop: Operators,
remote_scope: [],
remote_folder: [],
server_output: [],
client_output: [],
Expand Down
18 changes: 18 additions & 0 deletions docs/config/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ The generated remotes will be `ZAP_RELIABLE` and `ZAP_UNRELIABLE` respectively.

The generated remotes will change to be `PACKAGE_NAME_RELIABLE` and `PACKAGE_NAME_UNRELIABLE` respectively.

## `remote_folder`

This option changes the name folder that Zap's remotes are placed inside of ReplicatedStorage.

### Default

<CodeBlock code = 'opt remote_folder = "ZAP"' />


The generated remotes will be in `ReplicatedStorage -> ZAP`.


### Example

<CodeBlock code = 'opt remote_scope = "CHARACTER"' />


The generated remotes be in `ReplicatedStorage -> CHARACTER`

## `casing`

Expand Down
2 changes: 2 additions & 0 deletions zap/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ pub struct Config<'src> {

pub write_checks: bool,
pub manual_event_loop: bool,

pub remote_scope: &'src str,
pub remote_folder: &'src str,

pub server_output: &'src str,
pub client_output: &'src str,
Expand Down
8 changes: 6 additions & 2 deletions zap/src/output/luau/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,11 +828,15 @@ impl<'src> ClientOutput<'src> {

pub fn push_remotes(&mut self) {
self.push_line(&format!(
"local reliable = ReplicatedStorage:WaitForChild(\"{}_RELIABLE\")",
"local remotes = ReplicatedStorage:WaitForChild(\"{}\")",
self.config.remote_folder
));
self.push_line(&format!(
"local reliable = remotes:WaitForChild(\"{}_RELIABLE\")",
self.config.remote_scope
));
self.push_line(&format!(
"local unreliable = ReplicatedStorage:WaitForChild(\"{}_UNRELIABLE\")",
"local unreliable = remotes:WaitForChild(\"{}_UNRELIABLE\")",
self.config.remote_scope
));
self.push("\n");
Expand Down
23 changes: 19 additions & 4 deletions zap/src/output/luau/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,22 +877,36 @@ impl<'a> ServerOutput<'a> {
}

pub fn push_create_remotes(&mut self) {
self.push("\n");
self.push_line(&format!(
"local reliable = ReplicatedStorage:FindFirstChild(\"{}_RELIABLE\")",
"local remotes = ReplicatedStorage:FindFirstChild(\"{}\")",
self.config.remote_folder
));
self.push_line("if remotes == nil then");
self.indent();
self.push_line("remotes = Instance.new(\"Folder\")");
self.push_line(&format!("remotes.Name = \"{}\"", self.config.remote_folder));
self.push_line("remotes.Parent = ReplicatedStorage");
self.dedent();
self.push_line("end");
self.push("\n");

self.push_line(&format!(
"local reliable = remotes:FindFirstChild(\"{}_RELIABLE\")",
self.config.remote_scope
));
self.push_line("if reliable == nil then");
self.indent();
self.push_line("reliable = Instance.new(\"RemoteEvent\")");
self.push_line(&format!("reliable.Name = \"{}_RELIABLE\"", self.config.remote_scope));
self.push_line("reliable.Parent = ReplicatedStorage");
self.push_line("reliable.Parent = remotes");
self.dedent();
self.push_line("end");

self.push("\n");

self.push_line(&format!(
"local unreliable = ReplicatedStorage:FindFirstChild(\"{}_UNRELIABLE\")",
"local unreliable = remotes:FindFirstChild(\"{}_UNRELIABLE\")",
self.config.remote_scope
));
self.push_line("if unreliable == nil then");
Expand All @@ -902,9 +916,10 @@ impl<'a> ServerOutput<'a> {
"unreliable.Name = \"{}_UNRELIABLE\"",
self.config.remote_scope
));
self.push_line("unreliable.Parent = ReplicatedStorage");
self.push_line("unreliable.Parent = remotes");
self.dedent();
self.push_line("end");
self.push("\n");
}

pub fn push_player_map(&mut self) {
Expand Down
2 changes: 2 additions & 0 deletions zap/src/parser/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl<'src> Converter<'src> {
let (manual_event_loop, ..) = self.boolean_opt("manual_event_loop", false, &config.opts);

let (remote_scope, ..) = self.str_opt("remote_scope", "ZAP", &config.opts);
let (remote_folder, ..) = self.str_opt("remote_folder", "ZAP", &config.opts);

let (server_output, ..) = self.str_opt("server_output", "network/server.lua", &config.opts);
let (client_output, ..) = self.str_opt("client_output", "network/client.lua", &config.opts);
Expand All @@ -119,6 +120,7 @@ impl<'src> Converter<'src> {
manual_event_loop,

remote_scope,
remote_folder,

server_output,
client_output,
Expand Down

0 comments on commit 523d15f

Please sign in to comment.