Skip to content

Commit

Permalink
Update 0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMidnightOfficial committed Dec 30, 2022
1 parent 67c1773 commit ce99a97
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.2.2
- There is now a Promise version of some Functions.

## 1.4
- Now Converting rbxl to rbxm

Expand Down
34 changes: 34 additions & 0 deletions src/CrystalClient.lua
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,40 @@ function CrystalClient.CreateController(controllerDef: ControllerDef): Controlle
return controller
end

--[=[
Creates a new controller. (PROMISE)
:::caution
Controllers must be created _before_ calling `Crystal.Start()`.
:::
```lua
-- Create a controller
local MyController = Crystal.CreateControllerPromise {
Name = "MyController",
}
function MyController:CrystalStart()
print("MyController started")
end
function MyController:CrystalInit()
print("MyController initialized")
end
```
]=]
function CrystalClient.CreateControllerPromise(controllerDef: ControllerDef): Controller
return Promise.new(function(resolve)
assert(type(controllerDef) == "table", "Controller must be a table; got " .. type(controllerDef))
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")
local controller = controllerDef :: Controller
controllers[controller.Name] = controller
resolve(controller)
end)
end



--[=[
Requires all the modules that are children of the given parent with an optional affix. This is an easy
Expand Down
52 changes: 52 additions & 0 deletions src/CrystalServer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,58 @@ function CrystalServer.CreateService(serviceDef: ServiceDef): Service
return service
end

--[=[
Constructs a new service. (PROMISE)
:::caution
Services must be created _before_ calling `Crystal.Start()`.
:::
```lua
-- Create a service
local MyService = Crystal.CreateServicePromise {
Name = "MyService",
Client = {},
}
-- Expose a ToAllCaps remote function to the clients
function MyService.Client:ToAllCaps(player, msg)
return msg:upper()
end
-- Crystal will call CrystalStart after all services have been initialized
function MyService:CrystalStart()
print("MyService started")
end
-- Crystal will call CrystalInit when Crystal is first started
function MyService:CrystalInit()
print("MyService initialize")
end
```
]=]
function CrystalServer.CreateServicePromise(serviceDef: ServiceDef): Service
return Promise.new(function(resolve)
assert(type(serviceDef) == "table", "Service must be a table; got " .. type(serviceDef))
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")
local service = serviceDef
service.CrystalComm = ServerComm.new(CrystalRepServiceFolder, serviceDef.Name)
if type(service.Client) ~= "table" then
service.Client = {Server = service}
else
if service.Client.Server ~= service then
service.Client.Server = service
end
end
services[service.Name] = service
resolve(service)
end)
end





--[=[
Requires all the modules that are children of the given parent with an optional affix. This is an easy
Expand Down

0 comments on commit ce99a97

Please sign in to comment.