diff --git a/docs/.vitepress/components/Editor.vue b/docs/.vitepress/components/Editor.vue index 0ececd62..2be1d228 100644 --- a/docs/.vitepress/components/Editor.vue +++ b/docs/.vitepress/components/Editor.vue @@ -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}"`); @@ -161,7 +161,9 @@ const beforeMount = (monaco: Monaco) => { write_checks: Operators, manual_event_loop: Operators, + remote_scope: [], + remote_folder: [], server_output: [], client_output: [], diff --git a/docs/config/options.md b/docs/config/options.md index f94478b0..a5ead41e 100644 --- a/docs/config/options.md +++ b/docs/config/options.md @@ -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 + + + + +The generated remotes will be in `ReplicatedStorage -> ZAP`. + + +### Example + + + + +The generated remotes be in `ReplicatedStorage -> CHARACTER` ## `casing` diff --git a/zap/src/config.rs b/zap/src/config.rs index 49e16225..62485f84 100644 --- a/zap/src/config.rs +++ b/zap/src/config.rs @@ -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, diff --git a/zap/src/output/luau/client.rs b/zap/src/output/luau/client.rs index 022ec358..a6703919 100644 --- a/zap/src/output/luau/client.rs +++ b/zap/src/output/luau/client.rs @@ -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"); diff --git a/zap/src/output/luau/server.rs b/zap/src/output/luau/server.rs index abed0d8f..1d18f24a 100644 --- a/zap/src/output/luau/server.rs +++ b/zap/src/output/luau/server.rs @@ -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"); @@ -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) { diff --git a/zap/src/parser/convert.rs b/zap/src/parser/convert.rs index 1fbb0b15..cfa78577 100644 --- a/zap/src/parser/convert.rs +++ b/zap/src/parser/convert.rs @@ -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); @@ -119,6 +120,7 @@ impl<'src> Converter<'src> { manual_event_loop, remote_scope, + remote_folder, server_output, client_output,