Skip to content

Commit

Permalink
Merge pull request #241 from SigmaThetaTech/feature/get-services-cont…
Browse files Browse the repository at this point in the history
…rollers

Feature/get services controllers
  • Loading branch information
Sleitnick committed Feb 4, 2024
2 parents 65311cb + 83f53ca commit 20d5158
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Aftman
uses: ok-nick/setup-aftman@v0
uses: ok-nick/setup-aftman@v0.4.2
- name: Lint
run: |
selene ./src
Expand All @@ -29,5 +29,5 @@ jobs:
- uses: JohnnyMorganz/stylua-action@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: v0.19.1
version: v0.20.0
args: --check ./src
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Aftman
uses: ok-nick/setup-aftman@v0
uses: ok-nick/setup-aftman@v0.4.2
- name: Publish release to Wally
shell: bash
env:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.7.0
- Adds `Knit.GetServices()` function server-side
- Adds `Knit.GetControllers()` function client-side
- Freezes `services`/`controllers` tables so that they can be safely returned in the functions listed above.
- Update GitHub workflow dependencies

## 1.6.0

- Add support for UnreliableRemoteEvents (using `Knit.CreateUnreliableSignal()` on server)
Expand Down
2 changes: 1 addition & 1 deletion docs/gettingstarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Installing Knit is very simple. Just drop the module into ReplicatedStorage. Kni

**Rojo/Wally workflow:**

- Add Knit to your `wally.toml` dependency list (e.g. `Knit = "sleitnick/knit@^1.6"`)
- Add Knit to your `wally.toml` dependency list (e.g. `Knit = "sleitnick/knit@^1.7"`)
- Require Knit like any other module grabbed from Wally

:::note Wally
Expand Down
11 changes: 11 additions & 0 deletions src/KnitClient.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ function KnitClient.CreateController(controllerDef: ControllerDef): Controller
assert(type(controllerDef.Name) == "string", `Controller.Name must be a string; got {type(controllerDef.Name)}`)
assert(#controllerDef.Name > 0, "Controller.Name must be a non-empty string")
assert(not DoesControllerExist(controllerDef.Name), `Controller {controllerDef.Name} already exists`)
assert(not started, `Controllers cannot be created after calling "Knit.Start()"`)
local controller = controllerDef :: Controller
controllers[controller.Name] = controller
return controller
Expand Down Expand Up @@ -290,6 +291,14 @@ function KnitClient.GetController(controllerName: string): Controller
error(`Could not find controller "{controllerName}". Check to verify a controller with this name exists.`, 2)
end

--[=[
Gets a table of all controllers.
]=]
function KnitClient.GetControllers(): { [string]: Controller }
assert(started, "Cannot call GetControllers until Knit has been started")
return controllers
end

--[=[
@return Promise
Starts Knit. Should only be called once per client.
Expand All @@ -314,6 +323,8 @@ function KnitClient.Start(options: KnitOptions?)

started = true

table.freeze(controllers)

if options == nil then
selectedOptions = defaultOptions
else
Expand Down
11 changes: 11 additions & 0 deletions src/KnitServer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ function KnitServer.CreateService(serviceDef: ServiceDef): Service
assert(type(serviceDef.Name) == "string", `Service.Name must be a string; got {type(serviceDef.Name)}`)
assert(#serviceDef.Name > 0, "Service.Name must be a non-empty string")
assert(not DoesServiceExist(serviceDef.Name), `Service "{serviceDef.Name}" already exists`)
assert(not started, `Services cannot be created after calling "Knit.Start()"`)
local service = serviceDef
service.KnitComm = ServerComm.new(knitRepServiceFolder, serviceDef.Name)
if type(service.Client) ~= "table" then
Expand Down Expand Up @@ -239,6 +240,14 @@ function KnitServer.GetService(serviceName: string): Service
return assert(services[serviceName], `Could not find service "{serviceName}"`) :: Service
end

--[=[
Gets a table of all services.
]=]
function KnitServer.GetServices(): { [string]: Service }
assert(started, "Cannot call GetServices until Knit has been started")
return services
end

--[=[
@return SIGNAL_MARKER
Returns a marker that will transform the current key into
Expand Down Expand Up @@ -364,6 +373,8 @@ function KnitServer.Start(options: KnitOptions?)

started = true

table.freeze(services)

if options == nil then
selectedOptions = defaultOptions
else
Expand Down
2 changes: 1 addition & 1 deletion src/wally.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sleitnick/knit"
description = "Knit is a lightweight game framework"
version = "1.6.0"
version = "1.7.0"
license = "MIT"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"
Expand Down

0 comments on commit 20d5158

Please sign in to comment.