CleanableObject Interface Type

This commit is contained in:
ClintUNI 2024-07-09 02:48:37 +02:00
parent c4e9020157
commit eb61666031
2 changed files with 9 additions and 140 deletions

View file

@ -5,42 +5,9 @@ local trove = require(replicated.Modules.Utility.Trove)
-- --
--[[ UIObjects testing]]
export type DraggableClass = {
Parent: Page | Component,
Name: string,
DragButton: GuiButton,
DragEvent: signal.Signal<string, Enum.UserInputType, Enum.UserInputState, {Vector2}?, number?, number?>,
_: {
Status: "Stored" | "Built",
IsDragging: boolean,
DragStartTime: number,
OnBuild: (self: Draggable) -> ()?,
},
OnBuild: (self: Draggable, callback: (self: Draggable) -> ()) -> (),
Build: (self: Draggable, parent: Page | Component) -> (),
IsDragging: (self: Draggable) -> (boolean),
_DragStart: (self: Draggable) -> (),
_DragStop: (self: Draggable) -> (),
_MobileDrag: (self: Draggable, touchPositions: {Vector2}, scale: number, velocity: number, state: Enum.UserInputState) -> (),
Clean: (self: Draggable) -> (),
Destroy: (self: Draggable) -> (),
}
export type Draggable = typeof(setmetatable({} :: DraggableClass, {}))
--[[ == Template == ]] --[[ == Template == ]]
export type TemplateClass<Object, MethodOptions, Parameters> = { type TemplateClass<Object, MethodOptions, Parameters> = {
Files: { Files: {
[string]: (self: Object, parameters: {}?) -> () [string]: (self: Object, parameters: {}?) -> ()
}, },
@ -100,6 +67,11 @@ type BuildableObject<Self, Parent> = {
StatusIs: (self: Self, status: "Stored" | "Built") -> (boolean), StatusIs: (self: Self, status: "Stored" | "Built") -> (boolean),
} }
type CleanableObject<Self> = {
Clean: (self: Self) -> (),
Remove: (self: Self) -> (),
}
type RenderableObject<Self> = { type RenderableObject<Self> = {
_: { _: {
OnOpen: (self: Self) -> ()?, OnOpen: (self: Self) -> ()?,
@ -165,10 +137,7 @@ export type ComponentClass = {
OnUpdate: (self: Component, command: string, callback: (self: Component) -> ()) -> (), OnUpdate: (self: Component, command: string, callback: (self: Component) -> ()) -> (),
Update: (self: Component, command: string, parameters: {}?) -> (), Update: (self: Component, command: string, parameters: {}?) -> (),
} & BuildableObject<Component, Page> & CleanableObject<Component> & RenderableObject<Component>
Clean: (self: Component) -> (),
Remove: (self: Component) -> (),
} & BuildableObject<Component, Page> & RenderableObject<Component>
export type Component = typeof(setmetatable({} :: ComponentClass, {})) export type Component = typeof(setmetatable({} :: ComponentClass, {}))
@ -184,11 +153,8 @@ export type PageClass = {
Buttons: ObjectList<Button, Page>, Buttons: ObjectList<Button, Page>,
Components: ObjectList<Component, Page>, Components: ObjectList<Component, Page>,
Clean: (self: Page) -> (),
Remove: (self: Page) -> (),
GetManager: (self: Window) -> (Manager), GetManager: (self: Window) -> (Manager),
} & BuildableObject<Page, Window> & RenderableObject<Page> } & BuildableObject<Page, Window> & CleanableObject<Page> & RenderableObject<Page>
export type Page = typeof(setmetatable({} :: PageClass, {})) export type Page = typeof(setmetatable({} :: PageClass, {}))
@ -204,10 +170,7 @@ export type WindowClass = {
PageOpened: signal.Signal<Page, boolean>, PageOpened: signal.Signal<Page, boolean>,
PageClosed: signal.Signal<Page, boolean>, PageClosed: signal.Signal<Page, boolean>,
}, },
} & BuildableObject<Window, Manager> & CleanableObject<Window> & RenderableObject<Window>
Clean: (self: Window) -> (),
Remove: (self: Window) -> (),
} & BuildableObject<Window, Manager> & RenderableObject<Window>
export type Window = typeof(setmetatable({} :: WindowClass, {})) export type Window = typeof(setmetatable({} :: WindowClass, {}))

View file

@ -1,94 +0,0 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local uis = game:GetService("UserInputService")
local types = require(ReplicatedStorage.Modules.Managers.UIManager.Types)
local Signal = require(ReplicatedStorage.Modules.Utility.Signal)
local module = {}
local draggable: types.DraggableClass = {} :: types.DraggableClass
draggable["__index"] = draggable
function module.new(name: string): types.Draggable
local self = setmetatable({
Name = name,
DragEvent = Signal.new(),
_ = {
IsDragging = false,
DragStartTime = 0,
},
}, draggable)
return self
end
--[[ Draggable ]]
--[[
Use TouchSwipe for mobile, and MouseButton1Down with MouseButton1Up for PC
]]
function draggable:OnBuild(callback: (self: types.Draggable) -> ())
self._.OnBuild = callback
end
function draggable:Build(parent: types.Page | types.Component)
self.Parent = parent
if self._.OnBuild then
self._.OnBuild(self)
end
if self.DragButton then
if uis.MouseEnabled then
self.Parent.Container:ConnectMethod(self.DragButton.MouseButton1Down, "_DragStart", self, {})
self.Parent.Container:ConnectMethod(self.DragButton.MouseButton1Up, "_DragStop", self, {})
else
self.Parent.Container:Connect(self.DragButton.TouchPan, function(touchPositions: {Vector2}, scale: number, velocity: number, state: Enum.UserInputState)
self:_MobileDrag(touchPositions, scale, velocity, state)
end)
end
end
end
function draggable:IsDragging(): boolean
return self._.IsDragging
end
function draggable:_DragStart()
if self._.IsDragging then
return
end
self._.IsDragging = true
self._.DragStartTime = os.clock()
self.DragEvent:Fire(Enum.UserInputType.Touch, true)
end
function draggable:_DragStop()
self._.IsDragging = false
self.DragEvent:Fire(Enum.UserInputType.Touch, false)
end
function draggable:_MobileDrag(touchPositions: {Vector2}, scale: number, velocity: number, state: Enum.UserInputState)
if self._.IsDragging and state == Enum.UserInputState.Begin then
return
end
self._.IsDragging = state == Enum.UserInputState.Begin
self._.DragStartTime = self._.IsDragging and os.clock() or 0
self.DragEvent:Fire(Enum.UserInputType.Touch, state, touchPositions, scale, velocity)
end
function draggable:Clean()
self.DragEvent:DisconnectAll()
end
function draggable:Destroy()
self:Clean()
setmetatable(getmetatable(self), nil)
end
return module