diff --git a/src/Instances/New.luau b/src/Instances/New.luau index 09716db..4026844 100644 --- a/src/Instances/New.luau +++ b/src/Instances/New.luau @@ -54,7 +54,7 @@ return function( Component = Result else -- If it wasn't successful, error it because instance creation has to be complete. - Debugger.Fatal("FailedToCreate", component, Result) + Debugger.Fatal("FailedCreation", component, Result) end else if children then diff --git a/src/Keys/Change.luau b/src/Keys/Change.luau new file mode 100644 index 0000000..5766a19 --- /dev/null +++ b/src/Keys/Change.luau @@ -0,0 +1,25 @@ +-- Variables +local Packages = script.Parent.Parent.Parent.Parent.Packages +local Utility = script.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/#change) +]=] +return function(prop: string) + if not Keys["Change"] then + Keys["Change"] = function(instance: Instance, callback: (...any) -> ()) + local Success, Event = pcall(instance.GetPropertyChangedSignal, instance :: any, prop :: any) + if not Success or type(callback) ~= "function" then + Debugger.Fatal("") + end + Event:Connect(callback) + end + end + return Keys["Change"] +end diff --git a/src/Keys/Event.luau b/src/Keys/Event.luau new file mode 100644 index 0000000..9859d6c --- /dev/null +++ b/src/Keys/Event.luau @@ -0,0 +1,26 @@ +-- 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/#event) +]=] +return function(event: string) + if not Keys["Event"] then + Keys["Event"] = function(instance: Instance, callback: (...any) -> ()) + local Success, Event = pcall(FindProp, instance :: any, event :: any) + if not Success or type(callback) ~= "function" then + Debugger.Fatal("") + end + Event:Connect(callback) + end + end + return Keys["Event"] +end diff --git a/src/Keys/Key.luau b/src/Keys/Key.luau deleted file mode 100644 index 4c23168..0000000 --- a/src/Keys/Key.luau +++ /dev/null @@ -1,47 +0,0 @@ --- FOLDERS > -local Aegis = script.Parent.Parent - --- DEPENDENCIES > -local Types = require(Aegis.Types) -local Storage = require(Aegis.Runtime.Storage) -local Debugger = require(Aegis.Utility.Debugger) - --- FUNCTIONS > ---[[ - ## `Aegis.Key` - The key to index. - #### Parameters - - **keyName:** The name of the key to index. - #### Returns - - [`Key?`](https://lumin-dev.github.io/Aegis/api/keys/) | [`Tutorial`](https://lumin-dev.github.io/Aegis/guide/using-keys) - #### Example - ```luau - local Events = Aegis.Key("Events") - - new("ScreenGui", { - Name = "MenuUI", - Parent = Player:WaitForChild("PlayerGui"), - }, { - InteractButton = new("TextButton", { - Size = UDim2.new(0.1, 0, 0.075, 0), - Text = "Interact", - TextScaled = true, - - [Events] = { - MouseButton1Click = function() - print("Clicked!") - end, - } - }) - }) - ``` -]] -return function(name: Types.DefaultKeys | string): Types.Key - local FoundKey = Storage.RegisteredKeys[name] - - if not FoundKey then - Debugger.Error("KeyNotFound", name) - end - - return FoundKey -end diff --git a/src/Keys/List/OnAttributeChange.luau b/src/Keys/List/OnAttributeChange.luau deleted file mode 100644 index e69de29..0000000 diff --git a/src/Keys/List/OnChange.luau b/src/Keys/List/OnChange.luau deleted file mode 100644 index b0ff7a9..0000000 --- a/src/Keys/List/OnChange.luau +++ /dev/null @@ -1,28 +0,0 @@ --- 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 deleted file mode 100644 index 3f88b04..0000000 --- a/src/Keys/List/OnEvent.luau +++ /dev/null @@ -1,29 +0,0 @@ --- 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/RegisterKey.luau b/src/Keys/RegisterKey.luau deleted file mode 100644 index f8aded4..0000000 --- a/src/Keys/RegisterKey.luau +++ /dev/null @@ -1,46 +0,0 @@ --- FOLDERS > -local Aegis = script.Parent.Parent - --- DEPENDENCIES > -local Types = require(Aegis.Types) -local Is = require(Aegis.Utility.Is) -local Storage = require(Aegis.Runtime.Storage) -local Debugger = require(Aegis.Utility.Debugger) - --- FUNCTIONS > ---[[ - ## `Aegis.RegisterKey` - A new key to register. - #### Parameters - - **key:** The key to index. - #### Returns - - [`Key?`](https://lumin-dev.github.io/Aegis/api/keys/) | [`Tutorial`](https://lumin-dev.github.io/Aegis/guide/managing-keys) - #### Example - ```luau - local NamePrinterKey = Aegis.RegisterKey({ - KeyName = "NamePrinter", - ApplyKey = function(instance: Instance, value: any) - print(instance.Name, value) - end, - }) - - Aegis.new("Frame", { - Name = "UI", - [NamePrinterKey] = "is made by Aegis!", -- UI is made by Aegis! - }) - ``` -]] -return function(key: Types.Key): Types.Key? - if Is.Key(key) then - if not Storage.RegisteredKeys[key.KeyName] then - Storage.RegisteredKeys[key.KeyName] = key - return Storage.RegisteredKeys[key.KeyName] - else - Debugger.Warn("FailedToRegisterKey", `{key.KeyName} already exists.`) - return - end - else - Debugger.Warn("FailedToRegisterKey", "Argument#1 is not a key.") - return - end -end diff --git a/src/Keys/Tag.luau b/src/Keys/Tag.luau new file mode 100644 index 0000000..fc5202d --- /dev/null +++ b/src/Keys/Tag.luau @@ -0,0 +1,19 @@ +-- Variables +local Utility = script.Parent.Utility +local Keys = require(Utility.Keys) + +-- Module + +--[=[ + Adds a tag with the provided name to the instance. + + [Learn More](https://luminlabsdev.github.io/ui-framework/api/keys/#tag) +]=] +return function() + if not Keys["Tag"] then + Keys["Tag"] = function(instance: Instance, name: string) + instance:AddTag(name) + end + end + return Keys["Tag"] +end diff --git a/src/Keys/UnregisterKey.luau b/src/Keys/UnregisterKey.luau deleted file mode 100644 index 557d3b1..0000000 --- a/src/Keys/UnregisterKey.luau +++ /dev/null @@ -1,41 +0,0 @@ --- FOLDERS > -local Aegis = script.Parent.Parent - --- DEPENDENCIES > -local Storage = require(Aegis.Runtime.Storage) -local Debugger = require(Aegis.Utility.Debugger) - --- FUNCTIONS > ---[[ - ## `Aegis.UnregisterKey` - A key to remove. - #### Parameters - - **keyName:** The name of the key to remove. - #### Returns - - [`Key?`](https://lumin-dev.github.io/Aegis/api/keys/) | [`Tutorial`](https://lumin-dev.github.io/Aegis/guide/managing-keys) - #### Example - ```luau - local NamePrinterKey = Aegis.RegisterKey({ - KeyName = "NamePrinter", - ApplyKey = function(instance: Instance, value: any) - print(instance.Name, value) - end, - }) - - Aegis.new("Frame", { - Name = "UI", - [NamePrinterKey] = "is made by Aegis!", -- UI is made by Aegis! - }) - - Aegis.UnregisterKey("NamePrinter") -- Now, we are removing it. - ``` -]] -return function(key: string): () - if not Storage.RegisteredKeys[key] then - Debugger.Warn("KeyNotFound", key) - return - end - - table.clear(Storage.RegisteredKeys[key]) - Storage.RegisteredKeys[key] = nil -end diff --git a/src/Logs.luau b/src/Logs.luau index 7eb06fa..d9e9619 100644 --- a/src/Logs.luau +++ b/src/Logs.luau @@ -1,3 +1,9 @@ return { - + IncompatibleType = "Data type '%s' is incompatible", + NotAnimatable = "%s is not an animatable object", + FailedCreation = "%s could not be created; '%s'", + + InvalidType = "Expected type %s; got '%s'", + InvalidKey = "Expected valid key type; got '%s'", + InvalidClass = "'%s' is not an instance class name", } diff --git a/src/Utility/Debugger.luau b/src/Utility/Debugger.luau deleted file mode 100644 index ce75abb..0000000 --- a/src/Utility/Debugger.luau +++ /dev/null @@ -1,37 +0,0 @@ --- VARIABLES > -local Logs = { - TypeMismatch = "Expected type (%s); received (%s)", - MissingChild = "Could not find (%s) in (%s).", - FailedToCreate = "Failed to create instance with class name (%s); Result: %s", - ServiceExpected = "Expected to receive an Aegis.%s type. Received %s", - RestrictedType = "DataType '%s' is not compatible.", - FailedToRegisterKey = "Failed to register key. Reason: %s", - KeyNotFound = "Key (%s) isn't registered.", - MissingConstructor = "Missing a Aegis.%s constructor.", - NotAnimatable = "Data type (%s) is not animatable. Change to an animatable data type.", - CannotFindIndex = "Cannot find index (%s)", - ConstructorNotSupported = "`%s` constructor is not supported.", -} - --- FUNCTIONS > -local function Warn(id: string, ...: any) - local FoundId = Logs[id] or nil :: string? - - if FoundId then - warn(`\n[AEGIS] {string.format(FoundId, ...)}\nAt -> {debug.traceback()}`) - end -end - -local function Error(id: string, ...: any) - local FoundId = Logs[id] or nil :: string? - - if FoundId then - error(`\n[AEGIS] {string.format(FoundId, ...)}\nAt -> {debug.traceback()}`) - end -end - --- RETURNING > -return table.freeze({ - Warn = Warn, - Error = Error, -})