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