diff --git a/Libraries/Fusion/Animation/Spring.luau b/Libraries/Fusion/Animation/Spring.luau index 5b0744f..e11a5c8 100644 --- a/Libraries/Fusion/Animation/Spring.luau +++ b/Libraries/Fusion/Animation/Spring.luau @@ -14,7 +14,7 @@ local SpringScheduler = require "../Animation/SpringScheduler" local updateAll = require "../State/updateAll" local xtypeof = require "../Utility/xtypeof" local peek = require "../State/peek" -local typeof = require "../Polyfill/typeof" +local typeof = require "../../../Modules/Polyfill/typeof" local class = {} diff --git a/Libraries/Fusion/Animation/Tween.luau b/Libraries/Fusion/Animation/Tween.luau index 5bd62a8..2240ce8 100644 --- a/Libraries/Fusion/Animation/Tween.luau +++ b/Libraries/Fusion/Animation/Tween.luau @@ -13,7 +13,7 @@ local logError = require "../Logging/logError" local logErrorNonFatal = require "../Logging/logErrorNonFatal" local xtypeof = require "../Utility/xtypeof" local peek = require "../State/peek" -local typeof = require "../Polyfill/typeof" +local typeof = require "../../../Modules/Polyfill/typeof" local class = {} diff --git a/Libraries/Fusion/Animation/getTweenRatio.luau b/Libraries/Fusion/Animation/getTweenRatio.luau index 8ec5aac..859f5a7 100644 --- a/Libraries/Fusion/Animation/getTweenRatio.luau +++ b/Libraries/Fusion/Animation/getTweenRatio.luau @@ -6,7 +6,7 @@ ]] -- local TweenService = game:GetService "TweenService" -local easing = require "../Polyfill/easing" +local easing = require "../../../Modules/Polyfill/easing" local function getTweenRatio(tweenInfo: TweenInfo, currentTime: number): number local delay = tweenInfo.DelayTime diff --git a/Libraries/Fusion/Animation/lerpType.luau b/Libraries/Fusion/Animation/lerpType.luau index 5067588..2846692 100644 --- a/Libraries/Fusion/Animation/lerpType.luau +++ b/Libraries/Fusion/Animation/lerpType.luau @@ -10,7 +10,7 @@ ]] local Oklab = require "../Colour/Oklab" -local typeof = require "../Polyfill/typeof" +local typeof = require "../../../Modules/Polyfill/typeof" local function lerpType(from: any, to: any, ratio: number): any local typeString = typeof(from) diff --git a/Libraries/Fusion/Instances/Children.luau b/Libraries/Fusion/Instances/Children.luau index 68d32aa..8cf161b 100644 --- a/Libraries/Fusion/Instances/Children.luau +++ b/Libraries/Fusion/Instances/Children.luau @@ -11,7 +11,7 @@ local logWarn = require "../Logging/logWarn" local Observer = require "../State/Observer" local peek = require "../State/peek" local isState = require "../State/isState" -local typeof = require "../Polyfill/typeof" +local typeof = require "../../../Modules/Polyfill/typeof" type Set = { [T]: boolean } diff --git a/Libraries/Fusion/Instances/OnChange.luau b/Libraries/Fusion/Instances/OnChange.luau index 1960848..2abab9a 100644 --- a/Libraries/Fusion/Instances/OnChange.luau +++ b/Libraries/Fusion/Instances/OnChange.luau @@ -7,7 +7,7 @@ local PubTypes = require "../PubTypes" local logError = require "../Logging/logError" -local typeof = require "../Polyfill/typeof" +local typeof = require "../../../Modules/Polyfill/typeof" local function OnChange(propertyName: string): PubTypes.SpecialKey local changeKey = {} diff --git a/Libraries/Fusion/Instances/OnEvent.luau b/Libraries/Fusion/Instances/OnEvent.luau index ecd54b2..9350f19 100644 --- a/Libraries/Fusion/Instances/OnEvent.luau +++ b/Libraries/Fusion/Instances/OnEvent.luau @@ -7,7 +7,7 @@ local PubTypes = require "../PubTypes" local logError = require "../Logging/logError" -local typeof = require "../Polyfill/typeof" +local typeof = require "../../../Modules/Polyfill/typeof" local function getProperty_unsafe(instance: Instance, property: string) return (instance :: any)[property] diff --git a/Libraries/Fusion/Instances/applyInstanceProps.luau b/Libraries/Fusion/Instances/applyInstanceProps.luau index 0e554bd..1b891af 100644 --- a/Libraries/Fusion/Instances/applyInstanceProps.luau +++ b/Libraries/Fusion/Instances/applyInstanceProps.luau @@ -20,7 +20,7 @@ local xtypeof = require "../Utility/xtypeof" local logError = require "../Logging/logError" local Observer = require "../State/Observer" local peek = require "../State/peek" -local typeof = require "../Polyfill/typeof" +local typeof = require "../../../Modules/Polyfill/typeof" local function setProperty_unsafe( instance: Instance, diff --git a/Libraries/Fusion/Logging/logError.luau b/Libraries/Fusion/Logging/logError.luau index 49f7323..c6b2878 100644 --- a/Libraries/Fusion/Logging/logError.luau +++ b/Libraries/Fusion/Logging/logError.luau @@ -20,24 +20,20 @@ local function logError(messageID: string, errObj: Types.Error?, ...) local errorString if errObj == nil then errorString = string.format( - "[Fusion] " .. formatString .. "\n(ID: " .. messageID .. ")", - ... + string.format(`[Fusion] {formatString}\n(ID: {messageID})`, ...) ) else formatString = - formatString:gsub("ERROR_MESSAGE", tostring(errObj.message)) + string.gsub(formatString, "ERROR_MESSAGE", tostring(errObj.message)) errorString = string.format( - "[Fusion] " - .. formatString - .. "\n(ID: " - .. messageID - .. ")\n---- Stack trace ----\n" - .. tostring(errObj.trace), + `[Fusion] {formatString}\n(ID: {messageID})\n---- Stack trace ----\n{tostring( + errObj.trace + )}`, ... ) end - error(errorString:gsub("\n", "\n "), 0) + error(string.gsub(errorString, "\n", "\n "), 0) end return logError diff --git a/Libraries/Fusion/Logging/logErrorNonFatal.luau b/Libraries/Fusion/Logging/logErrorNonFatal.luau index 9d59733..aedc120 100644 --- a/Libraries/Fusion/Logging/logErrorNonFatal.luau +++ b/Libraries/Fusion/Logging/logErrorNonFatal.luau @@ -19,18 +19,16 @@ local function logErrorNonFatal(messageID: string, errObj: Types.Error?, ...) local errorString if errObj == nil then - errorString = + errorString = string.format( string.format(`[Fusion] {formatString}\n(ID: {messageID})`, ...) + ) else formatString = - formatString:gsub("ERROR_MESSAGE", tostring(errObj.message)) + string.gsub(formatString, "ERROR_MESSAGE", tostring(errObj.message)) errorString = string.format( - "[Fusion] " - .. formatString - .. "\n(ID: " - .. messageID - .. ")\n---- Stack trace ----\n" - .. tostring(errObj.trace), + `[Fusion] {formatString}\n(ID: {messageID})\n---- Stack trace ----\n{tostring( + errObj.trace + )}`, ... ) end diff --git a/Libraries/Fusion/Logging/messages.luau b/Libraries/Fusion/Logging/messages.luau index 0a8ebea..6e218ed 100644 --- a/Libraries/Fusion/Logging/messages.luau +++ b/Libraries/Fusion/Logging/messages.luau @@ -23,6 +23,7 @@ return { forKeysKeyCollision = "ForKeys should only write to output key '%s' once when processing key changes, but it wrote to it twice. Previously input key: '%s'; New input key: '%s'", forKeysDestructorError = "ForKeys destructor error: ERROR_MESSAGE", forPairsDestructorError = "ForPairs destructor error: ERROR_MESSAGE", + -- logError(invalidEasingStyle, easingStyle) forPairsKeyCollision = "ForPairs should only write to output key '%s' once when processing key changes, but it wrote to it twice. Previous input pair: '[%s] = %s'; New input pair: '[%s] = %s'", forPairsProcessorError = "ForPairs callback error: ERROR_MESSAGE", forValuesProcessorError = "ForValues callback error: ERROR_MESSAGE", @@ -49,7 +50,4 @@ return { unrecognisedChildType = "'%s' type children aren't accepted by `[Children]`.", unrecognisedPropertyKey = "'%s' keys aren't accepted in property tables.", unrecognisedPropertyStage = "'%s' isn't a valid stage for a special key to be applied at.", - - invalidEasingStyle = "The easing style must be a valid Enum.EasingStyle or a string of 'Linear', 'Quad', 'Cubic', 'Quart', 'Quint', 'Sine', 'Exponential', 'Circular', 'Elastic', 'Back', 'Bounce'. (got %s)", - invalidEasingDirection = "The easing direction must be a valid Enum.EasingDirection or a string of 'In', 'Out', 'InOut', 'OutIn'. (got %s)", } diff --git a/Libraries/Fusion/MercuryExternal.luau b/Libraries/Fusion/MercuryExternal.luau index b6e9b4b..4a9c412 100644 --- a/Libraries/Fusion/MercuryExternal.luau +++ b/Libraries/Fusion/MercuryExternal.luau @@ -1,6 +1,6 @@ --!strict --[[ - Roblox implementation for Fusion's abstract scheduler layer. + Mercury implementation for Fusion's abstract scheduler layer. ]] local RunService = game:GetService "RunService" @@ -24,7 +24,7 @@ function MercuryExternal.doTaskDeferred(resume: () -> ()) end --[[ - Sends an update step to Fusion using the Roblox clock time. + Sends an update step to Fusion using the Mercury clock time. ]] local function performUpdateStep() External.performUpdateStep(time()) @@ -38,7 +38,7 @@ function MercuryExternal.startScheduler() if stopSchedulerFunc ~= nil then return end - -- if RunService:IsClient() then + -- if not _SERVER then -- In cases where multiple Fusion modules are running simultaneously, -- -- this prevents collisions. -- local id = "FusionUpdateStep_" .. HttpService:GenerateGUID() diff --git a/Libraries/Fusion/PubTypes.luau b/Libraries/Fusion/PubTypes.luau index 6a1a3ff..90c5f36 100644 --- a/Libraries/Fusion/PubTypes.luau +++ b/Libraries/Fusion/PubTypes.luau @@ -133,7 +133,7 @@ export type Spring = StateObject & Dependent & { -- An object which can listen for updates on another state object. export type Observer = Dependent & { kind: "Observer", - onChange: (Observer, callback: () -> ()) -> (() -> ()), + onChange: (Observer, callback: () -> ()) -> () -> (), } --[[ diff --git a/Libraries/Fusion/Types.luau b/Libraries/Fusion/Types.luau index 8470b30..de8fb7f 100644 --- a/Libraries/Fusion/Types.luau +++ b/Libraries/Fusion/Types.luau @@ -83,7 +83,7 @@ export type ForPairs = PubTypes.ForPairs & { -- A state object whose value is derived from other objects using a callback. export type ForKeys = PubTypes.ForKeys & { _oldDependencySet: Set, - _processor: (PubTypes.Use, KI) -> (KO), + _processor: (PubTypes.Use, KI) -> KO, _destructor: (KO, M?) -> (), _inputIsState: boolean, _inputTable: PubTypes.CanBeState<{ [KI]: KO }>, @@ -103,7 +103,7 @@ export type ForKeys = PubTypes.ForKeys & { -- A state object whose value is derived from other objects using a callback. export type ForValues = PubTypes.ForValues & { _oldDependencySet: Set, - _processor: (PubTypes.Use, VI) -> (VO), + _processor: (PubTypes.Use, VI) -> VO, _destructor: (VO, M?) -> (), _inputIsState: boolean, _inputTable: PubTypes.CanBeState<{ [VI]: VO }>, diff --git a/Libraries/Fusion/Utility/cleanup.luau b/Libraries/Fusion/Utility/cleanup.luau index b67c299..9dc5a17 100644 --- a/Libraries/Fusion/Utility/cleanup.luau +++ b/Libraries/Fusion/Utility/cleanup.luau @@ -11,7 +11,7 @@ - an array - `cleanup` will be called on each item ]] -local typeof = require "../Polyfill/typeof" +local typeof = require "../../../Modules/Polyfill/typeof" local function cleanupOne(task: any) local taskType = typeof(task) diff --git a/Libraries/Fusion/Utility/needsDestruction.luau b/Libraries/Fusion/Utility/needsDestruction.luau index 1ee6eb0..6e265b7 100644 --- a/Libraries/Fusion/Utility/needsDestruction.luau +++ b/Libraries/Fusion/Utility/needsDestruction.luau @@ -5,7 +5,7 @@ requires manual cleanup. ]] -local typeof = require "../Polyfill/typeof" +local typeof = require "../../../Modules/Polyfill/typeof" local function needsDestruction(x: any): boolean return typeof(x) == "Instance" diff --git a/Libraries/Fusion/Utility/xtypeof.luau b/Libraries/Fusion/Utility/xtypeof.luau index 19187f1..438dcf2 100644 --- a/Libraries/Fusion/Utility/xtypeof.luau +++ b/Libraries/Fusion/Utility/xtypeof.luau @@ -6,7 +6,7 @@ Otherwise, returns `typeof()` the argument. ]] -local typeof = require "../Polyfill/typeof" +local typeof = require "../../../Modules/Polyfill/typeof" local function xtypeof(x: any) local typeString = typeof(x) diff --git a/Libraries/Fusion/init.luau b/Libraries/Fusion/init.luau index 43ac0e8..ebb7dcb 100644 --- a/Libraries/Fusion/init.luau +++ b/Libraries/Fusion/init.luau @@ -42,8 +42,8 @@ local Fusion = restrictRead("Fusion", { doNothing = require "./Utility/doNothing", peek = require "./State/peek", - typeof = require "./Polyfill/typeof", - TweenInfo = require "./Polyfill/TweenInfo", + typeof = require "../../Modules/Polyfill/typeof", + TweenInfo = require "../../Modules/Polyfill/TweenInfo", Help = function() return "See https://elttob.uk/Fusion/0.3/ for more information." @@ -69,10 +69,10 @@ type Fusion = { New: ( className: string - ) -> ((propertyTable: PubTypes.PropertyTable) -> Instance), + ) -> (propertyTable: PubTypes.PropertyTable) -> Instance, Hydrate: ( target: Instance - ) -> ((propertyTable: PubTypes.PropertyTable) -> Instance), + ) -> (propertyTable: PubTypes.PropertyTable) -> Instance, Ref: PubTypes.SpecialKey, Cleanup: PubTypes.SpecialKey, Children: PubTypes.SpecialKey, diff --git a/Libraries/Fusion/Polyfill/TweenInfo.luau b/Modules/Polyfill/TweenInfo.luau similarity index 77% rename from Libraries/Fusion/Polyfill/TweenInfo.luau rename to Modules/Polyfill/TweenInfo.luau index 1ffb808..23ca5f2 100644 --- a/Libraries/Fusion/Polyfill/TweenInfo.luau +++ b/Modules/Polyfill/TweenInfo.luau @@ -1,7 +1,6 @@ -- A basic polyfill for the TweenInfo.new function, -- allows using Enum.EasingStyle/Direction or strings instead -local logError = require "../Logging/logError" local TweenInfo = {} function TweenInfo.new( @@ -19,7 +18,7 @@ function TweenInfo.new( -- convert it to a string if type(easingStyle) ~= "string" then if easingStyle then - easingStyle = tostring(easingStyle):gsub("Enum.%w+.", "") + easingStyle = string.gsub(tostring(easingStyle), "Enum.%w+.", "") end else local ok @@ -42,13 +41,17 @@ function TweenInfo.new( end end if not ok then - logError("invalidEasingStyle", nil, easingStyle) + error( + `The easing style must be a valid Enum.EasingStyle or a string of 'Linear', 'Quad', 'Cubic', 'Quart', 'Quint', 'Sine', 'Exponential', 'Circular', 'Elastic', 'Back', 'Bounce'. (got {easingStyle})`, + 0 + ) end end if type(easingDirection) ~= "string" then if easingDirection then - easingDirection = tostring(easingDirection):gsub("Enum.%w+.", "") + easingDirection = + string.gsub(tostring(easingDirection), "Enum.%w+.", "") end else local ok @@ -64,7 +67,10 @@ function TweenInfo.new( end end if not ok then - logError("invalidEasingDirection", nil, easingDirection) + error( + `The easing direction must be a valid Enum.EasingDirection or a string of 'In', 'Out', 'InOut', 'OutIn'. (got {easingDirection})`, + 0 + ) end end @@ -99,9 +105,9 @@ function TweenInfo.new( .. " Reverses:" .. (reverses and "True" or "False") .. " EasingDirection:" - .. easingDirection + .. tostring(easingDirection) .. " EasingStyle:" - .. easingStyle + .. tostring(easingStyle) end mt.__metatable = "The metatable is locked" diff --git a/Libraries/Fusion/Polyfill/easing.luau b/Modules/Polyfill/easing.luau similarity index 100% rename from Libraries/Fusion/Polyfill/easing.luau rename to Modules/Polyfill/easing.luau diff --git a/Libraries/Fusion/Polyfill/typeof.luau b/Modules/Polyfill/typeof.luau similarity index 99% rename from Libraries/Fusion/Polyfill/typeof.luau rename to Modules/Polyfill/typeof.luau index 170ab2c..faa9f2b 100644 --- a/Libraries/Fusion/Polyfill/typeof.luau +++ b/Modules/Polyfill/typeof.luau @@ -178,4 +178,5 @@ return function(value) return t end end + return basicType end