Update Component to Modern V2

This commit is contained in:
Clint 2024-06-28 15:50:10 +02:00 committed by GitHub
parent 207dcc009d
commit bf2709874a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
local objectList = require(script.Parent.ObjectList)
local types = require(script.Parent.Types)
local component: types.ComponentClass = {} :: types.ComponentClass
local component = {} :: types.ComponentClass
component["__index"] = component
local module = {}
@ -8,51 +9,18 @@ local module = {}
function module.new(name: string): types.Component
local self = setmetatable({
Name= name,
Buttons = {
Active = {},
Stored = {},
},
Buttons = objectList.new(),
_ = {
UpdateCallbacks = {},
},
}, component)
self.Buttons.Parent = self
return self
end
--[[ Buttons ]]
function component:BuildButtons()
for _, button: types.Button in self.Buttons.Stored do
button:Build(self)
end
end
function component:AddButton(button: types.Button)
self.Buttons.Stored[button.Name] = button
end
function component:CloseAllButtons()
for _, button in self.Buttons.Active do
button:Close()
end
self.Buttons.Active = {}
end
function component:RemoveButtons()
self:CloseAllButtons()
for _, button in self.Buttons.Stored do
button:Remove()
end
self.Buttons.Stored = {}
end
--
function component:OnBuild(callback: (self: types.Component) -> ()): ()
self._.OnBuild = callback
end
@ -80,6 +48,16 @@ function component:Build(parent: types.Page): ()
if self._.OnBuild then
self._.OnBuild(self)
end
self._.Status = "Built"
end
function component:GetStatus(): "Built" | "Stored"
return self._.Status
end
function component:StatusIs(status: "Built" | "Stored")
return status == self._.Status
end
function component:Update(command: string, parameters: {}?): ()
@ -111,21 +89,23 @@ function component:Close(): ()
end
function component:Clean(): ()
self:CloseAllButtons()
self.Buttons:CleanAll()
if self.Container then
self.Container:Remove()
end
self._.Status = "Stored"
end
function component:Remove(): ()
self:Clean()
self:RemoveButtons()
self.Buttons:RemoveAll()
if self.Frame then
self.Frame:Destroy()
end
end
return module
return module