chore: refractor
This commit is contained in:
55
ReplicatedStorage/Client/LoadingScreen/init.lua
Normal file
55
ReplicatedStorage/Client/LoadingScreen/init.lua
Normal file
@@ -0,0 +1,55 @@
|
||||
--!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
|
||||
Reference in New Issue
Block a user