56 lines
1.3 KiB
Lua
56 lines
1.3 KiB
Lua
--!native
|
|
--!optimize 2
|
|
|
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
local Roact = require(ReplicatedStorage.Packages.roact)
|
|
local Players = game:GetService("Players")
|
|
|
|
local App = require(script.App)
|
|
|
|
local LoadingScreen = {}
|
|
|
|
function LoadingScreen.mount(target: Instance?)
|
|
local playerGui = target or Players.LocalPlayer:WaitForChild("PlayerGui")
|
|
local statusBinding, setStatus = Roact.createBinding("Loading...")
|
|
local detailBinding, setDetail = Roact.createBinding("Preparing client")
|
|
local progressBinding, setProgress = Roact.createBinding(0)
|
|
local visibleBinding, setVisible = Roact.createBinding(true)
|
|
|
|
local handle = Roact.mount(Roact.createElement(App, {
|
|
status = statusBinding,
|
|
detail = detailBinding,
|
|
progress = progressBinding,
|
|
visible = visibleBinding,
|
|
}), playerGui, "RoactLoadingScreen")
|
|
|
|
local closed = false
|
|
local function close()
|
|
if closed then
|
|
return
|
|
end
|
|
closed = true
|
|
setVisible(false)
|
|
Roact.unmount(handle)
|
|
handle = nil
|
|
end
|
|
|
|
return {
|
|
setStatus = function(text: string)
|
|
setStatus(text)
|
|
end,
|
|
setDetail = function(text: string)
|
|
setDetail(text)
|
|
end,
|
|
setProgress = function(value: number)
|
|
setProgress(math.clamp(value or 0, 0, 1))
|
|
end,
|
|
show = function()
|
|
setVisible(true)
|
|
end,
|
|
hide = close,
|
|
close = close,
|
|
}
|
|
end
|
|
|
|
return LoadingScreen
|