diff --git a/src/create.luau b/src/create.luau index 736ed26..d534ebe 100644 --- a/src/create.luau +++ b/src/create.luau @@ -2,6 +2,7 @@ if not game then script = require "test/relative-string" end local typeof = game and typeof or require "test/mock".typeof:: never local Instance = game and Instance or require "test/mock".Instance :: never +local types = require(script.Parent.types) local throw = require(script.Parent.throw) local defaults = require(script.Parent.defaults) local apply = require(script.Parent.apply) @@ -45,30 +46,30 @@ end type Props = { [any]: any } return (create :: any) :: ( (T & Instance) -> (Props) -> T ) & -( ("Folder") -> (Props) -> Folder ) & -( ("BillboardGui") -> (Props) -> BillboardGui ) & -( ("CanvasGroup") -> (Props) -> CanvasGroup ) & -( ("Frame") -> (Props) -> Frame ) & -( ("ImageButton") -> (Props) -> ImageButton ) & -( ("ImageLabel") -> (Props) -> ImageLabel ) & -( ("ScreenGui") -> (Props) -> ScreenGui ) & -( ("ScrollingFrame") -> (Props) -> ScrollingFrame ) & -( ("SurfaceGui") -> (Props) -> SurfaceGui ) & -( ("TextBox") -> (Props) -> TextBox ) & -( ("TextButton") -> (Props) -> TextButton ) & -( ("TextLabel") -> (Props) -> TextLabel ) & -( ("UIAspectRatioConstraint") -> (Props) -> UIAspectRatioConstraint ) & -( ("UICorner") -> (Props) -> UICorner ) & -( ("UIGradient") -> (Props) -> UIGradient ) & -( ("UIGridLayout") -> (Props) -> UIGridLayout ) & -( ("UIListLayout") -> (Props) -> UIListLayout ) & -( ("UIPadding") -> (Props) -> UIPadding ) & -( ("UIPageLayout") -> (Props) -> UIPageLayout ) & -( ("UIScale") -> (Props) -> UIScale ) & -( ("UISizeConstraint") -> (Props) -> UISizeConstraint ) & -( ("UIStroke") -> (Props) -> UIStroke ) & -( ("UITableLayout") -> (Props) -> UITableLayout ) & -( ("UITextSizeConstraint") -> (Props) -> UITextSizeConstraint ) & -( ("VideoFrame") -> (Props) -> VideoFrame ) & -( ("ViewportFrame") -> (Props) -> ViewportFrame ) & +( ("Folder") -> (types.FolderProps) -> Folder ) & +( ("BillboardGui") -> (types.BillboardGuiProps) -> BillboardGui ) & +( ("CanvasGroup") -> (types.CanvasGroupProps) -> CanvasGroup ) & +( ("Frame") -> (types.FrameProps) -> Frame ) & +( ("ImageButton") -> (types.ImageButtonProps) -> ImageButton ) & +( ("ImageLabel") -> (types.ImageLabelProps) -> ImageLabel ) & +( ("ScreenGui") -> (types.ScreenGuiProps) -> ScreenGui ) & +( ("ScrollingFrame") -> (types.ScrollingFrameProps) -> ScrollingFrame ) & +( ("SurfaceGui") -> (types.SurfaceGuiProps) -> SurfaceGui ) & +( ("TextBox") -> (types.TextBoxProps) -> TextBox ) & +( ("TextButton") -> (types.TextButtonProps) -> TextButton ) & +( ("TextLabel") -> (types.TextLabelProps) -> TextLabel ) & +( ("UIAspectRatioConstraint") -> (types.UIAspectRatioConstraintProps) -> UIAspectRatioConstraint ) & +( ("UICorner") -> (types.UICornerProps) -> UICorner ) & +( ("UIGradient") -> (types.UIGradientProps) -> UIGradient ) & +( ("UIGridLayout") -> (types.UIGridLayoutProps) -> UIGridLayout ) & +( ("UIListLayout") -> (types.UIListLayoutProps) -> UIListLayout ) & +( ("UIPadding") -> (types.UIPaddingProps) -> UIPadding ) & +( ("UIPageLayout") -> (types.UIPageLayoutProps) -> UIPageLayout ) & +( ("UIScale") -> (types.UIScaleProps) -> UIScale ) & +( ("UISizeConstraint") -> (types.UISizeConstraintProps) -> UISizeConstraint ) & +( ("UIStroke") -> (types.UIStrokeProps) -> UIStroke ) & +( ("UITableLayout") -> (types.UITableLayoutProps) -> UITableLayout ) & +( ("UITextSizeConstraint") -> (types.UITextSizeConstraintProps) -> UITextSizeConstraint ) & +( ("VideoFrame") -> (types.VideoFrameProps) -> VideoFrame ) & +( ("ViewportFrame") -> (types.ViewportFrameProps) -> ViewportFrame ) & ( (string) -> (Props) -> Instance ) diff --git a/src/types.luau b/src/types.luau new file mode 100644 index 0000000..0d182e5 --- /dev/null +++ b/src/types.luau @@ -0,0 +1,357 @@ +if not game then + script = require("test/relative-string") +end + +type Prop = T? | () -> T? + +-- Creatable instances + +export type FolderProps = InstanceProps + +export type BillboardGuiProps = LayerCollectorProps & { + Active: Prop, + Adornee: Prop, + AlwaysOnTop: Prop, + Brightness: Prop, + ClipsDescendants: Prop, + DistanceLowerLimit: Prop, + DistanceStep: Prop, + DistanceUpperLimit: Prop, + ExtentsOffset: Prop, + ExtentsOffsetWorldSpace: Prop, + LightInfluence: Prop, + MaxDistance: Prop, + PlayerToHideFrom: Prop, + Size: Prop, + SizeOffset: Prop, + StudsOffset: Prop, + StudsOffsetWorldSpace: Prop, +} + +export type CanvasGroupProps = GuiObjectProps & { + GroupColor3: Prop, + GroupTransparency: Prop, +} + +export type FrameProps = GuiObjectProps & { + Style: Prop, +} + +export type ImageButtonProps = GuiButtonProps & ImageProps & { + HoverImage: Prop, + PressedImage: Prop, +} + +export type ImageLabelProps = GuiObjectProps & ImageProps + +export type ScreenGuiProps = LayerCollectorProps & { + ClipToDeviceSafeArea: Prop, + DisplayOrder: Prop, + IgnoreGuiInset: Prop, + SafeAreaCompatibilityMode: Prop, + ScreenInsets: Prop, +} + +export type ScrollingFrameProps = GuiObjectProps & { + AutomaticCanvasSize: Prop, + BottomImage: Prop, + CanvasPosition: Prop, + CanvasSize: Prop, + ElasticBehavior: Prop, + HorizontalScrollBarInset: Prop, + MidImage: Prop, + ScrollBarImageColor3: Prop, + ScrollBarImageTransparency: Prop, + ScrollBarThickness: Prop, + ScrollingDirection: Prop, + ScrollingEnabled: Prop, + TopImage: Prop, + VerticalScrollBarInset: Prop, + VerticalScrollBarPosition: Prop, +} + +export type SurfaceGuiProps = LayerCollectorProps & { + Active: Prop, + Adornee: Prop, + AlwaysOnTop: Prop, + Brightness: Prop, + CanvasSize: Prop, + ClipsDescendants: Prop, + Face: Prop, + LightInfluence: Prop, + MaxDistance: Prop, + PixelsPerStud: Prop, + SizingMode: Prop, + ToolPunchThroughDistance: Prop, + ZOffset: Prop, +} + +export type TextLabelProps = GuiObjectProps & TextProps + +export type TextButtonProps = GuiButtonProps & TextProps + +export type TextBoxProps = GuiObjectProps & TextProps & { + ClearTextOnFocus: Prop, + CursorPosition: Prop, + MultiLine: Prop, + PlaceholderColor3: Prop, + PlaceholderText: Prop, + SelectionStart: Prop, + ShowNativeInput: Prop, + TextEditable: Prop, + + FocusLost: ((enterPressed: boolean, inputThatCausedFocusLoss: InputObject) -> ())?, + Focused: (() -> ())?, + ReturnPressedFromOnScreenKeyboard: (() -> ())?, +} + +export type VideoFrameProps = GuiObjectProps & { + Looped: Prop, + Playing: Prop, + TimePosition: Prop, + Video: Prop, + Volume: Prop, + + DidLoop: ((video: string) -> ())?, + Ended: ((video: string) -> ())?, + Loaded: ((video: string) -> ())?, + Paused: ((video: string) -> ())?, + Played: ((video: string) -> ())?, +} + +export type ViewportFrameProps = GuiObjectProps & { + Ambient: Prop, + CurrentCamera: Prop, + ImageColor3: Prop, + ImageTransparency: Prop, + LightColor: Prop, + LightDirection: Prop, +} + +-- Creatable UI modifiers + +export type UIAspectRatioConstraintProps = InstanceProps & { + AspectRatio: Prop, + AspectType: Prop, + DominantAxis: Prop, +} + +export type UICornerProps = InstanceProps & { + CornerRadius: Prop, +} + +export type UIGradientProps = InstanceProps & { + Color: Prop, + Enabled: Prop, + Offset: Prop, + Rotation: Prop, + Transparency: Prop, +} + +export type UIGridLayoutProps = UIGridStyleLayoutProps & { + CellPadding: Prop, + CellSize: Prop, + FillDirectionMaxCells: Prop, + StartCorner: Prop, +} + +export type UIListLayoutProps = UIGridStyleLayoutProps & { + Padding: Prop, +} + +export type UIPaddingProps = InstanceProps & { + PaddingBottom: Prop, + PaddingLeft: Prop, + PaddingRight: Prop, + PaddingTop: Prop, +} + +export type UIPageLayoutProps = UIGridStyleLayoutProps & { + Animated: Prop, + Circular: Prop, + EasingDirection: Prop, + EasingStyle: Prop, + GamepadInputEnabled: Prop, + Padding: Prop, + ScrollWheelInputEnabled: Prop, + TouchInputEnabled: Prop, + TweenTime: Prop, + + PageEnter: ((page: any) -> ())?, + PageLeave: ((page: any) -> ())?, + Stopped: ((currentPage: any) -> ())?, +} + +export type UIScaleProps = InstanceProps & { + Scale: Prop, +} + +export type UISizeConstraintProps = InstanceProps & { + MaxSize: Prop, + MinSize: Prop, +} + +export type UIStrokeProps = InstanceProps & { + ApplyStrokeMode: Prop, + Color: Prop, + Enabled: Prop, + LineJoinMode: Prop, + Thickness: Prop, + Transparency: Prop, +} + +export type UITableLayoutProps = UIGridStyleLayoutProps & { + FillEmptySpaceColumns: Prop, + FillEmptySpaceRows: Prop, + MajorAxis: Prop, + Padding: Prop, +} + +export type UITextSizeConstraintProps = InstanceProps & { + MaxTextSize: Prop, + MinTextSize: Prop, +} + +-- Helpers + +type ImageProps = { + Image: Prop, + ImageColor3: Prop, + ImageRectOffset: Prop, + ImageRectSize: Prop, + ImageTransparency: Prop, + ResampleMode: Prop, + ScaleType: Prop, + SliceCenter: Prop, + SliceScale: Prop, + TileSize: Prop, +} + +type TextProps = { + Font: Prop, + FontFace: Prop, + LineHeight: Prop, + MaxVisibleGraphemes: Prop, + RichText: Prop, + Text: Prop, + TextColor3: Prop, + TextDirection: Prop, + TextScaled: Prop, + TextSize: Prop, + TextStrokeColor3: Prop, + TextStrokeTransparency: Prop, + TextTransparency: Prop, + TextTruncate: Prop, + TextWrapped: Prop, + TextXAlignment: Prop, + TextYAlignment: Prop, +} + +-- Base instance types + +type InstanceProps = { + [any]: any, + + Archivable: Prop, + Name: Prop, + Parent: Prop, + + AncestryChanged: ((child: Instance, parent: Instance?) -> ())?, + AttributeChanged: ((attribute: string) -> ())?, + Changed: ((property: string) -> ())?, + ChildAdded: ((child: Instance) -> ())?, + ChildRemoved: ((child: Instance) -> ())?, + DescendantAdded: ((descendant: Instance) -> ())?, + DescendantRemoving: ((descendant: Instance) -> ())?, + Destroying: (() -> ())?, +} + +type GuiBase2dProps = InstanceProps & { + AutoLocalize: Prop, + Localize: Prop, + RootLocalizationTable: Prop, + SelectionBehaviorDown: Prop, + SelectionBehaviorLeft: Prop, + SelectionBehaviorRight: Prop, + SelectionBehaviorUp: Prop, + SelectionGroup: Prop, + + SelectionChanged: ((amISelected: boolean, previousSelection: GuiObject, newSelection: GuiObject) -> ())?, +} + +type UIGridStyleLayoutProps = InstanceProps & { + FillDirection: Prop, + HorizontalAlignment: Prop, + SortOrder: Prop, + VerticalAlignment: Prop, +} + +type GuiObjectProps = GuiBase2dProps & { + Active: Prop, + AnchorPoint: Prop, + AutomaticSize: Prop, + BackgroundColor3: Prop, + BackgroundTransparency: Prop, + BorderColor3: Prop, + BorderMode: Prop, + BorderSizePixel: Prop, + ClipsDescendants: Prop, + Interactable: Prop, + LayoutOrder: Prop, + NextSelectionDown: Prop, + NextSelectionLeft: Prop, + NextSelectionRight: Prop, + NextSelectionUp: Prop, + Position: Prop, + Rotation: Prop, + Selectable: Prop, + SelectionImageObject: Prop, + SelectionOrder: Prop, + Size: Prop, + SizeConstraint: Prop, + Visible: Prop, + ZIndex: Prop, + + InputBegan: ((input: InputObject) -> ())?, + InputChanged: ((input: InputObject) -> ())?, + InputEnded: ((input: InputObject) -> ())?, + MouseEnter: ((x: number, y: number) -> ())?, + MouseLeave: ((x: number, y: number) -> ())?, + MouseMoved: ((x: number, y: number) -> ())?, + MouseWheelBackward: ((x: number, y: number) -> ())?, + MouseWheelForward: ((x: number, y: number) -> ())?, + SelectionGained: (() -> ())?, + SelectionLost: (() -> ())?, + TouchLongPress: ((touchPositions: { Vector2 }, state: Enum.UserInputState) -> ())?, + TouchPan: (( + touchPositions: { Vector2 }, + totalTranslation: Vector2, + velocity: Vector2, + state: Enum.UserInputState + ) -> ())?, + TouchPinch: ((touchPositions: { Vector2 }, scale: number, velocity: number, state: Enum.UserInputState) -> ())?, + TouchRotate: ((touchPositions: { Vector2 }, rotation: number, velocity: number, state: Enum.UserInputState) -> ())?, + TouchSwipe: ((swipeDirection: Enum.SwipeDirection, numberOfTouches: number) -> ())?, + TouchTap: ((touchPositions: { Vector2 }) -> ())?, +} + +type LayerCollectorProps = GuiBase2dProps & { + Enabled: Prop, + ResetOnSpawn: Prop, + ZIndexBehavior: Prop, +} + +type GuiButtonProps = GuiObjectProps & { + AutoButtonColor: Prop, + Modal: Prop, + Selected: Prop, + Style: Prop, + + Activated: ((input: InputObject, clickCount: number) -> ())?, + MouseButton1Click: (() -> ())?, + MouseButton1Down: ((x: number, y: number) -> ())?, + MouseButton1Up: ((x: number, y: number) -> ())?, + MouseButton2Click: (() -> ())?, + MouseButton2Down: ((x: number, y: number) -> ())?, + MouseButton2Up: ((x: number, y: number) -> ())?, +}