From 1ab3819c9666b4481cd3e64ad47a0c392a14bf6f Mon Sep 17 00:00:00 2001 From: James <119134081+2jammers@users.noreply.github.com> Date: Fri, 8 Nov 2024 18:37:23 -0600 Subject: [PATCH] push structure changes --- dev.project.json | 38 +--- .../spring.luau => Animation/Spring.luau} | 0 src/Animation/Tween.luau | 0 src/Constructors/new.luau | 81 -------- src/Instances/Default.luau | 186 ++++++++++++++++++ src/Instances/New.luau | 70 +++++++ src/{Functions => Instances}/Update.luau | 27 +-- src/Keys/Attributes.luau | 10 - src/Keys/Changes.luau | 12 -- src/Keys/Cleanup.luau | 40 ---- src/Keys/Events.luau | 21 -- src/{Functions => Keys}/Key.luau | 0 src/Keys/List/OnAttributeChange.luau | 0 src/Keys/List/OnChange.luau | 28 +++ src/Keys/List/OnEvent.luau | 29 +++ src/Keys/Ref.luau | 19 -- src/{Functions => Keys}/RegisterKey.luau | 0 src/Keys/Tags.luau | 10 - src/{Functions => Keys}/UnregisterKey.luau | 0 src/Keys/Utility/FindProp.luau | 4 + src/Keys/Utility/Keys.luau | 1 + src/Logs.luau | 3 + .../compute.luau => State/Compute.luau} | 28 +-- .../state.luau => State/Value.luau} | 34 +--- src/Types.luau | 4 - src/init.luau | 48 ++--- tests/{client => Client}/UI.client.luau | 0 .../components/Background.luau | 0 tests/{client => Client}/useTheme.luau | 0 tests/{server => Server}/Test.server.luau | 0 tests/{shared => Shared}/Theme.luau | 0 tests/lighting/Atmosphere.rbxm | Bin 686 -> 0 bytes tests/lighting/Bloom.rbxm | Bin 602 -> 0 bytes tests/lighting/DepthOfField.rbxm | Bin 676 -> 0 bytes tests/lighting/Sky.rbxm | Bin 1126 -> 0 bytes tests/lighting/SunRays.rbxm | Bin 568 -> 0 bytes tests/workspace/Baseplate.rbxm | Bin 2512 -> 0 bytes tests/workspace/Spawn.rbxm | Bin 2716 -> 0 bytes 38 files changed, 367 insertions(+), 326 deletions(-) rename src/{Constructors/spring.luau => Animation/Spring.luau} (100%) create mode 100644 src/Animation/Tween.luau delete mode 100644 src/Constructors/new.luau create mode 100644 src/Instances/Default.luau create mode 100644 src/Instances/New.luau rename src/{Functions => Instances}/Update.luau (50%) delete mode 100644 src/Keys/Attributes.luau delete mode 100644 src/Keys/Changes.luau delete mode 100644 src/Keys/Cleanup.luau delete mode 100644 src/Keys/Events.luau rename src/{Functions => Keys}/Key.luau (100%) create mode 100644 src/Keys/List/OnAttributeChange.luau create mode 100644 src/Keys/List/OnChange.luau create mode 100644 src/Keys/List/OnEvent.luau delete mode 100644 src/Keys/Ref.luau rename src/{Functions => Keys}/RegisterKey.luau (100%) delete mode 100644 src/Keys/Tags.luau rename src/{Functions => Keys}/UnregisterKey.luau (100%) create mode 100644 src/Keys/Utility/FindProp.luau create mode 100644 src/Keys/Utility/Keys.luau create mode 100644 src/Logs.luau rename src/{Constructors/compute.luau => State/Compute.luau} (79%) rename src/{Constructors/state.luau => State/Value.luau} (82%) rename tests/{client => Client}/UI.client.luau (100%) rename tests/{client => Client}/components/Background.luau (100%) rename tests/{client => Client}/useTheme.luau (100%) rename tests/{server => Server}/Test.server.luau (100%) rename tests/{shared => Shared}/Theme.luau (100%) delete mode 100644 tests/lighting/Atmosphere.rbxm delete mode 100644 tests/lighting/Bloom.rbxm delete mode 100644 tests/lighting/DepthOfField.rbxm delete mode 100644 tests/lighting/Sky.rbxm delete mode 100644 tests/lighting/SunRays.rbxm delete mode 100644 tests/workspace/Baseplate.rbxm delete mode 100644 tests/workspace/Spawn.rbxm diff --git a/dev.project.json b/dev.project.json index 9b4b31f..2d94d48 100644 --- a/dev.project.json +++ b/dev.project.json @@ -1,45 +1,17 @@ { - "name": "aegis-dev", + "emitLegacyScripts": false, + "name": "ui-framework", "tree": { "$className": "DataModel", - "Workspace": { - "$path": "tests/workspace" - }, - "Lighting": { - "$path": "tests/lighting", - "$properties": { - "Technology": "Voxel", - "Ambient": { - "Color3": [ - 0.470588, - 0.470588, - 0.470588 - ] - }, - "OutdoorAmbient": { - "Color3": [ - 0.470588, - 0.470588, - 0.470588 - ] - } - } - }, "ReplicatedStorage": { - "$path": "tests/shared", "Packages": { "$path": "Packages", "ui-framework": { "$path": "src" } - } - }, - "ServerScriptService": { - "$path": "tests/server" - }, - "StarterPlayer": { - "StarterPlayerScripts": { - "$path": "tests/client" + }, + "Tests": { + "$path": "tests" } } } diff --git a/src/Constructors/spring.luau b/src/Animation/Spring.luau similarity index 100% rename from src/Constructors/spring.luau rename to src/Animation/Spring.luau diff --git a/src/Animation/Tween.luau b/src/Animation/Tween.luau new file mode 100644 index 0000000..e69de29 diff --git a/src/Constructors/new.luau b/src/Constructors/new.luau deleted file mode 100644 index c081edb..0000000 --- a/src/Constructors/new.luau +++ /dev/null @@ -1,81 +0,0 @@ --- FOLDERS > -local Root = script.Parent.Parent -local Utility = Root.Utility - --- DEPENDENCIES > -local Debugger = require(Utility.Debugger) -local Utils = require(Utility.Utils) -local Types = require(Root.Types) - --- FUNCTIONS > ---[[ - ## `Aegis.new` - A constructor to create new instances. - #### Parameters - - **classOrComponent:** The class name of the instance or the component to create. - - **properties:** A table of properties to be applied to the parent instance. - - **children:** A table of descendant instances to be parented to the parent instance. - #### Returns - - [`Instance`](https://create.roblox.com/docs/reference/engine/classes/Instance) | [`Tutorial`](https://lumin-dev.github.io/Aegis/guide/new-instances) - #### Example - ```luau - local BackgroundComponent = require(path.to.BackgroundComponent) - - local MenuUI = Aegis.new("ScreenGui", { - Name = "MenuUI", - IgnoreGuiInset = true, - Parent = Player:WaitForChild("PlayerGui"), - }, { - Background = Aegis.new(BackgroundComponent, { - Color = Color3.fromRGB(24, 24, 24), - }), - }) - ``` -]] -return function( - classOrComponent: string | Types.Component, - properties: (T & Types.Properties)?, - children: Types.Children? -): Instance - local Component - if type(classOrComponent) == "string" then - local Success, Result = pcall(Instance.new, classOrComponent) -- Create the instance wrapped inside pcall - - if Success then - if properties then - for property, value in properties :: any do - if property == "Parent" then - continue - end - - Utils.ApplyProperty(Result, property, value) - end - - if (properties :: any).Parent then - Utils.ApplyProperty(Result, "Parent", (properties :: any).Parent) - end - end - - if children then - for name, value in children do - value.Parent = Result - value.Name = if type(name) == "string" then name else value.Name - end - end - - Component = Result - else -- If it wasn't successful, error it because instance creation has to be complete. - Debugger.Error("FailedToCreate", classOrComponent, Result) - end - else - if children then - if not properties then - properties = {} :: any - end - (properties :: any).Children = children - end - - Component = classOrComponent(properties :: any) - end - return Component -end diff --git a/src/Instances/Default.luau b/src/Instances/Default.luau new file mode 100644 index 0000000..9e70a0c --- /dev/null +++ b/src/Instances/Default.luau @@ -0,0 +1,186 @@ +-- Stores default properties for common items +-- Forked from Fusion 0.3 +return { + ScreenGui = { + ResetOnSpawn = false, + ZIndexBehavior = Enum.ZIndexBehavior.Sibling + }, + + BillboardGui = { + ResetOnSpawn = false, + ZIndexBehavior = Enum.ZIndexBehavior.Sibling, + Active = true + }, + + SurfaceGui = { + ResetOnSpawn = false, + ZIndexBehavior = Enum.ZIndexBehavior.Sibling, + + SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud, + PixelsPerStud = 50 + }, + + Frame = { + BackgroundColor3 = Color3.new(1, 1, 1), + BorderColor3 = Color3.new(0, 0, 0), + BorderSizePixel = 0 + }, + + ScrollingFrame = { + BackgroundColor3 = Color3.new(1, 1, 1), + BorderColor3 = Color3.new(0, 0, 0), + BorderSizePixel = 0, + + ScrollBarImageColor3 = Color3.new(0, 0, 0) + }, + + TextLabel = { + BackgroundColor3 = Color3.new(1, 1, 1), + BorderColor3 = Color3.new(0, 0, 0), + BorderSizePixel = 0, + + Font = Enum.Font.SourceSans, + Text = "", + TextColor3 = Color3.new(0, 0, 0), + TextSize = 14 + }, + + TextButton = { + BackgroundColor3 = Color3.new(1, 1, 1), + BorderColor3 = Color3.new(0, 0, 0), + BorderSizePixel = 0, + + AutoButtonColor = false, + + Font = Enum.Font.SourceSans, + Text = "", + TextColor3 = Color3.new(0, 0, 0), + TextSize = 14 + }, + + TextBox = { + BackgroundColor3 = Color3.new(1, 1, 1), + BorderColor3 = Color3.new(0, 0, 0), + BorderSizePixel = 0, + + ClearTextOnFocus = false, + + Font = Enum.Font.SourceSans, + Text = "", + TextColor3 = Color3.new(0, 0, 0), + TextSize = 14 + }, + + ImageLabel = { + BackgroundColor3 = Color3.new(1, 1, 1), + BorderColor3 = Color3.new(0, 0, 0), + BorderSizePixel = 0 + }, + + ImageButton = { + BackgroundColor3 = Color3.new(1, 1, 1), + BorderColor3 = Color3.new(0, 0, 0), + BorderSizePixel = 0, + + AutoButtonColor = false + }, + + ViewportFrame = { + BackgroundColor3 = Color3.new(1, 1, 1), + BorderColor3 = Color3.new(0, 0, 0), + BorderSizePixel = 0 + }, + + VideoFrame = { + BackgroundColor3 = Color3.new(1, 1, 1), + BorderColor3 = Color3.new(0, 0, 0), + BorderSizePixel = 0 + }, + + CanvasGroup = { + BackgroundColor3 = Color3.new(1, 1, 1), + BorderColor3 = Color3.new(0, 0, 0), + BorderSizePixel = 0 + }, + + SpawnLocation = { + Duration = 0 + }, + + BoxHandleAdornment = { + ZIndex = 0 + }, + ConeHandleAdornment = { + ZIndex = 0 + }, + CylinderHandleAdornment = { + ZIndex = 0 + }, + ImageHandleAdornment = { + ZIndex = 0 + }, + LineHandleAdornment = { + ZIndex = 0 + }, + SphereHandleAdornment = { + ZIndex = 0 + }, + WireframeHandleAdornment = { + ZIndex = 0 + }, + + Part = { + Anchored = true, + Size = Vector3.one, + FrontSurface = Enum.SurfaceType.Smooth, + BackSurface = Enum.SurfaceType.Smooth, + LeftSurface = Enum.SurfaceType.Smooth, + RightSurface = Enum.SurfaceType.Smooth, + TopSurface = Enum.SurfaceType.Smooth, + BottomSurface = Enum.SurfaceType.Smooth, + }, + + TrussPart = { + Anchored = true, + Size = Vector3.one * 2, + FrontSurface = Enum.SurfaceType.Smooth, + BackSurface = Enum.SurfaceType.Smooth, + LeftSurface = Enum.SurfaceType.Smooth, + RightSurface = Enum.SurfaceType.Smooth, + TopSurface = Enum.SurfaceType.Smooth, + BottomSurface = Enum.SurfaceType.Smooth, + }, + + MeshPart = { + Anchored = true, + Size = Vector3.one, + FrontSurface = Enum.SurfaceType.Smooth, + BackSurface = Enum.SurfaceType.Smooth, + LeftSurface = Enum.SurfaceType.Smooth, + RightSurface = Enum.SurfaceType.Smooth, + TopSurface = Enum.SurfaceType.Smooth, + BottomSurface = Enum.SurfaceType.Smooth, + }, + + CornerWedgePart = { + Anchored = true, + Size = Vector3.one, + FrontSurface = Enum.SurfaceType.Smooth, + BackSurface = Enum.SurfaceType.Smooth, + LeftSurface = Enum.SurfaceType.Smooth, + RightSurface = Enum.SurfaceType.Smooth, + TopSurface = Enum.SurfaceType.Smooth, + BottomSurface = Enum.SurfaceType.Smooth, + }, + + VehicleSeat = { + Anchored = true, + Size = Vector3.one, + FrontSurface = Enum.SurfaceType.Smooth, + BackSurface = Enum.SurfaceType.Smooth, + LeftSurface = Enum.SurfaceType.Smooth, + RightSurface = Enum.SurfaceType.Smooth, + TopSurface = Enum.SurfaceType.Smooth, + BottomSurface = Enum.SurfaceType.Smooth, + }, +} diff --git a/src/Instances/New.luau b/src/Instances/New.luau new file mode 100644 index 0000000..09716db --- /dev/null +++ b/src/Instances/New.luau @@ -0,0 +1,70 @@ +-- Variables +local Root = script.Parent.Parent +local Utility = Root.Utility +local Packages = script.Parent.Parent.Parent.Parent.Packages + +local Debugger = require(Packages.debugger) +local Utils = require(Utility.Utils) +local Types = require(Root.Types) +local Default = require(Root.Instances.Default) + +-- Module + +--[=[ + Creates a new instance or component with the provided children and props. + + [Learn More](https://luminlabsdev.github.io/ui-framework/api/#new) +]=] +return function( + component: string | Types.Component, + properties: (T & Types.Properties)?, + children: Types.Children? +): Instance + local Component + if type(component) == "string" then + local Success, Result = pcall(Instance.new, component) -- Create the instance wrapped inside pcall + + if Success then + if Default[component] then + for prop, value in Default[component] do + (Result :: any)[prop] = value + end + end + + if properties then + for property, value in properties :: any do + if property == "Parent" then + continue + end + + Utils.ApplyProperty(Result, property, value) + end + + if (properties :: any).Parent then + Utils.ApplyProperty(Result, "Parent", (properties :: any).Parent) + end + end + + if children then + for name, value in children do + value.Parent = Result + value.Name = if type(name) == "string" then name else value.Name + end + end + + Component = Result + else -- If it wasn't successful, error it because instance creation has to be complete. + Debugger.Fatal("FailedToCreate", component, Result) + end + else + if children then + if not properties then + properties = {} :: any + end + (properties :: any).Children = children + end + + Component = component(properties :: any) + end + return Component +end diff --git a/src/Functions/Update.luau b/src/Instances/Update.luau similarity index 50% rename from src/Functions/Update.luau rename to src/Instances/Update.luau index 6a62be4..077c8bd 100644 --- a/src/Functions/Update.luau +++ b/src/Instances/Update.luau @@ -1,27 +1,14 @@ --- DEPENDENCIES > +-- Variables local Utils = require(script.Parent.Parent.Utility.Utils) local Types = require(script.Parent.Parent.Types) --- FUNCTIONS > ---[[ - ## `Aegis.Update` - A function to update the passed instance. - #### Parameters - - **instance:** The instance to update the properties of. - - **propertyTable:** A table of properties to be applied to the parent instance. - - **childrenTable:** A table of descendant instances to be parented to the parent instance. - #### Returns - - [`Instance`](https://create.roblox.com/docs/reference/engine/classes/Instance) | [`Tutorial`](https://lumin-dev.github.io/Aegis/guide/updating-instances) - #### Example - ```luau - local UI = PlayerGui:WaitForChild("LoadingUI") +-- Module - Aegis.Update(UI, { - Name = "MenuGUI", - IgnoreGuiInset = true, - }) - ``` -]] +--[=[ + Updates an instance, adding properties or children. + + [Learn More](https://luminlabsdev.github.io/ui-framework/api/#update) +]=] return function(component: Instance, properties: Types.Properties?, children: Types.Children?): Instance if properties then for property, value in properties do diff --git a/src/Keys/Attributes.luau b/src/Keys/Attributes.luau deleted file mode 100644 index 4e2fe8e..0000000 --- a/src/Keys/Attributes.luau +++ /dev/null @@ -1,10 +0,0 @@ --- RETURNING > -return { - KeyName = "Attributes", - ApplyKey = function(instance: Instance, value: { [string]: any }) - for attributeName, val in value do - -- Loop over provided attributes and set it to instance - instance:SetAttribute(attributeName, val) - end - end, -} diff --git a/src/Keys/Changes.luau b/src/Keys/Changes.luau deleted file mode 100644 index 92ab780..0000000 --- a/src/Keys/Changes.luau +++ /dev/null @@ -1,12 +0,0 @@ --- RETURNING > -return { - KeyName = "Changes", - ApplyKey = function(instance: Instance, value: { [string]: () -> () }) - for propertyName, fn in value do - if type(propertyName) == "string" and type(fn) == "function" then - -- Check the types and connect - instance:GetPropertyChangedSignal(propertyName):Connect(fn) - end - end - end, -} diff --git a/src/Keys/Cleanup.luau b/src/Keys/Cleanup.luau deleted file mode 100644 index 1945f18..0000000 --- a/src/Keys/Cleanup.luau +++ /dev/null @@ -1,40 +0,0 @@ --- FOLDERS > -local Utility = script.Parent.Parent.Utility - --- DEPENDENCIES > -local Is = require(Utility.Is) -local Utils = require(Utility.Utils) -local Types = require(script.Parent.Parent.Types) - --- FUNCTIONS > -local function CleanupElement(value: any, type: string) - if Is.AegisConstructor(value) == true then - (value :: Types.Constructor):Destroy() - elseif type == "Instance" then - (value :: Instance):Destroy() - elseif type == "RBXScriptConnection" then - (value :: RBXScriptConnection):Disconnect() - elseif type == "function" then - Utils.Spawn(value) - end -end - --- RETURNING > -return { - KeyName = "Cleanup", - ApplyKey = function(instance: Instance, value: any): () - local Type = typeof(value) - - instance.Destroying:Connect(function(): () - if Type == "table" then - for _, v in value do - CleanupElement(v, Type) - end - - table.clear(value) - else - CleanupElement(value, Type) - end - end) - end, -} diff --git a/src/Keys/Events.luau b/src/Keys/Events.luau deleted file mode 100644 index 03761d0..0000000 --- a/src/Keys/Events.luau +++ /dev/null @@ -1,21 +0,0 @@ --- DEPENDENCIES > -local Debugger = require(script.Parent.Parent.Utility.Debugger) - --- RETURNING > -return { - KeyName = "Events", - ApplyKey = function(instance: Instance, value: { [string]: (...any) -> () }) - local CurrentType: string -- A variable so that same types do not take extra memory - - for eventName, fn in value do - CurrentType = typeof((instance :: any)[eventName]) - if CurrentType == "RBXScriptSignal" then -- Check type - (instance :: any)[eventName]:Connect(function(...: any) - fn(unpack({ ... })) - end) - else - Debugger.Warn("TypeMismatch", "RBXScriptSignal", CurrentType) -- else just warn it - end - end - end, -} diff --git a/src/Functions/Key.luau b/src/Keys/Key.luau similarity index 100% rename from src/Functions/Key.luau rename to src/Keys/Key.luau diff --git a/src/Keys/List/OnAttributeChange.luau b/src/Keys/List/OnAttributeChange.luau new file mode 100644 index 0000000..e69de29 diff --git a/src/Keys/List/OnChange.luau b/src/Keys/List/OnChange.luau new file mode 100644 index 0000000..b0ff7a9 --- /dev/null +++ b/src/Keys/List/OnChange.luau @@ -0,0 +1,28 @@ +-- Variables +local Packages = script.Parent.Parent.Parent.Parent.Parent.Packages +local Utility = script.Parent.Parent.Utility +local Keys = require(Utility.Keys) +local Debugger = require(Packages.debugger) + +-- Module + +--[=[ + Connects a callback to a certain property change event. + + [Learn More](https://luminlabsdev.github.io/ui-framework/api/keys/#onchange) +]=] +return function(propName: string) + if not Keys["OnChange"] then + Keys["OnChange"] = { + Name = "OnChange", + Apply = function(instance: Instance, callback: (...any) -> ()) + local Success, Event = pcall(instance.GetPropertyChangedSignal, instance :: any, propName :: any) + if not Success or type(callback) ~= "function" then + Debugger.Fatal("") + end + Event:Connect(callback) + end + } + end + return Keys["OnChange"] +end diff --git a/src/Keys/List/OnEvent.luau b/src/Keys/List/OnEvent.luau new file mode 100644 index 0000000..3f88b04 --- /dev/null +++ b/src/Keys/List/OnEvent.luau @@ -0,0 +1,29 @@ +-- Variables +local Packages = script.Parent.Parent.Parent.Parent.Packages +local Utility = script.Parent.Utility +local FindProp = require(Utility.FindProp) +local Keys = require(Utility.Keys) +local Debugger = require(Packages.debugger) + +-- Module + +--[=[ + Connects a callback to an event on the instance. + + [Learn More](https://luminlabsdev.github.io/ui-framework/api/keys/#onevent) +]=] +return function(eventName: string) + if not Keys["OnEvent"] then + Keys["OnEvent"] = { + Name = "OnEvent", + Apply = function(instance: Instance, callback: (...any) -> ()) + local Success, Event = pcall(FindProp, instance :: any, eventName :: any) + if not Success or type(callback) ~= "function" then + Debugger.Fatal("") + end + Event:Connect(callback) + end + } + end + return Keys["OnEvent"] +end diff --git a/src/Keys/Ref.luau b/src/Keys/Ref.luau deleted file mode 100644 index 9f12bd1..0000000 --- a/src/Keys/Ref.luau +++ /dev/null @@ -1,19 +0,0 @@ --- FOLDERS > -local Utility = script.Parent.Parent.Utility - --- DEPENDENCIES > -local Is = require(Utility.Is) -local Debugger = require(Utility.Debugger) -local Types = require(script.Parent.Parent.Types) - --- RETURNING > -return { - KeyName = "Ref", - ApplyKey = function(instance: Instance, value: any) - if Is.AegisConstructor(value) == true and (value :: Types.Constructor).ConstructorClass == "state" then - value:Set(instance) - else - Debugger.Warn("ServiceExpected", "state", typeof(value)) - end - end, -} diff --git a/src/Functions/RegisterKey.luau b/src/Keys/RegisterKey.luau similarity index 100% rename from src/Functions/RegisterKey.luau rename to src/Keys/RegisterKey.luau diff --git a/src/Keys/Tags.luau b/src/Keys/Tags.luau deleted file mode 100644 index b33fff5..0000000 --- a/src/Keys/Tags.luau +++ /dev/null @@ -1,10 +0,0 @@ --- RETURNING > -return { - KeyName = "Tags", - ApplyKey = function(instance: Instance, value: { string }) - for _, tag in value do - -- Loop over provided tags and add it to instance - instance:AddTag(tag) - end - end, -} diff --git a/src/Functions/UnregisterKey.luau b/src/Keys/UnregisterKey.luau similarity index 100% rename from src/Functions/UnregisterKey.luau rename to src/Keys/UnregisterKey.luau diff --git a/src/Keys/Utility/FindProp.luau b/src/Keys/Utility/FindProp.luau new file mode 100644 index 0000000..04cd31c --- /dev/null +++ b/src/Keys/Utility/FindProp.luau @@ -0,0 +1,4 @@ +-- Check if a property/event exists on an instance or not +return function(instance: Instance, property: string) + return (instance :: any)[property] +end diff --git a/src/Keys/Utility/Keys.luau b/src/Keys/Utility/Keys.luau new file mode 100644 index 0000000..a564707 --- /dev/null +++ b/src/Keys/Utility/Keys.luau @@ -0,0 +1 @@ +return {} diff --git a/src/Logs.luau b/src/Logs.luau new file mode 100644 index 0000000..7eb06fa --- /dev/null +++ b/src/Logs.luau @@ -0,0 +1,3 @@ +return { + +} diff --git a/src/Constructors/compute.luau b/src/State/Compute.luau similarity index 79% rename from src/Constructors/compute.luau rename to src/State/Compute.luau index 0dbbefb..27c7960 100644 --- a/src/Constructors/compute.luau +++ b/src/State/Compute.luau @@ -112,31 +112,11 @@ function Class.Destroy(self: Types.Compute): nil return nil end ---[[ - ## `Aegis.compute` - A constructor that calculates the result while listening to the value of its dependencies. - #### Parameters - - **processor:** The processing function that will run everytime the value changes. - - **dependencies:** Table of dependencies whose values will be listened to. - #### Returns - - [`compute`](https://lumin-dev.github.io/Aegis/api/compute) | [`Tutorial`](https://lumin-dev.github.io/Aegis/guide/managing-computes) - #### Example - ```luau - local state = Aegis.state - local compute = Aegis.compute +--[=[ + Creates a new compute which is similar to a value but will compute the value on change. - local Coins = state(100) -- State object for coins - local Price = state(50) -- State object for price value - - local CalculateCoins = compute(function(get) - return get(Coins) - get(Price) - end, { Coins }) -- adding a dependency - - print(CalculateCoins:Get()) -- 50 - Coins:Set(200) -- changing the value - print(CalculateCoins:Get()) -- 150 - ``` -]] + [Learn More](https://luminlabsdev.github.io/ui-framework/api/#compute) +]=] return function( processor: (get: typeof(get)) -> (), dependencies: { Types.State | Types.Spring | Types.Constructor }? diff --git a/src/Constructors/state.luau b/src/State/Value.luau similarity index 82% rename from src/Constructors/state.luau rename to src/State/Value.luau index ee2a1c1..de8de92 100644 --- a/src/Constructors/state.luau +++ b/src/State/Value.luau @@ -145,37 +145,11 @@ function Class.Destroy(self: Types.State): nil return nil end ---[[ - ## `Aegis.state` - A constructor to create new state objects. - #### Parameters - - **initialValue:** The initial value of the state object. - - **protectType:** Whether to do type checking when setting value (default: true) - #### Returns - - [`state`](https://lumin-dev.github.io/Aegis/api/state) | [`Tutorial`](https://lumin-dev.github.io/Aegis/guide/managing-states) - #### Example - ```luau - local MyState = Aegis.state("Hello Aegis") +--[=[ + Creates a new value/state object that dynamically changes in UI whe changed itself. - MyState:Listen(function(newValue: string, oldValue: string) - print(`Before: {oldValue}`) - print(`After: {newValue}`) - print("-----") - end) - - MyState:Set("hi fellow developers") - MyState:Set("how are you guys") - ``` - - #### Output: - ```txt - Before: Hello Aegis - After: hi fellow developers - ----- - Before: hi fellow developers - After: how are you guys - ----- -]] + [Learn More](https://luminlabsdev.github.io/ui-framework/api/#value) +]=] return function(initialValue: any, protectType: boolean?): Types.State local Type = type(initialValue) diff --git a/src/Types.luau b/src/Types.luau index 281795b..f290f3a 100644 --- a/src/Types.luau +++ b/src/Types.luau @@ -1,4 +1,3 @@ --- EXTRA TYPES > export type Animatable = boolean | number @@ -41,7 +40,6 @@ export type SpringInfo = { Frequency: number?, } --- State types export type StateFunc = { _init: (self: State, prop: string, instance: Instance) -> (), Get: (self: State) -> any, @@ -59,7 +57,6 @@ export type StateProps = { export type State = typeof(setmetatable({} :: StateProps, {} :: { __index: StateFunc })) --- Spring types export type SpringFunc = { _init: (self: Spring, prop: string, instance: Instance) -> (), Get: (self: Spring) -> any, @@ -82,7 +79,6 @@ export type SpringProps = { export type Spring = typeof(setmetatable({} :: SpringProps, {} :: { __index: SpringFunc })) --- Compute types export type ComputeFunc = { _init: (self: Compute, prop: string, instance: Instance) -> (), Get: (self: Compute) -> any, diff --git a/src/init.luau b/src/init.luau index 7724e03..9b61d65 100644 --- a/src/init.luau +++ b/src/init.luau @@ -1,19 +1,19 @@ --- FOLDERS > -local Constructors = script.Constructors -local Functions = script.Functions +-- Variables +local Packages = script.Parent.Parent.Packages +local Instances = script.Instances +local Animation = script.Animation +local State = script.State +local Keys = script.Keys --- DEPENDENCIES > local Types = require(script.Types) +local Debugger = require(Packages.debugger) +local RegisterKey = require(Keys.RegisterKey) --- VARIABLES > -local RegisterKey = require(Functions.RegisterKey) - --- INITIALIZE > for _, key in script.Keys:GetChildren() do RegisterKey(require(key) :: Types.Key) end --- EXPORTING > +-- Types export type Key = Types.Key export type State = Types.State export type Spring = Types.Spring @@ -23,20 +23,24 @@ export type SpringInfo = Types.SpringInfo export type DefaultKeys = Types.DefaultKeys export type Component = Types.Component ---[[ - ## Aegis - A simple strictly typed UI framework made specifically for Roblox. -]] +-- Module +Debugger.SetMetadata({ + PackageURL = "https://github.com/luminlabsdev/ui-framework", + PackageName = "UI Framework", +}) + return table.freeze({ - -- CONSTRUCTORS > - new = require(Constructors.new), - state = require(Constructors.state), - spring = require(Constructors.spring), - compute = require(Constructors.compute), + New = require(Instances.New), + Update = require(Instances.Update), + Value = require(State.Value), + Compute = require(State.Compute), + Spring = require(Animation.Spring), + Tween = require(Animation.Tween), + + OnEvent = require(Keys.List.OnEvent), + OnChange = require(Keys.List.OnChange), - -- FUNCTIONS > - Update = require(Functions.Update), - Key = require(Functions.Key), - UnregisterKey = require(Functions.UnregisterKey), + Key = require(Keys.Key), + UnregisterKey = require(Keys.UnregisterKey), RegisterKey = RegisterKey, }) diff --git a/tests/client/UI.client.luau b/tests/Client/UI.client.luau similarity index 100% rename from tests/client/UI.client.luau rename to tests/Client/UI.client.luau diff --git a/tests/client/components/Background.luau b/tests/Client/components/Background.luau similarity index 100% rename from tests/client/components/Background.luau rename to tests/Client/components/Background.luau diff --git a/tests/client/useTheme.luau b/tests/Client/useTheme.luau similarity index 100% rename from tests/client/useTheme.luau rename to tests/Client/useTheme.luau diff --git a/tests/server/Test.server.luau b/tests/Server/Test.server.luau similarity index 100% rename from tests/server/Test.server.luau rename to tests/Server/Test.server.luau diff --git a/tests/shared/Theme.luau b/tests/Shared/Theme.luau similarity index 100% rename from tests/shared/Theme.luau rename to tests/Shared/Theme.luau diff --git a/tests/lighting/Atmosphere.rbxm b/tests/lighting/Atmosphere.rbxm deleted file mode 100644 index a4071246d6c5251dd3356c30a4e9eb06a40576f2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 686 zcmZ`%%T59@6fKAv31Ad;flDQl(d}$Sg2e7&QI_Yx^Qds zo`O&GBTtexWhgd@&G9IaJ!yl~ zs&gfW*5s&bbt+m>C*Gramk785A`NGO9Vj!p6gM`;bI@ATmFn0iN5mg_(f!E-O@B_WMTI+&z^LRVnWi0k@7= zBz9D)dm=ETY+ZjmcLw^u4;k|tGk?P<#8Uk+J&m>@Pie2UQhp AQUCw| diff --git a/tests/lighting/Bloom.rbxm b/tests/lighting/Bloom.rbxm deleted file mode 100644 index 9293c5d31c23e85d6241dd92823849968003c64f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 602 zcmZuv+e*Vg5KT%%tX9#2h}Twp_Xk9XHV+kyrO6K@?bI%8vn9KM>Wc-R{5wBo|3K$# zqzLVSGqZEqncdmFD^)JlqWksJYMwSd&-ZGwa(Ir?@P=2{f3|HSKzyidkEQPhQ^d4uMFvg zN|8zNPH66ST(Q1@!La*~d(6jdp5;OcBS?4Q1khkT9SwRk5e4c0yBaPXL3a$+w!y;N zW=2JpOBy$PR6JqFF(M3$sJFxH7lsNg%v2S<6|e`87;K`dazvrlWcuSXcp2`9n@gtIt6q(9^DWY8NqVZ}I9PJ6!7xrSVfTux WzgJJkh9AW}R`udol8EQFZ`kg#y*QX z8OJh^+R1f#m&!ydo1;3*$@2%pD?VSa0L1|`a@sW3kKL#vDGuEzqClI1xbF44Jrrrc zVHA7NH5NzfOpbC*YCxG3v3w!)U^33wp1@%gJJ8!Kw_+?tGL~ABY9a`rz$zUD+7!uz z)N)qY&~a(nU|W<~SsN^FB1SQVz;=mzp7zNL7-atoWUZN>cQa{^o90c{4Z5<3o zu?1aa>7+rf+EQte1Y}R?>tj9FOANa&LYXUj`m^q%un1o~Q3=CXp85KxeOhk$bvFA1 zx54?REI_dfjg|*#o(1G6McNB70KiORbzo>^C?3>eWBw3J!Xv=<|MuA_xqjP3H;uNe K*7f|~y!itlfqF&& diff --git a/tests/lighting/Sky.rbxm b/tests/lighting/Sky.rbxm deleted file mode 100644 index d79dee7aad3e824fa4d6f688f5091d478661a6ed..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1126 zcmbtU+iuf95Vb=QP|+eNqKIpXka$5PjuSUU6_T3-DTtb?cHgm^ZCTZLBYQ0jkG$~# z{1>0He*ot=5dt-(NIlZb?5t4aJenMDZs}qb|?V476|XgPV=YI)sm*X^`>TOFS7bX(c$;ogWe>A6vp4&_^Ri#-GqeAL`|Z(1viC2< zeK1|b?R0u=*K=I{?j}0?_oVT1LsjO7!sl&{C-<>oJ^Q{IF#ayqyiLMfp}qzQb({}W znQ7eS`jm0JzB&=saMmqOeONA>uns=883UO5Aut2M{~9o7%k#XR)AmTmajzdDD>R@i l4p> diff --git a/tests/lighting/SunRays.rbxm b/tests/lighting/SunRays.rbxm deleted file mode 100644 index 2d2e4619750e5404d8e31c2a30aa8a511eaf7990..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 568 zcmZuvZA!yH5Z#obSgfK|k&4=i|GhvFf(=r^Sejg5(@ta|CMCOpR!`s&>LEOfN7)x~hHKf#Q%EEasV-D&tqC zcqmkEbd#f|tY{QQagXf_CSdomwwY0tPvlYuX-ZS$dLc8OJdIJm2Zvz~uy&ZfF{Mf> zLpq{T$xOWx+Pf2%yr08i*gdSf%sV-kiOQ5wr27a0Xs{_qgCV6VC;j(S!^x3!*WleY zcoEyoAeTu-vxbL?ryMvzhGCHvJIqmTDA&p?n~VF;Bj~yug%+@o2n;HeFXZ7=JrgK< z?EW*fqAI84YfWY}J7WppZg9*7E(%x_6rsX=ribSN XzJ8yD9WMxnF6yq$*5GFSzuf)+0l{F9 diff --git a/tests/workspace/Baseplate.rbxm b/tests/workspace/Baseplate.rbxm deleted file mode 100644 index e56d236f45288ac2ba720add6eb1cc5075e9fa42..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2512 zcma)8%W@Jy6dg$7BbrD|q9(qGWm)cAxN(uP1OgUTLJ+9zo1qC^nM_Z0_n6=!r3)AC z@@am`_yu}Tj|>b$g172+!_49KxzA=-$*w2QcYgj^S>9fDoSYLYZB`DdozhGC^y1(5 zXdQ_Aq}B7l6Rt3&(8y0x_(m_%Q=>v&Z?roP>GLKjB)WkWZ<|aRdjuXdTZhdJ+F=Y5 zEnvMxTJqh2RJ@nZ0fVE9q>yM0>pE%47$v%);kwP0V4nEO!OU9Sq8$Vv5ez!ynNw!& z2@znYrNs+!5~k+>%K%!7+q6F-g+#Zp-XVp>cBuNy<<<$9d`{1w0zeY2Vl9wPAnSe* zngsrsUV;TA0!!yEX;~U0Pp8Pvg^uYyAse6!iNMrZA&sq05MBh~9eM-OkO*9DLQ>c? zWq5}JAd!tZ@>{7-9T&lMrwbr}s*B3Pavs_S>l~AKx216}e<~5ZJxPr4=HU-(B zpnr(0@VTChP2R$hUX&UnLiil?T-9e?kJr3V^lDPMT*tAQ-4`__eKS?P^N{1>on7bF z=0xpUu0>+@j1&^x!wRmG&~)i$%rDZWT^*zap@3i-|STP=gViMRZmG&r4i@l~h>{usR z#(=>TheQ~24wBoE!Bm4^j~hpJc59KniMTGHWZ*|~&%g}_9Xp=?5`QowfSo o(s90ja2)K-R-=P^#yU>>ujGFdeaTfDd$h%=z`pw?{vY@LFQJ*OhX4Qo diff --git a/tests/workspace/Spawn.rbxm b/tests/workspace/Spawn.rbxm deleted file mode 100644 index d3531b4b7773c0eaeb2253e5d1ba305e8e3872ce..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2716 zcma)8$#T;`5S2~XNeDZH&7ml+9Jp|xC>$rILJ`N9J;D!w6t1py8HFa6Qg$m{ciQkpT#pPXFRXwrAiaa*2bWDpRVrx zyH75`;v(tByC_h;a?RN37g~kRF3?kFV!7Gr4;plRhZK^W$GAw^kHmiXQv1Rw9rC~M zrrX=@!hZudB*_JgS4o>ep!Ww-?6t-s+?CtmK*#>L&R<-n_rL*3j$u4S+6?`%HgZ_6 zReQYz8|RGLiJi24X_N@mdx=G{*Bdln!wpFShaLsRTND19t}tS+x$uGF1J_3wuECH! zuF!m)6q20Ac$O3%`>`1bU-Ba0@-98U4Fi&73F9*9jOAt+#V#|yNiTr{k^rT5j&w~s zr}qkAk2Iaay+u9%8Ik}gCoc6`1iVUb0UDA3D<>ppn}>|m;Rld}V}63JT5XD~T&^#B zpFTgst2A&Z03;cb9LI=7wnW&{L7;|mUKxJa^5<4nT zPDzW^vLIK7fwQhZ7DK(C{y5JZe2la*eoG8^Zgd>gPST@wITCT;4zGgzH=9E)`06@D z(#Tw!M=`PT@yhpaKVVqKf~suA7UeRYSmleLYjh+H7JGwhw;UAkhrp^(+S%Boxd3sl zkU|npT`d8t9lv-?S9w&EY|J z;Lcpm9HKf9yLL_ypnmw^fJO*FKasC;v9O(v3VmX}-82K$3?1mG7=Nrc+xW0t4`-sO z;r~Q`U_@vmVPxn}7CzGFSP>j&X9jMMIJ9J;zmN}o_2xd(X0I)Lr%g}ngYq2q@}>zs z*|CWD#KJb^GC^uA5p)Rv5479s46yO>!fF1M9sTI0w$WLq$@7@