commit 1003e84648e11d722ee0ec8bcb4e07406a82984f Author: Azur Date: Sun Sep 14 13:34:16 2025 +0200 first commit diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..a9bc76a --- /dev/null +++ b/.eslintrc @@ -0,0 +1,27 @@ +{ + "parser": "@typescript-eslint/parser", + "parserOptions": { + "jsx": true, + "useJSXTextNode": true, + "ecmaVersion": 2018, + "sourceType": "module", + "project": "./tsconfig.json" + }, + "ignorePatterns": [ + "/out" + ], + "plugins": [ + "@typescript-eslint", + "roblox-ts", + "prettier" + ], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:roblox-ts/recommended-legacy", + "plugin:prettier/recommended" + ], + "rules": { + "prettier/prettier": "warn" + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d1e66cf --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/node_modules +/out \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..0d69450 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "printWidth": 120, + "tabWidth": 4, + "trailingComma": "all", + "useTabs": true +} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..c544019 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "roblox-ts.vscode-roblox-ts", + "dbaeumer.vscode-eslint" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..480840b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,15 @@ +{ + "typescript.tsdk": "node_modules/typescript/lib", + "files.eol": "\n", + "[typescript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true + }, + "[typescriptreact]": { + "editor.defaultFormatter": "dbaeumer.vscode-eslint", + "editor.formatOnSave": true + }, + "eslint.run": "onType", + "eslint.format.enable": true, + "eslint.useFlatConfig": false +} \ No newline at end of file diff --git a/default.project.json b/default.project.json new file mode 100644 index 0000000..1765cf0 --- /dev/null +++ b/default.project.json @@ -0,0 +1,19 @@ +{ + "name": "roblox-ts-plugin", + "globIgnorePaths": [ + "**/package.json", + "**/tsconfig.json" + ], + "tree": { + "$path": "out", + "include": { + "$path": "include", + "node_modules": { + "$className": "Folder", + "@rbxts": { + "$path": "node_modules/@rbxts" + } + } + } + } +} diff --git a/include/Promise.lua b/include/Promise.lua new file mode 100644 index 0000000..97cdf37 --- /dev/null +++ b/include/Promise.lua @@ -0,0 +1,2068 @@ +--[[ + An implementation of Promises similar to Promise/A+. +]] + +local ERROR_NON_PROMISE_IN_LIST = "Non-promise value passed into %s at index %s" +local ERROR_NON_LIST = "Please pass a list of promises to %s" +local ERROR_NON_FUNCTION = "Please pass a handler function to %s!" +local MODE_KEY_METATABLE = { __mode = "k" } + +local function isCallable(value) + if type(value) == "function" then + return true + end + + if type(value) == "table" then + local metatable = getmetatable(value) + if metatable and type(rawget(metatable, "__call")) == "function" then + return true + end + end + + return false +end + +--[[ + Creates an enum dictionary with some metamethods to prevent common mistakes. +]] +local function makeEnum(enumName, members) + local enum = {} + + for _, memberName in ipairs(members) do + enum[memberName] = memberName + end + + return setmetatable(enum, { + __index = function(_, k) + error(string.format("%s is not in %s!", k, enumName), 2) + end, + __newindex = function() + error(string.format("Creating new members in %s is not allowed!", enumName), 2) + end, + }) +end + +--[=[ + An object to represent runtime errors that occur during execution. + Promises that experience an error like this will be rejected with + an instance of this object. + + @class Error +]=] +local Error +do + Error = { + Kind = makeEnum("Promise.Error.Kind", { + "ExecutionError", + "AlreadyCancelled", + "NotResolvedInTime", + "TimedOut", + }), + } + Error.__index = Error + + function Error.new(options, parent) + options = options or {} + return setmetatable({ + error = tostring(options.error) or "[This error has no error text.]", + trace = options.trace, + context = options.context, + kind = options.kind, + parent = parent, + createdTick = os.clock(), + createdTrace = debug.traceback(), + }, Error) + end + + function Error.is(anything) + if type(anything) == "table" then + local metatable = getmetatable(anything) + + if type(metatable) == "table" then + return rawget(anything, "error") ~= nil and type(rawget(metatable, "extend")) == "function" + end + end + + return false + end + + function Error.isKind(anything, kind) + assert(kind ~= nil, "Argument #2 to Promise.Error.isKind must not be nil") + + return Error.is(anything) and anything.kind == kind + end + + function Error:extend(options) + options = options or {} + + options.kind = options.kind or self.kind + + return Error.new(options, self) + end + + function Error:getErrorChain() + local runtimeErrors = { self } + + while runtimeErrors[#runtimeErrors].parent do + table.insert(runtimeErrors, runtimeErrors[#runtimeErrors].parent) + end + + return runtimeErrors + end + + function Error:__tostring() + local errorStrings = { + string.format("-- Promise.Error(%s) --", self.kind or "?"), + } + + for _, runtimeError in ipairs(self:getErrorChain()) do + table.insert( + errorStrings, + table.concat({ + runtimeError.trace or runtimeError.error, + runtimeError.context, + }, "\n") + ) + end + + return table.concat(errorStrings, "\n") + end +end + +--[[ + Packs a number of arguments into a table and returns its length. + + Used to cajole varargs without dropping sparse values. +]] +local function pack(...) + return select("#", ...), { ... } +end + +--[[ + Returns first value (success), and packs all following values. +]] +local function packResult(success, ...) + return success, select("#", ...), { ... } +end + +local function makeErrorHandler(traceback) + assert(traceback ~= nil, "traceback is nil") + + return function(err) + -- If the error object is already a table, forward it directly. + -- Should we extend the error here and add our own trace? + + if type(err) == "table" then + return err + end + + return Error.new({ + error = err, + kind = Error.Kind.ExecutionError, + trace = debug.traceback(tostring(err), 2), + context = "Promise created at:\n\n" .. traceback, + }) + end +end + +--[[ + Calls a Promise executor with error handling. +]] +local function runExecutor(traceback, callback, ...) + return packResult(xpcall(callback, makeErrorHandler(traceback), ...)) +end + +--[[ + Creates a function that invokes a callback with correct error handling and + resolution mechanisms. +]] +local function createAdvancer(traceback, callback, resolve, reject) + return function(...) + local ok, resultLength, result = runExecutor(traceback, callback, ...) + + if ok then + resolve(unpack(result, 1, resultLength)) + else + reject(result[1]) + end + end +end + +local function isEmpty(t) + return next(t) == nil +end + +--[=[ + An enum value used to represent the Promise's status. + @interface Status + @tag enum + @within Promise + .Started "Started" -- The Promise is executing, and not settled yet. + .Resolved "Resolved" -- The Promise finished successfully. + .Rejected "Rejected" -- The Promise was rejected. + .Cancelled "Cancelled" -- The Promise was cancelled before it finished. +]=] +--[=[ + @prop Status Status + @within Promise + @readonly + @tag enums + A table containing all members of the `Status` enum, e.g., `Promise.Status.Resolved`. +]=] +--[=[ + A Promise is an object that represents a value that will exist in the future, but doesn't right now. + Promises allow you to then attach callbacks that can run once the value becomes available (known as *resolving*), + or if an error has occurred (known as *rejecting*). + + @class Promise + @__index prototype +]=] +local Promise = { + Error = Error, + Status = makeEnum("Promise.Status", { "Started", "Resolved", "Rejected", "Cancelled" }), + _getTime = os.clock, + _timeEvent = game:GetService("RunService").Heartbeat, + _unhandledRejectionCallbacks = {}, +} +Promise.prototype = {} +Promise.__index = Promise.prototype + +function Promise._new(traceback, callback, parent) + if parent ~= nil and not Promise.is(parent) then + error("Argument #2 to Promise.new must be a promise or nil", 2) + end + + local self = { + -- The executor thread. + _thread = nil, + + -- Used to locate where a promise was created + _source = traceback, + + _status = Promise.Status.Started, + + -- A table containing a list of all results, whether success or failure. + -- Only valid if _status is set to something besides Started + _values = nil, + + -- Lua doesn't like sparse arrays very much, so we explicitly store the + -- length of _values to handle middle nils. + _valuesLength = -1, + + -- Tracks if this Promise has no error observers.. + _unhandledRejection = true, + + -- Queues representing functions we should invoke when we update! + _queuedResolve = {}, + _queuedReject = {}, + _queuedFinally = {}, + + -- The function to run when/if this promise is cancelled. + _cancellationHook = nil, + + -- The "parent" of this promise in a promise chain. Required for + -- cancellation propagation upstream. + _parent = parent, + + -- Consumers are Promises that have chained onto this one. + -- We track them for cancellation propagation downstream. + _consumers = setmetatable({}, MODE_KEY_METATABLE), + } + + if parent and parent._status == Promise.Status.Started then + parent._consumers[self] = true + end + + setmetatable(self, Promise) + + local function resolve(...) + self:_resolve(...) + end + + local function reject(...) + self:_reject(...) + end + + local function onCancel(cancellationHook) + if cancellationHook then + if self._status == Promise.Status.Cancelled then + cancellationHook() + else + self._cancellationHook = cancellationHook + end + end + + return self._status == Promise.Status.Cancelled + end + + self._thread = coroutine.create(function() + local ok, _, result = runExecutor(self._source, callback, resolve, reject, onCancel) + + if not ok then + reject(result[1]) + end + end) + + task.spawn(self._thread) + + return self +end + +--[=[ + Construct a new Promise that will be resolved or rejected with the given callbacks. + + If you `resolve` with a Promise, it will be chained onto. + + You can safely yield within the executor function and it will not block the creating thread. + + ```lua + local myFunction() + return Promise.new(function(resolve, reject, onCancel) + wait(1) + resolve("Hello world!") + end) + end + + myFunction():andThen(print) + ``` + + You do not need to use `pcall` within a Promise. Errors that occur during execution will be caught and turned into a rejection automatically. If `error()` is called with a table, that table will be the rejection value. Otherwise, string errors will be converted into `Promise.Error(Promise.Error.Kind.ExecutionError)` objects for tracking debug information. + + You may register an optional cancellation hook by using the `onCancel` argument: + + * This should be used to abort any ongoing operations leading up to the promise being settled. + * Call the `onCancel` function with a function callback as its only argument to set a hook which will in turn be called when/if the promise is cancelled. + * `onCancel` returns `true` if the Promise was already cancelled when you called `onCancel`. + * Calling `onCancel` with no argument will not override a previously set cancellation hook, but it will still return `true` if the Promise is currently cancelled. + * You can set the cancellation hook at any time before resolving. + * When a promise is cancelled, calls to `resolve` or `reject` will be ignored, regardless of if you set a cancellation hook or not. + + :::caution + If the Promise is cancelled, the `executor` thread is closed with `coroutine.close` after the cancellation hook is called. + + You must perform any cleanup code in the cancellation hook: any time your executor yields, it **may never resume**. + ::: + + @param executor (resolve: (...: any) -> (), reject: (...: any) -> (), onCancel: (abortHandler?: () -> ()) -> boolean) -> () + @return Promise +]=] +function Promise.new(executor) + return Promise._new(debug.traceback(nil, 2), executor) +end + +function Promise:__tostring() + return string.format("Promise(%s)", self._status) +end + +--[=[ + The same as [Promise.new](/api/Promise#new), except execution begins after the next `Heartbeat` event. + + This is a spiritual replacement for `spawn`, but it does not suffer from the same [issues](https://eryn.io/gist/3db84579866c099cdd5bb2ff37947cec) as `spawn`. + + ```lua + local function waitForChild(instance, childName, timeout) + return Promise.defer(function(resolve, reject) + local child = instance:WaitForChild(childName, timeout) + + ;(child and resolve or reject)(child) + end) + end + ``` + + @param executor (resolve: (...: any) -> (), reject: (...: any) -> (), onCancel: (abortHandler?: () -> ()) -> boolean) -> () + @return Promise +]=] +function Promise.defer(executor) + local traceback = debug.traceback(nil, 2) + local promise + promise = Promise._new(traceback, function(resolve, reject, onCancel) + local connection + connection = Promise._timeEvent:Connect(function() + connection:Disconnect() + local ok, _, result = runExecutor(traceback, executor, resolve, reject, onCancel) + + if not ok then + reject(result[1]) + end + end) + end) + + return promise +end + +-- Backwards compatibility +Promise.async = Promise.defer + +--[=[ + Creates an immediately resolved Promise with the given value. + + ```lua + -- Example using Promise.resolve to deliver cached values: + function getSomething(name) + if cache[name] then + return Promise.resolve(cache[name]) + else + return Promise.new(function(resolve, reject) + local thing = getTheThing() + cache[name] = thing + + resolve(thing) + end) + end + end + ``` + + @param ... any + @return Promise<...any> +]=] +function Promise.resolve(...) + local length, values = pack(...) + return Promise._new(debug.traceback(nil, 2), function(resolve) + resolve(unpack(values, 1, length)) + end) +end + +--[=[ + Creates an immediately rejected Promise with the given value. + + :::caution + Something needs to consume this rejection (i.e. `:catch()` it), otherwise it will emit an unhandled Promise rejection warning on the next frame. Thus, you should not create and store rejected Promises for later use. Only create them on-demand as needed. + ::: + + @param ... any + @return Promise<...any> +]=] +function Promise.reject(...) + local length, values = pack(...) + return Promise._new(debug.traceback(nil, 2), function(_, reject) + reject(unpack(values, 1, length)) + end) +end + +--[[ + Runs a non-promise-returning function as a Promise with the + given arguments. +]] +function Promise._try(traceback, callback, ...) + local valuesLength, values = pack(...) + + return Promise._new(traceback, function(resolve) + resolve(callback(unpack(values, 1, valuesLength))) + end) +end + +--[=[ + Begins a Promise chain, calling a function and returning a Promise resolving with its return value. If the function errors, the returned Promise will be rejected with the error. You can safely yield within the Promise.try callback. + + :::info + `Promise.try` is similar to [Promise.promisify](#promisify), except the callback is invoked immediately instead of returning a new function. + ::: + + ```lua + Promise.try(function() + return math.random(1, 2) == 1 and "ok" or error("Oh an error!") + end) + :andThen(function(text) + print(text) + end) + :catch(function(err) + warn("Something went wrong") + end) + ``` + + @param callback (...: T...) -> ...any + @param ... T... -- Additional arguments passed to `callback` + @return Promise +]=] +function Promise.try(callback, ...) + return Promise._try(debug.traceback(nil, 2), callback, ...) +end + +--[[ + Returns a new promise that: + * is resolved when all input promises resolve + * is rejected if ANY input promises reject +]] +function Promise._all(traceback, promises, amount) + if type(promises) ~= "table" then + error(string.format(ERROR_NON_LIST, "Promise.all"), 3) + end + + -- We need to check that each value is a promise here so that we can produce + -- a proper error rather than a rejected promise with our error. + for i, promise in pairs(promises) do + if not Promise.is(promise) then + error(string.format(ERROR_NON_PROMISE_IN_LIST, "Promise.all", tostring(i)), 3) + end + end + + -- If there are no values then return an already resolved promise. + if #promises == 0 or amount == 0 then + return Promise.resolve({}) + end + + return Promise._new(traceback, function(resolve, reject, onCancel) + -- An array to contain our resolved values from the given promises. + local resolvedValues = {} + local newPromises = {} + + -- Keep a count of resolved promises because just checking the resolved + -- values length wouldn't account for promises that resolve with nil. + local resolvedCount = 0 + local rejectedCount = 0 + local done = false + + local function cancel() + for _, promise in ipairs(newPromises) do + promise:cancel() + end + end + + -- Called when a single value is resolved and resolves if all are done. + local function resolveOne(i, ...) + if done then + return + end + + resolvedCount = resolvedCount + 1 + + if amount == nil then + resolvedValues[i] = ... + else + resolvedValues[resolvedCount] = ... + end + + if resolvedCount >= (amount or #promises) then + done = true + resolve(resolvedValues) + cancel() + end + end + + onCancel(cancel) + + -- We can assume the values inside `promises` are all promises since we + -- checked above. + for i, promise in ipairs(promises) do + newPromises[i] = promise:andThen(function(...) + resolveOne(i, ...) + end, function(...) + rejectedCount = rejectedCount + 1 + + if amount == nil or #promises - rejectedCount < amount then + cancel() + done = true + + reject(...) + end + end) + end + + if done then + cancel() + end + end) +end + +--[=[ + Accepts an array of Promises and returns a new promise that: + * is resolved after all input promises resolve. + * is rejected if *any* input promises reject. + + :::info + Only the first return value from each promise will be present in the resulting array. + ::: + + After any input Promise rejects, all other input Promises that are still pending will be cancelled if they have no other consumers. + + ```lua + local promises = { + returnsAPromise("example 1"), + returnsAPromise("example 2"), + returnsAPromise("example 3"), + } + + return Promise.all(promises) + ``` + + @param promises {Promise} + @return Promise<{T}> +]=] +function Promise.all(promises) + return Promise._all(debug.traceback(nil, 2), promises) +end + +--[=[ + Folds an array of values or promises into a single value. The array is traversed sequentially. + + The reducer function can return a promise or value directly. Each iteration receives the resolved value from the previous, and the first receives your defined initial value. + + The folding will stop at the first rejection encountered. + ```lua + local basket = {"blueberry", "melon", "pear", "melon"} + Promise.fold(basket, function(cost, fruit) + if fruit == "blueberry" then + return cost -- blueberries are free! + else + -- call a function that returns a promise with the fruit price + return fetchPrice(fruit):andThen(function(fruitCost) + return cost + fruitCost + end) + end + end, 0) + ``` + + @since v3.1.0 + @param list {T | Promise} + @param reducer (accumulator: U, value: T, index: number) -> U | Promise + @param initialValue U +]=] +function Promise.fold(list, reducer, initialValue) + assert(type(list) == "table", "Bad argument #1 to Promise.fold: must be a table") + assert(isCallable(reducer), "Bad argument #2 to Promise.fold: must be a function") + + local accumulator = Promise.resolve(initialValue) + return Promise.each(list, function(resolvedElement, i) + accumulator = accumulator:andThen(function(previousValueResolved) + return reducer(previousValueResolved, resolvedElement, i) + end) + end):andThen(function() + return accumulator + end) +end + +--[=[ + Accepts an array of Promises and returns a Promise that is resolved as soon as `count` Promises are resolved from the input array. The resolved array values are in the order that the Promises resolved in. When this Promise resolves, all other pending Promises are cancelled if they have no other consumers. + + `count` 0 results in an empty array. The resultant array will never have more than `count` elements. + + ```lua + local promises = { + returnsAPromise("example 1"), + returnsAPromise("example 2"), + returnsAPromise("example 3"), + } + + return Promise.some(promises, 2) -- Only resolves with first 2 promises to resolve + ``` + + @param promises {Promise} + @param count number + @return Promise<{T}> +]=] +function Promise.some(promises, count) + assert(type(count) == "number", "Bad argument #2 to Promise.some: must be a number") + + return Promise._all(debug.traceback(nil, 2), promises, count) +end + +--[=[ + Accepts an array of Promises and returns a Promise that is resolved as soon as *any* of the input Promises resolves. It will reject only if *all* input Promises reject. As soon as one Promises resolves, all other pending Promises are cancelled if they have no other consumers. + + Resolves directly with the value of the first resolved Promise. This is essentially [[Promise.some]] with `1` count, except the Promise resolves with the value directly instead of an array with one element. + + ```lua + local promises = { + returnsAPromise("example 1"), + returnsAPromise("example 2"), + returnsAPromise("example 3"), + } + + return Promise.any(promises) -- Resolves with first value to resolve (only rejects if all 3 rejected) + ``` + + @param promises {Promise} + @return Promise +]=] +function Promise.any(promises) + return Promise._all(debug.traceback(nil, 2), promises, 1):andThen(function(values) + return values[1] + end) +end + +--[=[ + Accepts an array of Promises and returns a new Promise that resolves with an array of in-place Statuses when all input Promises have settled. This is equivalent to mapping `promise:finally` over the array of Promises. + + ```lua + local promises = { + returnsAPromise("example 1"), + returnsAPromise("example 2"), + returnsAPromise("example 3"), + } + + return Promise.allSettled(promises) + ``` + + @param promises {Promise} + @return Promise<{Status}> +]=] +function Promise.allSettled(promises) + if type(promises) ~= "table" then + error(string.format(ERROR_NON_LIST, "Promise.allSettled"), 2) + end + + -- We need to check that each value is a promise here so that we can produce + -- a proper error rather than a rejected promise with our error. + for i, promise in pairs(promises) do + if not Promise.is(promise) then + error(string.format(ERROR_NON_PROMISE_IN_LIST, "Promise.allSettled", tostring(i)), 2) + end + end + + -- If there are no values then return an already resolved promise. + if #promises == 0 then + return Promise.resolve({}) + end + + return Promise._new(debug.traceback(nil, 2), function(resolve, _, onCancel) + -- An array to contain our resolved values from the given promises. + local fates = {} + local newPromises = {} + + -- Keep a count of resolved promises because just checking the resolved + -- values length wouldn't account for promises that resolve with nil. + local finishedCount = 0 + + -- Called when a single value is resolved and resolves if all are done. + local function resolveOne(i, ...) + finishedCount = finishedCount + 1 + + fates[i] = ... + + if finishedCount >= #promises then + resolve(fates) + end + end + + onCancel(function() + for _, promise in ipairs(newPromises) do + promise:cancel() + end + end) + + -- We can assume the values inside `promises` are all promises since we + -- checked above. + for i, promise in ipairs(promises) do + newPromises[i] = promise:finally(function(...) + resolveOne(i, ...) + end) + end + end) +end + +--[=[ + Accepts an array of Promises and returns a new promise that is resolved or rejected as soon as any Promise in the array resolves or rejects. + + :::warning + If the first Promise to settle from the array settles with a rejection, the resulting Promise from `race` will reject. + + If you instead want to tolerate rejections, and only care about at least one Promise resolving, you should use [Promise.any](#any) or [Promise.some](#some) instead. + ::: + + All other Promises that don't win the race will be cancelled if they have no other consumers. + + ```lua + local promises = { + returnsAPromise("example 1"), + returnsAPromise("example 2"), + returnsAPromise("example 3"), + } + + return Promise.race(promises) -- Only returns 1st value to resolve or reject + ``` + + @param promises {Promise} + @return Promise +]=] +function Promise.race(promises) + assert(type(promises) == "table", string.format(ERROR_NON_LIST, "Promise.race")) + + for i, promise in pairs(promises) do + assert(Promise.is(promise), string.format(ERROR_NON_PROMISE_IN_LIST, "Promise.race", tostring(i))) + end + + return Promise._new(debug.traceback(nil, 2), function(resolve, reject, onCancel) + local newPromises = {} + local finished = false + + local function cancel() + for _, promise in ipairs(newPromises) do + promise:cancel() + end + end + + local function finalize(callback) + return function(...) + cancel() + finished = true + return callback(...) + end + end + + if onCancel(finalize(reject)) then + return + end + + for i, promise in ipairs(promises) do + newPromises[i] = promise:andThen(finalize(resolve), finalize(reject)) + end + + if finished then + cancel() + end + end) +end + +--[=[ + Iterates serially over the given an array of values, calling the predicate callback on each value before continuing. + + If the predicate returns a Promise, we wait for that Promise to resolve before moving on to the next item + in the array. + + :::info + `Promise.each` is similar to `Promise.all`, except the Promises are ran in order instead of all at once. + + But because Promises are eager, by the time they are created, they're already running. Thus, we need a way to defer creation of each Promise until a later time. + + The predicate function exists as a way for us to operate on our data instead of creating a new closure for each Promise. If you would prefer, you can pass in an array of functions, and in the predicate, call the function and return its return value. + ::: + + ```lua + Promise.each({ + "foo", + "bar", + "baz", + "qux" + }, function(value, index) + return Promise.delay(1):andThen(function() + print(("%d) Got %s!"):format(index, value)) + end) + end) + + --[[ + (1 second passes) + > 1) Got foo! + (1 second passes) + > 2) Got bar! + (1 second passes) + > 3) Got baz! + (1 second passes) + > 4) Got qux! + ]] + ``` + + If the Promise a predicate returns rejects, the Promise from `Promise.each` is also rejected with the same value. + + If the array of values contains a Promise, when we get to that point in the list, we wait for the Promise to resolve before calling the predicate with the value. + + If a Promise in the array of values is already Rejected when `Promise.each` is called, `Promise.each` rejects with that value immediately (the predicate callback will never be called even once). If a Promise in the list is already Cancelled when `Promise.each` is called, `Promise.each` rejects with `Promise.Error(Promise.Error.Kind.AlreadyCancelled`). If a Promise in the array of values is Started at first, but later rejects, `Promise.each` will reject with that value and iteration will not continue once iteration encounters that value. + + Returns a Promise containing an array of the returned/resolved values from the predicate for each item in the array of values. + + If this Promise returned from `Promise.each` rejects or is cancelled for any reason, the following are true: + - Iteration will not continue. + - Any Promises within the array of values will now be cancelled if they have no other consumers. + - The Promise returned from the currently active predicate will be cancelled if it hasn't resolved yet. + + @since 3.0.0 + @param list {T | Promise} + @param predicate (value: T, index: number) -> U | Promise + @return Promise<{U}> +]=] +function Promise.each(list, predicate) + assert(type(list) == "table", string.format(ERROR_NON_LIST, "Promise.each")) + assert(isCallable(predicate), string.format(ERROR_NON_FUNCTION, "Promise.each")) + + return Promise._new(debug.traceback(nil, 2), function(resolve, reject, onCancel) + local results = {} + local promisesToCancel = {} + + local cancelled = false + + local function cancel() + for _, promiseToCancel in ipairs(promisesToCancel) do + promiseToCancel:cancel() + end + end + + onCancel(function() + cancelled = true + + cancel() + end) + + -- We need to preprocess the list of values and look for Promises. + -- If we find some, we must register our andThen calls now, so that those Promises have a consumer + -- from us registered. If we don't do this, those Promises might get cancelled by something else + -- before we get to them in the series because it's not possible to tell that we plan to use it + -- unless we indicate it here. + + local preprocessedList = {} + + for index, value in ipairs(list) do + if Promise.is(value) then + if value:getStatus() == Promise.Status.Cancelled then + cancel() + return reject(Error.new({ + error = "Promise is cancelled", + kind = Error.Kind.AlreadyCancelled, + context = string.format( + "The Promise that was part of the array at index %d passed into Promise.each was already cancelled when Promise.each began.\n\nThat Promise was created at:\n\n%s", + index, + value._source + ), + })) + elseif value:getStatus() == Promise.Status.Rejected then + cancel() + return reject(select(2, value:await())) + end + + -- Chain a new Promise from this one so we only cancel ours + local ourPromise = value:andThen(function(...) + return ... + end) + + table.insert(promisesToCancel, ourPromise) + preprocessedList[index] = ourPromise + else + preprocessedList[index] = value + end + end + + for index, value in ipairs(preprocessedList) do + if Promise.is(value) then + local success + success, value = value:await() + + if not success then + cancel() + return reject(value) + end + end + + if cancelled then + return + end + + local predicatePromise = Promise.resolve(predicate(value, index)) + + table.insert(promisesToCancel, predicatePromise) + + local success, result = predicatePromise:await() + + if not success then + cancel() + return reject(result) + end + + results[index] = result + end + + resolve(results) + end) +end + +--[=[ + Checks whether the given object is a Promise via duck typing. This only checks if the object is a table and has an `andThen` method. + + @param object any + @return boolean -- `true` if the given `object` is a Promise. +]=] +function Promise.is(object) + if type(object) ~= "table" then + return false + end + + local objectMetatable = getmetatable(object) + + if objectMetatable == Promise then + -- The Promise came from this library. + return true + elseif objectMetatable == nil then + -- No metatable, but we should still chain onto tables with andThen methods + return isCallable(object.andThen) + elseif + type(objectMetatable) == "table" + and type(rawget(objectMetatable, "__index")) == "table" + and isCallable(rawget(rawget(objectMetatable, "__index"), "andThen")) + then + -- Maybe this came from a different or older Promise library. + return true + end + + return false +end + +--[=[ + Wraps a function that yields into one that returns a Promise. + + Any errors that occur while executing the function will be turned into rejections. + + :::info + `Promise.promisify` is similar to [Promise.try](#try), except the callback is returned as a callable function instead of being invoked immediately. + ::: + + ```lua + local sleep = Promise.promisify(wait) + + sleep(1):andThen(print) + ``` + + ```lua + local isPlayerInGroup = Promise.promisify(function(player, groupId) + return player:IsInGroup(groupId) + end) + ``` + + @param callback (...: any) -> ...any + @return (...: any) -> Promise +]=] +function Promise.promisify(callback) + return function(...) + return Promise._try(debug.traceback(nil, 2), callback, ...) + end +end + +--[=[ + Returns a Promise that resolves after `seconds` seconds have passed. The Promise resolves with the actual amount of time that was waited. + + This function is **not** a wrapper around `wait`. `Promise.delay` uses a custom scheduler which provides more accurate timing. As an optimization, cancelling this Promise instantly removes the task from the scheduler. + + :::warning + Passing `NaN`, infinity, or a number less than 1/60 is equivalent to passing 1/60. + ::: + + ```lua + Promise.delay(5):andThenCall(print, "This prints after 5 seconds") + ``` + + @function delay + @within Promise + @param seconds number + @return Promise +]=] +do + -- uses a sorted doubly linked list (queue) to achieve O(1) remove operations and O(n) for insert + + -- the initial node in the linked list + local first + local connection + + function Promise.delay(seconds) + assert(type(seconds) == "number", "Bad argument #1 to Promise.delay, must be a number.") + -- If seconds is -INF, INF, NaN, or less than 1 / 60, assume seconds is 1 / 60. + -- This mirrors the behavior of wait() + if not (seconds >= 1 / 60) or seconds == math.huge then + seconds = 1 / 60 + end + + return Promise._new(debug.traceback(nil, 2), function(resolve, _, onCancel) + local startTime = Promise._getTime() + local endTime = startTime + seconds + + local node = { + resolve = resolve, + startTime = startTime, + endTime = endTime, + } + + if connection == nil then -- first is nil when connection is nil + first = node + connection = Promise._timeEvent:Connect(function() + local threadStart = Promise._getTime() + + while first ~= nil and first.endTime < threadStart do + local current = first + first = current.next + + if first == nil then + connection:Disconnect() + connection = nil + else + first.previous = nil + end + + current.resolve(Promise._getTime() - current.startTime) + end + end) + else -- first is non-nil + if first.endTime < endTime then -- if `node` should be placed after `first` + -- we will insert `node` between `current` and `next` + -- (i.e. after `current` if `next` is nil) + local current = first + local next = current.next + + while next ~= nil and next.endTime < endTime do + current = next + next = current.next + end + + -- `current` must be non-nil, but `next` could be `nil` (i.e. last item in list) + current.next = node + node.previous = current + + if next ~= nil then + node.next = next + next.previous = node + end + else + -- set `node` to `first` + node.next = first + first.previous = node + first = node + end + end + + onCancel(function() + -- remove node from queue + local next = node.next + + if first == node then + if next == nil then -- if `node` is the first and last + connection:Disconnect() + connection = nil + else -- if `node` is `first` and not the last + next.previous = nil + end + first = next + else + local previous = node.previous + -- since `node` is not `first`, then we know `previous` is non-nil + previous.next = next + + if next ~= nil then + next.previous = previous + end + end + end) + end) + end +end + +--[=[ + Returns a new Promise that resolves if the chained Promise resolves within `seconds` seconds, or rejects if execution time exceeds `seconds`. The chained Promise will be cancelled if the timeout is reached. + + Rejects with `rejectionValue` if it is non-nil. If a `rejectionValue` is not given, it will reject with a `Promise.Error(Promise.Error.Kind.TimedOut)`. This can be checked with [[Error.isKind]]. + + ```lua + getSomething():timeout(5):andThen(function(something) + -- got something and it only took at max 5 seconds + end):catch(function(e) + -- Either getting something failed or the time was exceeded. + + if Promise.Error.isKind(e, Promise.Error.Kind.TimedOut) then + warn("Operation timed out!") + else + warn("Operation encountered an error!") + end + end) + ``` + + Sugar for: + + ```lua + Promise.race({ + Promise.delay(seconds):andThen(function() + return Promise.reject( + rejectionValue == nil + and Promise.Error.new({ kind = Promise.Error.Kind.TimedOut }) + or rejectionValue + ) + end), + promise + }) + ``` + + @param seconds number + @param rejectionValue? any -- The value to reject with if the timeout is reached + @return Promise +]=] +function Promise.prototype:timeout(seconds, rejectionValue) + local traceback = debug.traceback(nil, 2) + + return Promise.race({ + Promise.delay(seconds):andThen(function() + return Promise.reject(rejectionValue == nil and Error.new({ + kind = Error.Kind.TimedOut, + error = "Timed out", + context = string.format( + "Timeout of %d seconds exceeded.\n:timeout() called at:\n\n%s", + seconds, + traceback + ), + }) or rejectionValue) + end), + self, + }) +end + +--[=[ + Returns the current Promise status. + + @return Status +]=] +function Promise.prototype:getStatus() + return self._status +end + +--[[ + Creates a new promise that receives the result of this promise. + + The given callbacks are invoked depending on that result. +]] +function Promise.prototype:_andThen(traceback, successHandler, failureHandler) + self._unhandledRejection = false + + -- If we are already cancelled, we return a cancelled Promise + if self._status == Promise.Status.Cancelled then + local promise = Promise.new(function() end) + promise:cancel() + + return promise + end + + -- Create a new promise to follow this part of the chain + return Promise._new(traceback, function(resolve, reject, onCancel) + -- Our default callbacks just pass values onto the next promise. + -- This lets success and failure cascade correctly! + + local successCallback = resolve + if successHandler then + successCallback = createAdvancer(traceback, successHandler, resolve, reject) + end + + local failureCallback = reject + if failureHandler then + failureCallback = createAdvancer(traceback, failureHandler, resolve, reject) + end + + if self._status == Promise.Status.Started then + -- If we haven't resolved yet, put ourselves into the queue + table.insert(self._queuedResolve, successCallback) + table.insert(self._queuedReject, failureCallback) + + onCancel(function() + -- These are guaranteed to exist because the cancellation handler is guaranteed to only + -- be called at most once + if self._status == Promise.Status.Started then + table.remove(self._queuedResolve, table.find(self._queuedResolve, successCallback)) + table.remove(self._queuedReject, table.find(self._queuedReject, failureCallback)) + end + end) + elseif self._status == Promise.Status.Resolved then + -- This promise has already resolved! Trigger success immediately. + successCallback(unpack(self._values, 1, self._valuesLength)) + elseif self._status == Promise.Status.Rejected then + -- This promise died a terrible death! Trigger failure immediately. + failureCallback(unpack(self._values, 1, self._valuesLength)) + end + end, self) +end + +--[=[ + Chains onto an existing Promise and returns a new Promise. + + :::warning + Within the failure handler, you should never assume that the rejection value is a string. Some rejections within the Promise library are represented by [[Error]] objects. If you want to treat it as a string for debugging, you should call `tostring` on it first. + ::: + + You can return a Promise from the success or failure handler and it will be chained onto. + + Calling `andThen` on a cancelled Promise returns a cancelled Promise. + + :::tip + If the Promise returned by `andThen` is cancelled, `successHandler` and `failureHandler` will not run. + + To run code no matter what, use [Promise:finally]. + ::: + + @param successHandler (...: any) -> ...any + @param failureHandler? (...: any) -> ...any + @return Promise<...any> +]=] +function Promise.prototype:andThen(successHandler, failureHandler) + assert(successHandler == nil or isCallable(successHandler), string.format(ERROR_NON_FUNCTION, "Promise:andThen")) + assert(failureHandler == nil or isCallable(failureHandler), string.format(ERROR_NON_FUNCTION, "Promise:andThen")) + + return self:_andThen(debug.traceback(nil, 2), successHandler, failureHandler) +end + +--[=[ + Shorthand for `Promise:andThen(nil, failureHandler)`. + + Returns a Promise that resolves if the `failureHandler` worked without encountering an additional error. + + :::warning + Within the failure handler, you should never assume that the rejection value is a string. Some rejections within the Promise library are represented by [[Error]] objects. If you want to treat it as a string for debugging, you should call `tostring` on it first. + ::: + + Calling `catch` on a cancelled Promise returns a cancelled Promise. + + :::tip + If the Promise returned by `catch` is cancelled, `failureHandler` will not run. + + To run code no matter what, use [Promise:finally]. + ::: + + @param failureHandler (...: any) -> ...any + @return Promise<...any> +]=] +function Promise.prototype:catch(failureHandler) + assert(failureHandler == nil or isCallable(failureHandler), string.format(ERROR_NON_FUNCTION, "Promise:catch")) + return self:_andThen(debug.traceback(nil, 2), nil, failureHandler) +end + +--[=[ + Similar to [Promise.andThen](#andThen), except the return value is the same as the value passed to the handler. In other words, you can insert a `:tap` into a Promise chain without affecting the value that downstream Promises receive. + + ```lua + getTheValue() + :tap(print) + :andThen(function(theValue) + print("Got", theValue, "even though print returns nil!") + end) + ``` + + If you return a Promise from the tap handler callback, its value will be discarded but `tap` will still wait until it resolves before passing the original value through. + + @param tapHandler (...: any) -> ...any + @return Promise<...any> +]=] +function Promise.prototype:tap(tapHandler) + assert(isCallable(tapHandler), string.format(ERROR_NON_FUNCTION, "Promise:tap")) + return self:_andThen(debug.traceback(nil, 2), function(...) + local callbackReturn = tapHandler(...) + + if Promise.is(callbackReturn) then + local length, values = pack(...) + return callbackReturn:andThen(function() + return unpack(values, 1, length) + end) + end + + return ... + end) +end + +--[=[ + Attaches an `andThen` handler to this Promise that calls the given callback with the predefined arguments. The resolved value is discarded. + + ```lua + promise:andThenCall(someFunction, "some", "arguments") + ``` + + This is sugar for + + ```lua + promise:andThen(function() + return someFunction("some", "arguments") + end) + ``` + + @param callback (...: any) -> any + @param ...? any -- Additional arguments which will be passed to `callback` + @return Promise +]=] +function Promise.prototype:andThenCall(callback, ...) + assert(isCallable(callback), string.format(ERROR_NON_FUNCTION, "Promise:andThenCall")) + local length, values = pack(...) + return self:_andThen(debug.traceback(nil, 2), function() + return callback(unpack(values, 1, length)) + end) +end + +--[=[ + Attaches an `andThen` handler to this Promise that discards the resolved value and returns the given value from it. + + ```lua + promise:andThenReturn("some", "values") + ``` + + This is sugar for + + ```lua + promise:andThen(function() + return "some", "values" + end) + ``` + + :::caution + Promises are eager, so if you pass a Promise to `andThenReturn`, it will begin executing before `andThenReturn` is reached in the chain. Likewise, if you pass a Promise created from [[Promise.reject]] into `andThenReturn`, it's possible that this will trigger the unhandled rejection warning. If you need to return a Promise, it's usually best practice to use [[Promise.andThen]]. + ::: + + @param ... any -- Values to return from the function + @return Promise +]=] +function Promise.prototype:andThenReturn(...) + local length, values = pack(...) + return self:_andThen(debug.traceback(nil, 2), function() + return unpack(values, 1, length) + end) +end + +--[=[ + Cancels this promise, preventing the promise from resolving or rejecting. Does not do anything if the promise is already settled. + + Cancellations will propagate upwards and downwards through chained promises. + + Promises will only be cancelled if all of their consumers are also cancelled. This is to say that if you call `andThen` twice on the same promise, and you cancel only one of the child promises, it will not cancel the parent promise until the other child promise is also cancelled. + + ```lua + promise:cancel() + ``` +]=] +function Promise.prototype:cancel() + if self._status ~= Promise.Status.Started then + return + end + + self._status = Promise.Status.Cancelled + + if self._cancellationHook then + self._cancellationHook() + end + + coroutine.close(self._thread) + + if self._parent then + self._parent:_consumerCancelled(self) + end + + for child in pairs(self._consumers) do + child:cancel() + end + + self:_finalize() +end + +--[[ + Used to decrease the number of consumers by 1, and if there are no more, + cancel this promise. +]] +function Promise.prototype:_consumerCancelled(consumer) + if self._status ~= Promise.Status.Started then + return + end + + self._consumers[consumer] = nil + + if next(self._consumers) == nil then + self:cancel() + end +end + +--[[ + Used to set a handler for when the promise resolves, rejects, or is + cancelled. +]] +function Promise.prototype:_finally(traceback, finallyHandler) + self._unhandledRejection = false + + local promise = Promise._new(traceback, function(resolve, reject, onCancel) + local handlerPromise + + onCancel(function() + -- The finally Promise is not a proper consumer of self. We don't care about the resolved value. + -- All we care about is running at the end. Therefore, if self has no other consumers, it's safe to + -- cancel. We don't need to hold out cancelling just because there's a finally handler. + self:_consumerCancelled(self) + + if handlerPromise then + handlerPromise:cancel() + end + end) + + local finallyCallback = resolve + if finallyHandler then + finallyCallback = function(...) + local callbackReturn = finallyHandler(...) + + if Promise.is(callbackReturn) then + handlerPromise = callbackReturn + + callbackReturn + :finally(function(status) + if status ~= Promise.Status.Rejected then + resolve(self) + end + end) + :catch(function(...) + reject(...) + end) + else + resolve(self) + end + end + end + + if self._status == Promise.Status.Started then + -- The promise is not settled, so queue this. + table.insert(self._queuedFinally, finallyCallback) + else + -- The promise already settled or was cancelled, run the callback now. + finallyCallback(self._status) + end + end) + + return promise +end + +--[=[ + Set a handler that will be called regardless of the promise's fate. The handler is called when the promise is + resolved, rejected, *or* cancelled. + + Returns a new Promise that: + - resolves with the same values that this Promise resolves with. + - rejects with the same values that this Promise rejects with. + - is cancelled if this Promise is cancelled. + + If the value you return from the handler is a Promise: + - We wait for the Promise to resolve, but we ultimately discard the resolved value. + - If the returned Promise rejects, the Promise returned from `finally` will reject with the rejected value from the + *returned* promise. + - If the `finally` Promise is cancelled, and you returned a Promise from the handler, we cancel that Promise too. + + Otherwise, the return value from the `finally` handler is entirely discarded. + + :::note Cancellation + As of Promise v4, `Promise:finally` does not count as a consumer of the parent Promise for cancellation purposes. + This means that if all of a Promise's consumers are cancelled and the only remaining callbacks are finally handlers, + the Promise is cancelled and the finally callbacks run then and there. + + Cancellation still propagates through the `finally` Promise though: if you cancel the `finally` Promise, it can cancel + its parent Promise if it had no other consumers. Likewise, if the parent Promise is cancelled, the `finally` Promise + will also be cancelled. + ::: + + ```lua + local thing = createSomething() + + doSomethingWith(thing) + :andThen(function() + print("It worked!") + -- do something.. + end) + :catch(function() + warn("Oh no it failed!") + end) + :finally(function() + -- either way, destroy thing + + thing:Destroy() + end) + + ``` + + @param finallyHandler (status: Status) -> ...any + @return Promise<...any> +]=] +function Promise.prototype:finally(finallyHandler) + assert(finallyHandler == nil or isCallable(finallyHandler), string.format(ERROR_NON_FUNCTION, "Promise:finally")) + return self:_finally(debug.traceback(nil, 2), finallyHandler) +end + +--[=[ + Same as `andThenCall`, except for `finally`. + + Attaches a `finally` handler to this Promise that calls the given callback with the predefined arguments. + + @param callback (...: any) -> any + @param ...? any -- Additional arguments which will be passed to `callback` + @return Promise +]=] +function Promise.prototype:finallyCall(callback, ...) + assert(isCallable(callback), string.format(ERROR_NON_FUNCTION, "Promise:finallyCall")) + local length, values = pack(...) + return self:_finally(debug.traceback(nil, 2), function() + return callback(unpack(values, 1, length)) + end) +end + +--[=[ + Attaches a `finally` handler to this Promise that discards the resolved value and returns the given value from it. + + ```lua + promise:finallyReturn("some", "values") + ``` + + This is sugar for + + ```lua + promise:finally(function() + return "some", "values" + end) + ``` + + @param ... any -- Values to return from the function + @return Promise +]=] +function Promise.prototype:finallyReturn(...) + local length, values = pack(...) + return self:_finally(debug.traceback(nil, 2), function() + return unpack(values, 1, length) + end) +end + +--[=[ + Yields the current thread until the given Promise completes. Returns the Promise's status, followed by the values that the promise resolved or rejected with. + + @yields + @return Status -- The Status representing the fate of the Promise + @return ...any -- The values the Promise resolved or rejected with. +]=] +function Promise.prototype:awaitStatus() + self._unhandledRejection = false + + if self._status == Promise.Status.Started then + local thread = coroutine.running() + + self + :finally(function() + task.spawn(thread) + end) + -- The finally promise can propagate rejections, so we attach a catch handler to prevent the unhandled + -- rejection warning from appearing + :catch( + function() end + ) + + coroutine.yield() + end + + if self._status == Promise.Status.Resolved then + return self._status, unpack(self._values, 1, self._valuesLength) + elseif self._status == Promise.Status.Rejected then + return self._status, unpack(self._values, 1, self._valuesLength) + end + + return self._status +end + +local function awaitHelper(status, ...) + return status == Promise.Status.Resolved, ... +end + +--[=[ + Yields the current thread until the given Promise completes. Returns true if the Promise resolved, followed by the values that the promise resolved or rejected with. + + :::caution + If the Promise gets cancelled, this function will return `false`, which is indistinguishable from a rejection. If you need to differentiate, you should use [[Promise.awaitStatus]] instead. + ::: + + ```lua + local worked, value = getTheValue():await() + + if worked then + print("got", value) + else + warn("it failed") + end + ``` + + @yields + @return boolean -- `true` if the Promise successfully resolved + @return ...any -- The values the Promise resolved or rejected with. +]=] +function Promise.prototype:await() + return awaitHelper(self:awaitStatus()) +end + +local function expectHelper(status, ...) + if status ~= Promise.Status.Resolved then + error((...) == nil and "Expected Promise rejected with no value." or (...), 3) + end + + return ... +end + +--[=[ + Yields the current thread until the given Promise completes. Returns the values that the promise resolved with. + + ```lua + local worked = pcall(function() + print("got", getTheValue():expect()) + end) + + if not worked then + warn("it failed") + end + ``` + + This is essentially sugar for: + + ```lua + select(2, assert(promise:await())) + ``` + + **Errors** if the Promise rejects or gets cancelled. + + @error any -- Errors with the rejection value if this Promise rejects or gets cancelled. + @yields + @return ...any -- The values the Promise resolved with. +]=] +function Promise.prototype:expect() + return expectHelper(self:awaitStatus()) +end + +-- Backwards compatibility +Promise.prototype.awaitValue = Promise.prototype.expect + +--[[ + Intended for use in tests. + + Similar to await(), but instead of yielding if the promise is unresolved, + _unwrap will throw. This indicates an assumption that a promise has + resolved. +]] +function Promise.prototype:_unwrap() + if self._status == Promise.Status.Started then + error("Promise has not resolved or rejected.", 2) + end + + local success = self._status == Promise.Status.Resolved + + return success, unpack(self._values, 1, self._valuesLength) +end + +function Promise.prototype:_resolve(...) + if self._status ~= Promise.Status.Started then + if Promise.is((...)) then + (...):_consumerCancelled(self) + end + return + end + + -- If the resolved value was a Promise, we chain onto it! + if Promise.is((...)) then + -- Without this warning, arguments sometimes mysteriously disappear + if select("#", ...) > 1 then + local message = string.format( + "When returning a Promise from andThen, extra arguments are " .. "discarded! See:\n\n%s", + self._source + ) + warn(message) + end + + local chainedPromise = ... + + local promise = chainedPromise:andThen(function(...) + self:_resolve(...) + end, function(...) + local maybeRuntimeError = chainedPromise._values[1] + + -- Backwards compatibility < v2 + if chainedPromise._error then + maybeRuntimeError = Error.new({ + error = chainedPromise._error, + kind = Error.Kind.ExecutionError, + context = "[No stack trace available as this Promise originated from an older version of the Promise library (< v2)]", + }) + end + + if Error.isKind(maybeRuntimeError, Error.Kind.ExecutionError) then + return self:_reject(maybeRuntimeError:extend({ + error = "This Promise was chained to a Promise that errored.", + trace = "", + context = string.format( + "The Promise at:\n\n%s\n...Rejected because it was chained to the following Promise, which encountered an error:\n", + self._source + ), + })) + end + + self:_reject(...) + end) + + if promise._status == Promise.Status.Cancelled then + self:cancel() + elseif promise._status == Promise.Status.Started then + -- Adopt ourselves into promise for cancellation propagation. + self._parent = promise + promise._consumers[self] = true + end + + return + end + + self._status = Promise.Status.Resolved + self._valuesLength, self._values = pack(...) + + -- We assume that these callbacks will not throw errors. + for _, callback in ipairs(self._queuedResolve) do + coroutine.wrap(callback)(...) + end + + self:_finalize() +end + +function Promise.prototype:_reject(...) + if self._status ~= Promise.Status.Started then + return + end + + self._status = Promise.Status.Rejected + self._valuesLength, self._values = pack(...) + + -- If there are any rejection handlers, call those! + if not isEmpty(self._queuedReject) then + -- We assume that these callbacks will not throw errors. + for _, callback in ipairs(self._queuedReject) do + coroutine.wrap(callback)(...) + end + else + -- At this point, no one was able to observe the error. + -- An error handler might still be attached if the error occurred + -- synchronously. We'll wait one tick, and if there are still no + -- observers, then we should put a message in the console. + + local err = tostring((...)) + + coroutine.wrap(function() + Promise._timeEvent:Wait() + + -- Someone observed the error, hooray! + if not self._unhandledRejection then + return + end + + -- Build a reasonable message + local message = string.format("Unhandled Promise rejection:\n\n%s\n\n%s", err, self._source) + + for _, callback in ipairs(Promise._unhandledRejectionCallbacks) do + task.spawn(callback, self, unpack(self._values, 1, self._valuesLength)) + end + + if Promise.TEST then + -- Don't spam output when we're running tests. + return + end + + warn(message) + end)() + end + + self:_finalize() +end + +--[[ + Calls any :finally handlers. We need this to be a separate method and + queue because we must call all of the finally callbacks upon a success, + failure, *and* cancellation. +]] +function Promise.prototype:_finalize() + for _, callback in ipairs(self._queuedFinally) do + -- Purposefully not passing values to callbacks here, as it could be the + -- resolved values, or rejected errors. If the developer needs the values, + -- they should use :andThen or :catch explicitly. + coroutine.wrap(callback)(self._status) + end + + self._queuedFinally = nil + self._queuedReject = nil + self._queuedResolve = nil + + -- Clear references to other Promises to allow gc + if not Promise.TEST then + self._parent = nil + self._consumers = nil + end + + task.defer(coroutine.close, self._thread) +end + +--[=[ + Chains a Promise from this one that is resolved if this Promise is already resolved, and rejected if it is not resolved at the time of calling `:now()`. This can be used to ensure your `andThen` handler occurs on the same frame as the root Promise execution. + + ```lua + doSomething() + :now() + :andThen(function(value) + print("Got", value, "synchronously.") + end) + ``` + + If this Promise is still running, Rejected, or Cancelled, the Promise returned from `:now()` will reject with the `rejectionValue` if passed, otherwise with a `Promise.Error(Promise.Error.Kind.NotResolvedInTime)`. This can be checked with [[Error.isKind]]. + + @param rejectionValue? any -- The value to reject with if the Promise isn't resolved + @return Promise +]=] +function Promise.prototype:now(rejectionValue) + local traceback = debug.traceback(nil, 2) + if self._status == Promise.Status.Resolved then + return self:_andThen(traceback, function(...) + return ... + end) + else + return Promise.reject(rejectionValue == nil and Error.new({ + kind = Error.Kind.NotResolvedInTime, + error = "This Promise was not resolved in time for :now()", + context = ":now() was called at:\n\n" .. traceback, + }) or rejectionValue) + end +end + +--[=[ + Repeatedly calls a Promise-returning function up to `times` number of times, until the returned Promise resolves. + + If the amount of retries is exceeded, the function will return the latest rejected Promise. + + ```lua + local function canFail(a, b, c) + return Promise.new(function(resolve, reject) + -- do something that can fail + + local failed, thing = doSomethingThatCanFail(a, b, c) + + if failed then + reject("it failed") + else + resolve(thing) + end + end) + end + + local MAX_RETRIES = 10 + local value = Promise.retry(canFail, MAX_RETRIES, "foo", "bar", "baz") -- args to send to canFail + ``` + + @since 3.0.0 + @param callback (...: P) -> Promise + @param times number + @param ...? P + @return Promise +]=] +function Promise.retry(callback, times, ...) + assert(isCallable(callback), "Parameter #1 to Promise.retry must be a function") + assert(type(times) == "number", "Parameter #2 to Promise.retry must be a number") + + local args, length = { ... }, select("#", ...) + + return Promise.resolve(callback(...)):catch(function(...) + if times > 0 then + return Promise.retry(callback, times - 1, unpack(args, 1, length)) + else + return Promise.reject(...) + end + end) +end + +--[=[ + Repeatedly calls a Promise-returning function up to `times` number of times, waiting `seconds` seconds between each + retry, until the returned Promise resolves. + + If the amount of retries is exceeded, the function will return the latest rejected Promise. + + @since v3.2.0 + @param callback (...: P) -> Promise + @param times number + @param seconds number + @param ...? P + @return Promise +]=] +function Promise.retryWithDelay(callback, times, seconds, ...) + assert(isCallable(callback), "Parameter #1 to Promise.retry must be a function") + assert(type(times) == "number", "Parameter #2 (times) to Promise.retry must be a number") + assert(type(seconds) == "number", "Parameter #3 (seconds) to Promise.retry must be a number") + + local args, length = { ... }, select("#", ...) + + return Promise.resolve(callback(...)):catch(function(...) + if times > 0 then + Promise.delay(seconds):await() + + return Promise.retryWithDelay(callback, times - 1, seconds, unpack(args, 1, length)) + else + return Promise.reject(...) + end + end) +end + +--[=[ + Converts an event into a Promise which resolves the next time the event fires. + + The optional `predicate` callback, if passed, will receive the event arguments and should return `true` or `false`, based on if this fired event should resolve the Promise or not. If `true`, the Promise resolves. If `false`, nothing happens and the predicate will be rerun the next time the event fires. + + The Promise will resolve with the event arguments. + + :::tip + This function will work given any object with a `Connect` method. This includes all Roblox events. + ::: + + ```lua + -- Creates a Promise which only resolves when `somePart` is touched + -- by a part named `"Something specific"`. + return Promise.fromEvent(somePart.Touched, function(part) + return part.Name == "Something specific" + end) + ``` + + @since 3.0.0 + @param event Event -- Any object with a `Connect` method. This includes all Roblox events. + @param predicate? (...: P) -> boolean -- A function which determines if the Promise should resolve with the given value, or wait for the next event to check again. + @return Promise

+]=] +function Promise.fromEvent(event, predicate) + predicate = predicate or function() + return true + end + + return Promise._new(debug.traceback(nil, 2), function(resolve, _, onCancel) + local connection + local shouldDisconnect = false + + local function disconnect() + connection:Disconnect() + connection = nil + end + + -- We use shouldDisconnect because if the callback given to Connect is called before + -- Connect returns, connection will still be nil. This happens with events that queue up + -- events when there's nothing connected, such as RemoteEvents + + connection = event:Connect(function(...) + local callbackValue = predicate(...) + + if callbackValue == true then + resolve(...) + + if connection then + disconnect() + else + shouldDisconnect = true + end + elseif type(callbackValue) ~= "boolean" then + error("Promise.fromEvent predicate should always return a boolean") + end + end) + + if shouldDisconnect and connection then + return disconnect() + end + + onCancel(disconnect) + end) +end + +--[=[ + Registers a callback that runs when an unhandled rejection happens. An unhandled rejection happens when a Promise + is rejected, and the rejection is not observed with `:catch`. + + The callback is called with the actual promise that rejected, followed by the rejection values. + + @since v3.2.0 + @param callback (promise: Promise, ...: any) -- A callback that runs when an unhandled rejection happens. + @return () -> () -- Function that unregisters the `callback` when called +]=] +function Promise.onUnhandledRejection(callback) + table.insert(Promise._unhandledRejectionCallbacks, callback) + + return function() + local index = table.find(Promise._unhandledRejectionCallbacks, callback) + + if index then + table.remove(Promise._unhandledRejectionCallbacks, index) + end + end +end + +return Promise diff --git a/include/RuntimeLib.lua b/include/RuntimeLib.lua new file mode 100644 index 0000000..1236bfa --- /dev/null +++ b/include/RuntimeLib.lua @@ -0,0 +1,260 @@ +local Promise = require(script.Parent.Promise) + +local RunService = game:GetService("RunService") + +local OUTPUT_PREFIX = "roblox-ts: " +local NODE_MODULES = "node_modules" +local DEFAULT_SCOPE = "@rbxts" + +local TS = {} + +TS.Promise = Promise + +local function isPlugin(context) + return RunService:IsStudio() and context:FindFirstAncestorWhichIsA("Plugin") ~= nil +end + +function TS.getModule(context, scope, moduleName) + -- legacy call signature + if moduleName == nil then + moduleName = scope + scope = DEFAULT_SCOPE + end + + -- ensure modules have fully replicated + if RunService:IsRunning() and RunService:IsClient() and not isPlugin(context) and not game:IsLoaded() then + game.Loaded:Wait() + end + + local object = context + repeat + local nodeModulesFolder = object:FindFirstChild(NODE_MODULES) + if nodeModulesFolder then + local scopeFolder = nodeModulesFolder:FindFirstChild(scope) + if scopeFolder then + local module = scopeFolder:FindFirstChild(moduleName) + if module then + return module + end + end + end + object = object.Parent + until object == nil + + error(OUTPUT_PREFIX .. "Could not find module: " .. moduleName, 2) +end + +-- This is a hash which TS.import uses as a kind of linked-list-like history of [Script who Loaded] -> Library +local currentlyLoading = {} +local registeredLibraries = {} + +function TS.import(context, module, ...) + for i = 1, select("#", ...) do + module = module:WaitForChild((select(i, ...))) + end + + if module.ClassName ~= "ModuleScript" then + error(OUTPUT_PREFIX .. "Failed to import! Expected ModuleScript, got " .. module.ClassName, 2) + end + + currentlyLoading[context] = module + + -- Check to see if a case like this occurs: + -- module -> Module1 -> Module2 -> module + + -- WHERE currentlyLoading[module] is Module1 + -- and currentlyLoading[Module1] is Module2 + -- and currentlyLoading[Module2] is module + + local currentModule = module + local depth = 0 + + while currentModule do + depth = depth + 1 + currentModule = currentlyLoading[currentModule] + + if currentModule == module then + local str = currentModule.Name -- Get the string traceback + + for _ = 1, depth do + currentModule = currentlyLoading[currentModule] + str = str .. " ⇒ " .. currentModule.Name + end + + error(OUTPUT_PREFIX .. "Failed to import! Detected a circular dependency chain: " .. str, 2) + end + end + + if not registeredLibraries[module] then + if _G[module] then + error( + OUTPUT_PREFIX + .. "Invalid module access! Do you have multiple TS runtimes trying to import this? " + .. module:GetFullName(), + 2 + ) + end + + _G[module] = TS + registeredLibraries[module] = true -- register as already loaded for subsequent calls + end + + local data = require(module) + + if currentlyLoading[context] == module then -- Thread-safe cleanup! + currentlyLoading[context] = nil + end + + return data +end + +function TS.instanceof(obj, class) + -- custom Class.instanceof() check + if type(class) == "table" and type(class.instanceof) == "function" then + return class.instanceof(obj) + end + + -- metatable check + if type(obj) == "table" then + obj = getmetatable(obj) + while obj ~= nil do + if obj == class then + return true + end + local mt = getmetatable(obj) + if mt then + obj = mt.__index + else + obj = nil + end + end + end + + return false +end + +function TS.async(callback) + return function(...) + local n = select("#", ...) + local args = { ... } + return Promise.new(function(resolve, reject) + coroutine.wrap(function() + local ok, result = pcall(callback, unpack(args, 1, n)) + if ok then + resolve(result) + else + reject(result) + end + end)() + end) + end +end + +function TS.await(promise) + if not Promise.is(promise) then + return promise + end + + local status, value = promise:awaitStatus() + if status == Promise.Status.Resolved then + return value + elseif status == Promise.Status.Rejected then + error(value, 2) + else + error("The awaited Promise was cancelled", 2) + end +end + +local SIGN = 2 ^ 31 +local COMPLEMENT = 2 ^ 32 +local function bit_sign(num) + -- Restores the sign after an unsigned conversion according to 2s complement. + if bit32.btest(num, SIGN) then + return num - COMPLEMENT + else + return num + end +end + +function TS.bit_lrsh(a, b) + return bit_sign(bit32.arshift(a, b)) +end + +TS.TRY_RETURN = 1 +TS.TRY_BREAK = 2 +TS.TRY_CONTINUE = 3 + +function TS.try(try, catch, finally) + -- execute try + local trySuccess, exitTypeOrTryError, returns = pcall(try) + local exitType, tryError + if trySuccess then + exitType = exitTypeOrTryError + else + tryError = exitTypeOrTryError + end + + local catchSuccess = true + local catchError + + -- if try block failed, and catch block exists, execute catch + if not trySuccess and catch then + local newExitTypeOrCatchError, newReturns + catchSuccess, newExitTypeOrCatchError, newReturns = pcall(catch, tryError) + local newExitType + if catchSuccess then + newExitType = newExitTypeOrCatchError + else + catchError = newExitTypeOrCatchError + end + + if newExitType then + exitType, returns = newExitType, newReturns + end + end + + -- execute finally + if finally then + local newExitType, newReturns = finally() + if newExitType then + exitType, returns = newExitType, newReturns + end + end + + -- if exit type is a control flow, do not rethrow errors + if exitType ~= TS.TRY_RETURN and exitType ~= TS.TRY_BREAK and exitType ~= TS.TRY_CONTINUE then + -- if catch block threw an error, rethrow it + if not catchSuccess then + error(catchError, 2) + end + + -- if try block threw an error and there was no catch block, rethrow it + if not trySuccess and not catch then + error(tryError, 2) + end + end + + return exitType, returns +end + +function TS.generator(callback) + local co = coroutine.create(callback) + return { + next = function(...) + if coroutine.status(co) == "dead" then + return { done = true } + else + local success, value = coroutine.resume(co, ...) + if success == false then + error(value, 2) + end + return { + value = value, + done = coroutine.status(co) == "dead", + } + end + end, + } +end + +return TS diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..13a88d3 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,2562 @@ +{ + "name": "next_station_plugin", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "next_station_plugin", + "version": "1.0.0", + "license": "ISC", + "devDependencies": { + "@rbxts/compiler-types": "^3.0.0-types.0", + "@rbxts/types": "^1.0.881", + "@typescript-eslint/eslint-plugin": "^8.43.0", + "@typescript-eslint/parser": "^8.43.0", + "eslint": "^9.35.0", + "eslint-config-prettier": "^10.1.8", + "eslint-plugin-prettier": "^5.5.4", + "eslint-plugin-roblox-ts": "^1.1.0", + "prettier": "^3.6.2", + "roblox-ts": "^3.0.0", + "typescript": "^5.8.3" + } + }, + "node_modules/@eslint-community/eslint-utils": { + "version": "4.9.0", + "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.9.0.tgz", + "integrity": "sha512-ayVFHdtZ+hsq1t2Dy24wCmGXGe4q9Gu3smhLYALJrr473ZH27MsnSL+LKUlimp4BWJqMDMLmPpx/Q9R3OAlL4g==", + "dev": true, + "license": "MIT", + "dependencies": { + "eslint-visitor-keys": "^3.4.3" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" + } + }, + "node_modules/@eslint-community/regexpp": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.12.1.tgz", + "integrity": "sha512-CCZCDJuduB9OUkFkY2IgppNZMi2lBQgD2qzwXkEia16cge2pijY/aXi96CJMquDMn3nJdlPV1A5KrJEXwfLNzQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.0.0 || ^14.0.0 || >=16.0.0" + } + }, + "node_modules/@eslint/config-array": { + "version": "0.21.0", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.21.0.tgz", + "integrity": "sha512-ENIdc4iLu0d93HeYirvKmrzshzofPw6VkZRKQGe9Nv46ZnWUzcF1xV01dcvEg/1wXUR61OmmlSfyeyO7EvjLxQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@eslint/object-schema": "^2.1.6", + "debug": "^4.3.1", + "minimatch": "^3.1.2" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/config-array/node_modules/brace-expansion": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", + "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/@eslint/config-array/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/@eslint/config-helpers": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@eslint/config-helpers/-/config-helpers-0.3.1.tgz", + "integrity": "sha512-xR93k9WhrDYpXHORXpxVL5oHj3Era7wo6k/Wd8/IsQNnZUTzkGS29lyn3nAT05v6ltUuTFVCCYDEGfy2Or/sPA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/core": { + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.15.2.tgz", + "integrity": "sha512-78Md3/Rrxh83gCxoUc0EiciuOHsIITzLy53m3d9UyiW8y9Dj2D29FeETqyKA+BRK76tnTp6RXWb3pCay8Oyomg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@types/json-schema": "^7.0.15" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/eslintrc": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.3.1.tgz", + "integrity": "sha512-gtF186CXhIl1p4pJNGZw8Yc6RlshoePRvE0X91oPGb3vZ8pM3qOS9W9NGPat9LziaBV7XrJWGylNQXkGcnM3IQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ajv": "^6.12.4", + "debug": "^4.3.2", + "espree": "^10.0.1", + "globals": "^14.0.0", + "ignore": "^5.2.0", + "import-fresh": "^3.2.1", + "js-yaml": "^4.1.0", + "minimatch": "^3.1.2", + "strip-json-comments": "^3.1.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@eslint/eslintrc/node_modules/brace-expansion": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", + "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/@eslint/eslintrc/node_modules/ignore": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", + "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 4" + } + }, + "node_modules/@eslint/eslintrc/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/@eslint/js": { + "version": "9.35.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.35.0.tgz", + "integrity": "sha512-30iXE9whjlILfWobBkNerJo+TXYsgVM5ERQwMcMKCHckHflCmf7wXDAHlARoWnh0s1U72WqlbeyE7iAcCzuCPw==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://eslint.org/donate" + } + }, + "node_modules/@eslint/object-schema": { + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.6.tgz", + "integrity": "sha512-RBMg5FRL0I0gs51M/guSAj5/e14VQ4tpZnQNWwuDT66P14I43ItmPfIZRhO9fUVIPOAQXU47atlywZ/czoqFPA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/plugin-kit": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.3.5.tgz", + "integrity": "sha512-Z5kJ+wU3oA7MMIqVR9tyZRtjYPr4OC004Q4Rw7pgOKUOKkJfZ3O24nz3WYfGRpMDNmcOi3TwQOmgm7B7Tpii0w==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@eslint/core": "^0.15.2", + "levn": "^0.4.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@humanfs/core": { + "version": "0.19.1", + "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz", + "integrity": "sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18.0" + } + }, + "node_modules/@humanfs/node": { + "version": "0.16.7", + "resolved": "https://registry.npmjs.org/@humanfs/node/-/node-0.16.7.tgz", + "integrity": "sha512-/zUx+yOsIrG4Y43Eh2peDeKCxlRt/gET6aHfaKpuq267qXdYDFViVHfMaLyygZOnl0kGWxFIgsBy8QFuTLUXEQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanfs/core": "^0.19.1", + "@humanwhocodes/retry": "^0.4.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, + "node_modules/@humanwhocodes/module-importer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", + "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.22" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, + "node_modules/@humanwhocodes/retry": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.4.3.tgz", + "integrity": "sha512-bV0Tgo9K4hfPCek+aMAn81RppFKv2ySDQeMoSZuvTASywNTnVJCArCZE2FWqpvIatKu7VMRLWlR1EazvVhDyhQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, + "node_modules/@nodelib/fs.scandir": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", + "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@nodelib/fs.stat": "2.0.5", + "run-parallel": "^1.1.9" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.stat": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", + "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.walk": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", + "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@nodelib/fs.scandir": "2.1.5", + "fastq": "^1.6.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@pkgr/core": { + "version": "0.2.9", + "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.2.9.tgz", + "integrity": "sha512-QNqXyfVS2wm9hweSYD2O7F0G06uurj9kZ96TRQE5Y9hU7+tgdZwIkbAKc5Ocy1HxEY2kuDQa6cQ1WRs/O5LFKA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.20.0 || ^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/pkgr" + } + }, + "node_modules/@rbxts/compiler-types": { + "version": "3.0.0-types.0", + "resolved": "https://registry.npmjs.org/@rbxts/compiler-types/-/compiler-types-3.0.0-types.0.tgz", + "integrity": "sha512-VGOHJPoL7+56NTatMGqQj3K7xWuzEV+aP4QD5vZiHu+bcff3kiTmtoadaF6NkJrmwfFAvbsd4Dg764ZjWNceag==", + "dev": true, + "license": "MIT" + }, + "node_modules/@rbxts/types": { + "version": "1.0.881", + "resolved": "https://registry.npmjs.org/@rbxts/types/-/types-1.0.881.tgz", + "integrity": "sha512-Dz5XHJBhvhhDMsHUp0HOQ3rbZTypvTpS2pIAdHfXneUyJbBIJGAXGbUQa3A1AsFAIpN6M6FW0mVkg7LnKOCPNw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@roblox-ts/luau-ast": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@roblox-ts/luau-ast/-/luau-ast-2.0.0.tgz", + "integrity": "sha512-cmMi093IdwBOLVxwuordhM8AmtbyTIyRpsTbB0D/JauidW4SXsQRQowSwWjHo4QP0DRJBXvOIlxtqEQi50uNzQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@roblox-ts/path-translator": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@roblox-ts/path-translator/-/path-translator-1.1.0.tgz", + "integrity": "sha512-D0akTmnNYqBw+ZIek5JxocT3BjmbgGOuOy0x1nIIxHBPNLGCpzseToY8jyYs/0mlvnN2xnSP/k8Tv+jvGOQSwQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ajv": "^8.12.0", + "fs-extra": "^11.2.0" + } + }, + "node_modules/@roblox-ts/path-translator/node_modules/ajv": { + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", + "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/@roblox-ts/path-translator/node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "dev": true, + "license": "MIT" + }, + "node_modules/@roblox-ts/rojo-resolver": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@roblox-ts/rojo-resolver/-/rojo-resolver-1.1.0.tgz", + "integrity": "sha512-QmvVryu1EeME+3QUoG5j/gHGJoJUaffCgZ92mhlG7cJSd1uyhgpY4CNWriZAwZJYkTlzd5Htkpn+18yDFbOFXA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ajv": "^8.17.1", + "fs-extra": "^11.2.0" + } + }, + "node_modules/@roblox-ts/rojo-resolver/node_modules/ajv": { + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", + "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/@roblox-ts/rojo-resolver/node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/estree": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", + "integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@typescript-eslint/eslint-plugin": { + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.43.0.tgz", + "integrity": "sha512-8tg+gt7ENL7KewsKMKDHXR1vm8tt9eMxjJBYINf6swonlWgkYn5NwyIgXpbbDxTNU5DgpDFfj95prcTq2clIQQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/regexpp": "^4.10.0", + "@typescript-eslint/scope-manager": "8.43.0", + "@typescript-eslint/type-utils": "8.43.0", + "@typescript-eslint/utils": "8.43.0", + "@typescript-eslint/visitor-keys": "8.43.0", + "graphemer": "^1.4.0", + "ignore": "^7.0.0", + "natural-compare": "^1.4.0", + "ts-api-utils": "^2.1.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "@typescript-eslint/parser": "^8.43.0", + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <6.0.0" + } + }, + "node_modules/@typescript-eslint/parser": { + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.43.0.tgz", + "integrity": "sha512-B7RIQiTsCBBmY+yW4+ILd6mF5h1FUwJsVvpqkrgpszYifetQ2Ke+Z4u6aZh0CblkUGIdR59iYVyXqqZGkZ3aBw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/scope-manager": "8.43.0", + "@typescript-eslint/types": "8.43.0", + "@typescript-eslint/typescript-estree": "8.43.0", + "@typescript-eslint/visitor-keys": "8.43.0", + "debug": "^4.3.4" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <6.0.0" + } + }, + "node_modules/@typescript-eslint/project-service": { + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.43.0.tgz", + "integrity": "sha512-htB/+D/BIGoNTQYffZw4uM4NzzuolCoaA/BusuSIcC8YjmBYQioew5VUZAYdAETPjeed0hqCaW7EHg+Robq8uw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/tsconfig-utils": "^8.43.0", + "@typescript-eslint/types": "^8.43.0", + "debug": "^4.3.4" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.0.0" + } + }, + "node_modules/@typescript-eslint/scope-manager": { + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.43.0.tgz", + "integrity": "sha512-daSWlQ87ZhsjrbMLvpuuMAt3y4ba57AuvadcR7f3nl8eS3BjRc8L9VLxFLk92RL5xdXOg6IQ+qKjjqNEimGuAg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.43.0", + "@typescript-eslint/visitor-keys": "8.43.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/tsconfig-utils": { + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.43.0.tgz", + "integrity": "sha512-ALC2prjZcj2YqqL5X/bwWQmHA2em6/94GcbB/KKu5SX3EBDOsqztmmX1kMkvAJHzxk7TazKzJfFiEIagNV3qEA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.0.0" + } + }, + "node_modules/@typescript-eslint/type-utils": { + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.43.0.tgz", + "integrity": "sha512-qaH1uLBpBuBBuRf8c1mLJ6swOfzCXryhKND04Igr4pckzSEW9JX5Aw9AgW00kwfjWJF0kk0ps9ExKTfvXfw4Qg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.43.0", + "@typescript-eslint/typescript-estree": "8.43.0", + "@typescript-eslint/utils": "8.43.0", + "debug": "^4.3.4", + "ts-api-utils": "^2.1.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <6.0.0" + } + }, + "node_modules/@typescript-eslint/types": { + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.43.0.tgz", + "integrity": "sha512-vQ2FZaxJpydjSZJKiSW/LJsabFFvV7KgLC5DiLhkBcykhQj8iK9BOaDmQt74nnKdLvceM5xmhaTF+pLekrxEkw==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/typescript-estree": { + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.43.0.tgz", + "integrity": "sha512-7Vv6zlAhPb+cvEpP06WXXy/ZByph9iL6BQRBDj4kmBsW98AqEeQHlj/13X+sZOrKSo9/rNKH4Ul4f6EICREFdw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/project-service": "8.43.0", + "@typescript-eslint/tsconfig-utils": "8.43.0", + "@typescript-eslint/types": "8.43.0", + "@typescript-eslint/visitor-keys": "8.43.0", + "debug": "^4.3.4", + "fast-glob": "^3.3.2", + "is-glob": "^4.0.3", + "minimatch": "^9.0.4", + "semver": "^7.6.0", + "ts-api-utils": "^2.1.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.0.0" + } + }, + "node_modules/@typescript-eslint/utils": { + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.43.0.tgz", + "integrity": "sha512-S1/tEmkUeeswxd0GGcnwuVQPFWo8NzZTOMxCvw8BX7OMxnNae+i8Tm7REQen/SwUIPoPqfKn7EaZ+YLpiB3k9g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/eslint-utils": "^4.7.0", + "@typescript-eslint/scope-manager": "8.43.0", + "@typescript-eslint/types": "8.43.0", + "@typescript-eslint/typescript-estree": "8.43.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <6.0.0" + } + }, + "node_modules/@typescript-eslint/visitor-keys": { + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.43.0.tgz", + "integrity": "sha512-T+S1KqRD4sg/bHfLwrpF/K3gQLBM1n7Rp7OjjikjTEssI2YJzQpi5WXoynOaQ93ERIuq3O8RBTOUYDKszUCEHw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.43.0", + "eslint-visitor-keys": "^4.2.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/visitor-keys/node_modules/eslint-visitor-keys": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.1.tgz", + "integrity": "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/acorn": { + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", + "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-jsx": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", + "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, + "node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "license": "MIT", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dev": true, + "license": "ISC", + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true, + "license": "Python-2.0" + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true, + "license": "MIT" + }, + "node_modules/binary-extensions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", + "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/brace-expansion": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", + "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/braces": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "dev": true, + "license": "MIT", + "dependencies": { + "fill-range": "^7.1.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/chokidar": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "dev": true, + "license": "MIT", + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/chokidar/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "dev": true, + "license": "ISC", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true, + "license": "MIT" + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true, + "license": "MIT" + }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dev": true, + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/deep-is": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true, + "license": "MIT" + }, + "node_modules/escalade": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", + "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/eslint": { + "version": "9.35.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.35.0.tgz", + "integrity": "sha512-QePbBFMJFjgmlE+cXAlbHZbHpdFVS2E/6vzCy7aKlebddvl1vadiC4JFV5u/wqTkNUwEV8WrQi257jf5f06hrg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/eslint-utils": "^4.8.0", + "@eslint-community/regexpp": "^4.12.1", + "@eslint/config-array": "^0.21.0", + "@eslint/config-helpers": "^0.3.1", + "@eslint/core": "^0.15.2", + "@eslint/eslintrc": "^3.3.1", + "@eslint/js": "9.35.0", + "@eslint/plugin-kit": "^0.3.5", + "@humanfs/node": "^0.16.6", + "@humanwhocodes/module-importer": "^1.0.1", + "@humanwhocodes/retry": "^0.4.2", + "@types/estree": "^1.0.6", + "@types/json-schema": "^7.0.15", + "ajv": "^6.12.4", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.6", + "debug": "^4.3.2", + "escape-string-regexp": "^4.0.0", + "eslint-scope": "^8.4.0", + "eslint-visitor-keys": "^4.2.1", + "espree": "^10.4.0", + "esquery": "^1.5.0", + "esutils": "^2.0.2", + "fast-deep-equal": "^3.1.3", + "file-entry-cache": "^8.0.0", + "find-up": "^5.0.0", + "glob-parent": "^6.0.2", + "ignore": "^5.2.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "lodash.merge": "^4.6.2", + "minimatch": "^3.1.2", + "natural-compare": "^1.4.0", + "optionator": "^0.9.3" + }, + "bin": { + "eslint": "bin/eslint.js" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://eslint.org/donate" + }, + "peerDependencies": { + "jiti": "*" + }, + "peerDependenciesMeta": { + "jiti": { + "optional": true + } + } + }, + "node_modules/eslint-config-prettier": { + "version": "10.1.8", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-10.1.8.tgz", + "integrity": "sha512-82GZUjRS0p/jganf6q1rEO25VSoHH0hKPCTrgillPjdI/3bgBhAE1QzHrHTizjpRvy6pGAvKjDJtk2pF9NDq8w==", + "dev": true, + "license": "MIT", + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "funding": { + "url": "https://opencollective.com/eslint-config-prettier" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, + "node_modules/eslint-plugin-prettier": { + "version": "5.5.4", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.5.4.tgz", + "integrity": "sha512-swNtI95SToIz05YINMA6Ox5R057IMAmWZ26GqPxusAp1TZzj+IdY9tXNWWD3vkF/wEqydCONcwjTFpxybBqZsg==", + "dev": true, + "license": "MIT", + "dependencies": { + "prettier-linter-helpers": "^1.0.0", + "synckit": "^0.11.7" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint-plugin-prettier" + }, + "peerDependencies": { + "@types/eslint": ">=8.0.0", + "eslint": ">=8.0.0", + "eslint-config-prettier": ">= 7.0.0 <10.0.0 || >=10.1.0", + "prettier": ">=3.0.0" + }, + "peerDependenciesMeta": { + "@types/eslint": { + "optional": true + }, + "eslint-config-prettier": { + "optional": true + } + } + }, + "node_modules/eslint-plugin-roblox-ts": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-roblox-ts/-/eslint-plugin-roblox-ts-1.1.0.tgz", + "integrity": "sha512-VsT+m6hEH7+KRsHvI3ixApFcT9H4PhInohM37cffySjv0XGtak1QojNRz4K+CEYYk90masVISZG+9SMCRwLAbw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/type-utils": "8.36.0", + "@typescript-eslint/utils": "8.36.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=22.5.1" + }, + "peerDependencies": { + "eslint": ">=8.0.0", + "typescript": ">=5.2.0 <5.9.0" + } + }, + "node_modules/eslint-plugin-roblox-ts/node_modules/@typescript-eslint/project-service": { + "version": "8.36.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.36.0.tgz", + "integrity": "sha512-JAhQFIABkWccQYeLMrHadu/fhpzmSQ1F1KXkpzqiVxA/iYI6UnRt2trqXHt1sYEcw1mxLnB9rKMsOxXPxowN/g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/tsconfig-utils": "^8.36.0", + "@typescript-eslint/types": "^8.36.0", + "debug": "^4.3.4" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <5.9.0" + } + }, + "node_modules/eslint-plugin-roblox-ts/node_modules/@typescript-eslint/scope-manager": { + "version": "8.36.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.36.0.tgz", + "integrity": "sha512-wCnapIKnDkN62fYtTGv2+RY8FlnBYA3tNm0fm91kc2BjPhV2vIjwwozJ7LToaLAyb1ca8BxrS7vT+Pvvf7RvqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.36.0", + "@typescript-eslint/visitor-keys": "8.36.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/eslint-plugin-roblox-ts/node_modules/@typescript-eslint/tsconfig-utils": { + "version": "8.36.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.36.0.tgz", + "integrity": "sha512-Nhh3TIEgN18mNbdXpd5Q8mSCBnrZQeY9V7Ca3dqYvNDStNIGRmJA6dmrIPMJ0kow3C7gcQbpsG2rPzy1Ks/AnA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <5.9.0" + } + }, + "node_modules/eslint-plugin-roblox-ts/node_modules/@typescript-eslint/type-utils": { + "version": "8.36.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.36.0.tgz", + "integrity": "sha512-5aaGYG8cVDd6cxfk/ynpYzxBRZJk7w/ymto6uiyUFtdCozQIsQWh7M28/6r57Fwkbweng8qAzoMCPwSJfWlmsg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/typescript-estree": "8.36.0", + "@typescript-eslint/utils": "8.36.0", + "debug": "^4.3.4", + "ts-api-utils": "^2.1.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <5.9.0" + } + }, + "node_modules/eslint-plugin-roblox-ts/node_modules/@typescript-eslint/types": { + "version": "8.36.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.36.0.tgz", + "integrity": "sha512-xGms6l5cTJKQPZOKM75Dl9yBfNdGeLRsIyufewnxT4vZTrjC0ImQT4fj8QmtJK84F58uSh5HVBSANwcfiXxABQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/eslint-plugin-roblox-ts/node_modules/@typescript-eslint/typescript-estree": { + "version": "8.36.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.36.0.tgz", + "integrity": "sha512-JaS8bDVrfVJX4av0jLpe4ye0BpAaUW7+tnS4Y4ETa3q7NoZgzYbN9zDQTJ8kPb5fQ4n0hliAt9tA4Pfs2zA2Hg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/project-service": "8.36.0", + "@typescript-eslint/tsconfig-utils": "8.36.0", + "@typescript-eslint/types": "8.36.0", + "@typescript-eslint/visitor-keys": "8.36.0", + "debug": "^4.3.4", + "fast-glob": "^3.3.2", + "is-glob": "^4.0.3", + "minimatch": "^9.0.4", + "semver": "^7.6.0", + "ts-api-utils": "^2.1.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <5.9.0" + } + }, + "node_modules/eslint-plugin-roblox-ts/node_modules/@typescript-eslint/utils": { + "version": "8.36.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.36.0.tgz", + "integrity": "sha512-VOqmHu42aEMT+P2qYjylw6zP/3E/HvptRwdn/PZxyV27KhZg2IOszXod4NcXisWzPAGSS4trE/g4moNj6XmH2g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/eslint-utils": "^4.7.0", + "@typescript-eslint/scope-manager": "8.36.0", + "@typescript-eslint/types": "8.36.0", + "@typescript-eslint/typescript-estree": "8.36.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <5.9.0" + } + }, + "node_modules/eslint-plugin-roblox-ts/node_modules/@typescript-eslint/visitor-keys": { + "version": "8.36.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.36.0.tgz", + "integrity": "sha512-vZrhV2lRPWDuGoxcmrzRZyxAggPL+qp3WzUrlZD+slFueDiYHxeBa34dUXPuC0RmGKzl4lS5kFJYvKCq9cnNDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.36.0", + "eslint-visitor-keys": "^4.2.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/eslint-plugin-roblox-ts/node_modules/eslint-visitor-keys": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.1.tgz", + "integrity": "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint-scope": { + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.4.0.tgz", + "integrity": "sha512-sNXOfKCn74rt8RICKMvJS7XKV/Xk9kA7DyJr8mJik3S7Cwgy3qlkkmyS2uQB3jiJg6VNdZd/pDBJu0nvG2NlTg==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^5.2.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint-visitor-keys": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint/node_modules/brace-expansion": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", + "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/eslint/node_modules/eslint-visitor-keys": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.1.tgz", + "integrity": "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint/node_modules/ignore": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", + "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 4" + } + }, + "node_modules/eslint/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/espree": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-10.4.0.tgz", + "integrity": "sha512-j6PAQ2uUr79PZhBjP5C5fhl8e39FmRnOjsD5lGnWrFU8i2G776tBK7+nP8KuQUTTyAZUwfQqXAgrVH5MbH9CYQ==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "acorn": "^8.15.0", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^4.2.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/espree/node_modules/eslint-visitor-keys": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.1.tgz", + "integrity": "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/esquery": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.6.0.tgz", + "integrity": "sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "estraverse": "^5.1.0" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/esrecurse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", + "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "estraverse": "^5.2.0" + }, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/estraverse": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=4.0" + } + }, + "node_modules/esutils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/fast-diff": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz", + "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", + "dev": true, + "license": "Apache-2.0" + }, + "node_modules/fast-glob": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz", + "integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.8" + }, + "engines": { + "node": ">=8.6.0" + } + }, + "node_modules/fast-glob/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true, + "license": "MIT" + }, + "node_modules/fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", + "dev": true, + "license": "MIT" + }, + "node_modules/fast-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.0.tgz", + "integrity": "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/fastq": { + "version": "1.19.1", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.19.1.tgz", + "integrity": "sha512-GwLTyxkCXjXbxqIhTsMI2Nui8huMPtnxg7krajPJAjnEG/iiOS7i+zCtWGZR9G0NBKbXKh6X9m9UIsYX/N6vvQ==", + "dev": true, + "license": "ISC", + "dependencies": { + "reusify": "^1.0.4" + } + }, + "node_modules/file-entry-cache": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", + "integrity": "sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "flat-cache": "^4.0.0" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/fill-range": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "dev": true, + "license": "MIT", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/find-up": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "dev": true, + "license": "MIT", + "dependencies": { + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/flat-cache": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-4.0.1.tgz", + "integrity": "sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw==", + "dev": true, + "license": "MIT", + "dependencies": { + "flatted": "^3.2.9", + "keyv": "^4.5.4" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/flatted": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.3.tgz", + "integrity": "sha512-GX+ysw4PBCz0PzosHDepZGANEuFCMLrnRTiEy9McGjmkCQYwRq4A/X786G/fjM/+OjsWSU1ZrY5qyARZmO/uwg==", + "dev": true, + "license": "ISC" + }, + "node_modules/fs-extra": { + "version": "11.3.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.3.1.tgz", + "integrity": "sha512-eXvGGwZ5CL17ZSwHWd3bbgk7UUpF6IFHtP57NYYakPvHOs8GDgDe5KJI36jIJzDkJ6eJjuzRA8eBQb6SkKue0g==", + "dev": true, + "license": "MIT", + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=14.14" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "dev": true, + "license": "ISC", + "engines": { + "node": "6.* || 8.* || >= 10.*" + } + }, + "node_modules/glob-parent": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", + "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.3" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/globals": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/graceful-fs": { + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", + "dev": true, + "license": "ISC" + }, + "node_modules/graphemer": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", + "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", + "dev": true, + "license": "MIT" + }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ignore": { + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.5.tgz", + "integrity": "sha512-Hs59xBNfUIunMFgWAbGX5cq6893IbWg4KnrjbYwX3tx0ztorVgTDA6B2sxf8ejHJ4wz8BqGUMYlnzNBer5NvGg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 4" + } + }, + "node_modules/import-fresh": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.1.tgz", + "integrity": "sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.8.19" + } + }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "license": "MIT", + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-core-module": { + "version": "2.16.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.1.tgz", + "integrity": "sha512-UfoeMA6fIJ8wTYFEUjelnaGI67v6+N7qXJEvQuIGa99l4xsCruSYOVSQ0uPANn4dAzm8lkYPaKLrrijLq7x23w==", + "dev": true, + "license": "MIT", + "dependencies": { + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true, + "license": "ISC" + }, + "node_modules/js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dev": true, + "license": "MIT", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/json-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", + "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true, + "license": "MIT" + }, + "node_modules/json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", + "dev": true, + "license": "MIT" + }, + "node_modules/jsonfile": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.0.tgz", + "integrity": "sha512-FGuPw30AdOIUTRMC2OMRtQV+jkVj2cfPqSeWXv1NEAJ1qZ5zb1X6z1mFhbfOB/iy3ssJCD+3KuZ8r8C3uVFlAg==", + "dev": true, + "license": "MIT", + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/keyv": { + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", + "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", + "dev": true, + "license": "MIT", + "dependencies": { + "json-buffer": "3.0.1" + } + }, + "node_modules/kleur": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.5.tgz", + "integrity": "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/locate-path": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "dev": true, + "license": "MIT", + "dependencies": { + "p-locate": "^5.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 8" + } + }, + "node_modules/micromatch": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", + "dev": true, + "license": "MIT", + "dependencies": { + "braces": "^3.0.3", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=8.6" + } + }, + "node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, + "license": "MIT" + }, + "node_modules/natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", + "dev": true, + "license": "MIT" + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/optionator": { + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", + "integrity": "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==", + "dev": true, + "license": "MIT", + "dependencies": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.5" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/p-limit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "yocto-queue": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "dev": true, + "license": "MIT", + "dependencies": { + "p-limit": "^3.0.2" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "license": "MIT", + "dependencies": { + "callsites": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "dev": true, + "license": "MIT" + }, + "node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/prettier": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.6.2.tgz", + "integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-diff": "^1.1.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/queue-microtask": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", + "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "license": "MIT", + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, + "node_modules/require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/resolve": { + "version": "1.22.10", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.10.tgz", + "integrity": "sha512-NPRy+/ncIMeDlTAsuqwKIiferiawhefFJtkNSW0qZJEqMEb+qBt/77B/jGeeek+F0uOeN05CDa6HXbbIgtVX4w==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-core-module": "^2.16.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/reusify": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz", + "integrity": "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==", + "dev": true, + "license": "MIT", + "engines": { + "iojs": ">=1.0.0", + "node": ">=0.10.0" + } + }, + "node_modules/roblox-ts": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/roblox-ts/-/roblox-ts-3.0.0.tgz", + "integrity": "sha512-hwAC2frIFlLJOtHd6F+5opMEhBgfAMK9z5l1mP+bykLBbMO5cn1q5lIwhhXbeh9Pq07rlhF8uGHlmeRLPd/3AA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@roblox-ts/luau-ast": "=2.0.0", + "@roblox-ts/path-translator": "=1.1.0", + "@roblox-ts/rojo-resolver": "=1.1.0", + "chokidar": "^3.6.0", + "fs-extra": "^11.2.0", + "kleur": "^4.1.5", + "resolve": "^1.22.6", + "typescript": "=5.5.3", + "yargs": "^17.7.2" + }, + "bin": { + "rbxtsc": "out/CLI/cli.js" + } + }, + "node_modules/roblox-ts/node_modules/typescript": { + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", + "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/run-parallel": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", + "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "queue-microtask": "^1.2.2" + } + }, + "node_modules/semver": { + "version": "7.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", + "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/synckit": { + "version": "0.11.11", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.11.11.tgz", + "integrity": "sha512-MeQTA1r0litLUf0Rp/iisCaL8761lKAZHaimlbGK4j0HysC4PLfqygQj9srcs0m2RdtDYnF8UuYyKpbjHYp7Jw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@pkgr/core": "^0.2.9" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/synckit" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/ts-api-utils": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.1.0.tgz", + "integrity": "sha512-CUgTZL1irw8u29bzrOD/nH85jqyc74D6SshFgujOIA7osm2Rz7dYH77agkx7H4FBNxDq7Cjf+IjaX/8zwFW+ZQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18.12" + }, + "peerDependencies": { + "typescript": ">=4.8.4" + } + }, + "node_modules/type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, + "license": "MIT", + "dependencies": { + "prelude-ls": "^1.2.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/typescript": { + "version": "5.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz", + "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/uri-js": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "punycode": "^2.1.0" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/word-wrap": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/y18n": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=10" + } + }, + "node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "dev": true, + "license": "MIT", + "dependencies": { + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=12" + } + }, + "node_modules/yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..f16753a --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "next_station_plugin", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "build": "rbxtsc", + "watch": "rbxtsc -w" + }, + "keywords": [], + "author": "", + "license": "ISC", + "type": "commonjs", + "devDependencies": { + "@rbxts/compiler-types": "^3.0.0-types.0", + "@rbxts/types": "^1.0.881", + "@typescript-eslint/eslint-plugin": "^8.43.0", + "@typescript-eslint/parser": "^8.43.0", + "eslint": "^9.35.0", + "eslint-config-prettier": "^10.1.8", + "eslint-plugin-prettier": "^5.5.4", + "eslint-plugin-roblox-ts": "^1.1.0", + "prettier": "^3.6.2", + "roblox-ts": "^3.0.0", + "typescript": "^5.8.3" + } +} diff --git a/serve.project.json b/serve.project.json new file mode 100644 index 0000000..bafc516 --- /dev/null +++ b/serve.project.json @@ -0,0 +1,16 @@ +{ + "name": "roblox-ts-plugin-serve", + "globIgnorePaths": [ + "**/package.json", + "**/tsconfig.json" + ], + "tree": { + "$className": "DataModel", + "ServerScriptService": { + "$className": "ServerScriptService", + "Plugin": { + "$path": "./default.project.json" + } + } + } +} diff --git a/src/Adornment/Area.ts b/src/Adornment/Area.ts new file mode 100644 index 0000000..2b042e3 --- /dev/null +++ b/src/Adornment/Area.ts @@ -0,0 +1,65 @@ +import { createAnchor } from "Utils/Gui"; +import { Handles } from "./Handles"; + +function areaSphereAdornment(model: Folder, anchor: Part) { + const sphereAdornment = new Instance("SphereHandleAdornment"); + sphereAdornment.Adornee = anchor; + sphereAdornment.AlwaysOnTop = true; + sphereAdornment.ZIndex = 5; + sphereAdornment.Color3 = new Color3(1, 0, 0); + sphereAdornment.Transparency = 0.8; + sphereAdornment.Radius = 0.4; + sphereAdornment.Parent = model; + return sphereAdornment; +} + +export class HandlesArea { + originHandles: Handles; + originAdornment: SphereHandleAdornment; + originAnchor: Part; + originValueChanged; + + tipHandles: Handles; + tipAdornment: SphereHandleAdornment; + tipAnchor: Part; + tipValueChanged; + + box: BoxHandleAdornment; + boxAnchor: Part; + constructor(model: Folder, firstPos: Vector3, secondPos: Vector3) { + this.originHandles = new Handles(model, firstPos); + this.originAnchor = this.originHandles.anchor; + this.originAdornment = areaSphereAdornment(model, this.originHandles.anchor); + this.tipHandles = new Handles(model, secondPos); + this.tipAnchor = this.tipHandles.anchor; + this.tipAdornment = areaSphereAdornment(model, this.tipHandles.anchor); + + // create the box + const boxSize = secondPos.sub(firstPos); + const boxCenter = firstPos.add(boxSize.div(2)); + this.boxAnchor = createAnchor(model, boxCenter); + const box = new Instance("BoxHandleAdornment"); + box.Adornee = this.boxAnchor; + box.AlwaysOnTop = true; + box.ZIndex = 5; + box.Color3 = new Color3(1, 0, 0); + box.Transparency = 0.8; + box.Size = new Vector3(math.abs(boxSize.X), math.abs(boxSize.Y), math.abs(boxSize.Z)); + box.Parent = model; + this.box = box; + + // Function + this.originAnchor.GetPropertyChangedSignal("Position").Connect(() => this.updateBox()); + this.tipAnchor.GetPropertyChangedSignal("Position").Connect(() => this.updateBox()); + this.originValueChanged = this.originHandles.valueChanged; + this.tipValueChanged = this.tipHandles.valueChanged; + } + updateBox() { + const origin = this.originAnchor.Position; + const tip = this.tipAnchor.Position; + const boxSize = tip.sub(origin); + const boxCenter = origin.add(boxSize.div(2)); + this.boxAnchor.Position = boxCenter; + this.box.Size = new Vector3(math.abs(boxSize.X), math.abs(boxSize.Y), math.abs(boxSize.Z)); + } +} diff --git a/src/Adornment/Handles.ts b/src/Adornment/Handles.ts new file mode 100644 index 0000000..0f2b0ec --- /dev/null +++ b/src/Adornment/Handles.ts @@ -0,0 +1,51 @@ +import Signal from "@rbxts/signal"; +import { createAnchor } from "Utils/Gui"; + +export class Handles { + currentVector: Vector3 = new Vector3(); + anchor: Part; + valueChanged = new Signal<(newValue: Vector3) => void>(); + + constructor(model: Folder, startPosition: Vector3 = Vector3.zero, anchor = createAnchor(model, startPosition)) { + this.anchor = anchor; + + const handles = new Instance("Handles"); + handles.Adornee = this.anchor; + handles.Parent = model; + handles.MouseButton1Down.Connect(() => { + this.currentVector = this.anchor.Position; + }); + handles.MouseDrag.Connect((face, distance) => { + // Apply the changes to the anchor's position + let offset = Vector3.zero; + + switch (face) { + case Enum.NormalId.Right: + offset = new Vector3(distance, 0, 0); + break; + case Enum.NormalId.Left: + offset = new Vector3(-distance, 0, 0); + break; + case Enum.NormalId.Top: + offset = new Vector3(0, distance, 0); + break; + case Enum.NormalId.Bottom: + offset = new Vector3(0, -distance, 0); + break; + case Enum.NormalId.Front: + offset = new Vector3(0, 0, -distance); + break; + case Enum.NormalId.Back: + offset = new Vector3(0, 0, distance); + break; + } + + this.anchor.Position = this.currentVector.add(offset); + }); + + handles.MouseButton1Up.Connect(() => { + const newpos = this.anchor.Position; + this.valueChanged.Fire(newpos); + }); + } +} diff --git a/src/Lualibs/CollapsibleTitledSection.d.ts b/src/Lualibs/CollapsibleTitledSection.d.ts new file mode 100644 index 0000000..69276ab --- /dev/null +++ b/src/Lualibs/CollapsibleTitledSection.d.ts @@ -0,0 +1,13 @@ +declare class CollapsibleTitledSection { + constructor( + nameSuffix: string, + titleText: string, + autoScalingList?: boolean, + minimizable?: boolean, + minimizedByDefault?: boolean, + ); + GetSectionFrame(): Instance; + GetContentsFrame(): Instance; + SetCollapsedState(minimized: boolean): void; +} +export = CollapsibleTitledSection; diff --git a/src/Lualibs/CollapsibleTitledSection.lua b/src/Lualibs/CollapsibleTitledSection.lua new file mode 100644 index 0000000..d4842fa --- /dev/null +++ b/src/Lualibs/CollapsibleTitledSection.lua @@ -0,0 +1,168 @@ +---------------------------------------- +-- +-- CollapsibleTitledSectionClass +-- +-- Creates a section with a title label: +-- +-- "SectionXXX" +-- "TitleBarVisual" +-- "Contents" +-- +-- Requires "parent" and "sectionName" parameters and returns the section and its contentsFrame +-- The entire frame will resize dynamically as contents frame changes size. +-- +-- "autoScalingList" is a boolean that defines wheter or not the content frame automatically resizes when children are added. +-- This is important for cases when you want minimize button to push or contract what is below it. +-- +-- Both "minimizeable" and "minimizedByDefault" are false by default +-- These parameters define if the section will have an arrow button infront of the title label, +-- which the user may use to hide the section's contents +-- +---------------------------------------- +GuiUtilities = require(script.Parent.GuiUtilities) + +local kRightButtonAsset = "rbxasset://textures/TerrainTools/button_arrow.png" +local kDownButtonAsset = "rbxasset://textures/TerrainTools/button_arrow_down.png" + +local kArrowSize = 9 +local kDoubleClickTimeSec = 0.5 + +CollapsibleTitledSectionClass = {} +CollapsibleTitledSectionClass.__index = CollapsibleTitledSectionClass + + +function CollapsibleTitledSectionClass.new(nameSuffix, titleText, autoScalingList, minimizable, minimizedByDefault) + local self = {} + setmetatable(self, CollapsibleTitledSectionClass) + + self._minimized = minimizedByDefault + self._minimizable = minimizable + + self._titleBarHeight = GuiUtilities.kTitleBarHeight + + local frame = Instance.new('Frame') + frame.Name = 'CTSection' .. nameSuffix + frame.BackgroundTransparency = 1 + self._frame = frame + + local uiListLayout = Instance.new('UIListLayout') + uiListLayout.SortOrder = Enum.SortOrder.LayoutOrder + uiListLayout.Parent = frame + self._uiListLayout = uiListLayout + + local contentsFrame = Instance.new('Frame') + contentsFrame.Name = 'Contents' + contentsFrame.BackgroundTransparency = 1 + contentsFrame.Size = UDim2.new(1, 0, 0, 1) + contentsFrame.Position = UDim2.new(0, 0, 0, titleBarSize) + contentsFrame.Parent = frame + contentsFrame.LayoutOrder = 2 + GuiUtilities.syncGuiElementBackgroundColor(contentsFrame) + + self._contentsFrame = contentsFrame + + uiListLayout:GetPropertyChangedSignal('AbsoluteContentSize'):connect(function() + self:_UpdateSize() + end) + self:_UpdateSize() + + self:_CreateTitleBar(titleText) + self:SetCollapsedState(self._minimized) + + if (autoScalingList) then + GuiUtilities.MakeFrameAutoScalingList(self:GetContentsFrame()) + end + + return self +end + + +function CollapsibleTitledSectionClass:GetSectionFrame() + return self._frame +end + +function CollapsibleTitledSectionClass:GetContentsFrame() + return self._contentsFrame +end + +function CollapsibleTitledSectionClass:_UpdateSize() + local totalSize = self._uiListLayout.AbsoluteContentSize.Y + self._frame.Size = UDim2.new(1, 0, 0, totalSize) +end + +function CollapsibleTitledSectionClass:_UpdateMinimizeButton() + -- We can't rotate it because rotated images don't get clipped by parents. + -- This is all in a scroll widget. + -- :( + if (self._minimized) then + self._minimizeButton.Image = kRightButtonAsset + else + self._minimizeButton.Image = kDownButtonAsset + end +end + +function CollapsibleTitledSectionClass:SetCollapsedState(bool) + self._minimized = bool + self._contentsFrame.Visible = not bool + self:_UpdateMinimizeButton() + self:_UpdateSize() +end + +function CollapsibleTitledSectionClass:_ToggleCollapsedState() + self:SetCollapsedState(not self._minimized) +end + +function CollapsibleTitledSectionClass:_CreateTitleBar(titleText) + local titleTextOffset = self._titleBarHeight + + local titleBar = Instance.new('ImageButton') + titleBar.AutoButtonColor = false + titleBar.Name = 'TitleBarVisual' + titleBar.BorderSizePixel = 0 + titleBar.Position = UDim2.new(0, 0, 0, 0) + titleBar.Size = UDim2.new(1, 0, 0, self._titleBarHeight) + titleBar.Parent = self._frame + titleBar.LayoutOrder = 1 + GuiUtilities.syncGuiElementTitleColor(titleBar) + + local titleLabel = Instance.new('TextLabel') + titleLabel.Name = 'TitleLabel' + titleLabel.BackgroundTransparency = 1 + titleLabel.Font = Enum.Font.SourceSansBold --todo: input spec font + titleLabel.TextSize = 15 --todo: input spec font size + titleLabel.TextXAlignment = Enum.TextXAlignment.Left + titleLabel.Text = titleText + titleLabel.Position = UDim2.new(0, titleTextOffset, 0, 0) + titleLabel.Size = UDim2.new(1, -titleTextOffset, 1, GuiUtilities.kTextVerticalFudge) + titleLabel.Parent = titleBar + GuiUtilities.syncGuiElementFontColor(titleLabel) + + self._minimizeButton = Instance.new('ImageButton') + self._minimizeButton.Name = 'MinimizeSectionButton' + self._minimizeButton.Image = kRightButtonAsset --todo: input arrow image from spec + self._minimizeButton.Size = UDim2.new(0, kArrowSize, 0, kArrowSize) + self._minimizeButton.AnchorPoint = Vector2.new(0.5, 0.5) + self._minimizeButton.Position = UDim2.new(0, self._titleBarHeight*.5, + 0, self._titleBarHeight*.5) + self._minimizeButton.BackgroundTransparency = 1 + self._minimizeButton.Visible = self._minimizable -- only show when minimizable + + self._minimizeButton.MouseButton1Down:connect(function() + self:_ToggleCollapsedState() + end) + self:_UpdateMinimizeButton() + self._minimizeButton.Parent = titleBar + + self._latestClickTime = 0 + titleBar.MouseButton1Down:connect(function() + local now = tick() + if (now - self._latestClickTime < kDoubleClickTimeSec) then + self:_ToggleCollapsedState() + self._latestClickTime = 0 + else + self._latestClickTime = now + end + end) +end + +return CollapsibleTitledSectionClass \ No newline at end of file diff --git a/src/Lualibs/CustomTextButton.d.ts b/src/Lualibs/CustomTextButton.d.ts new file mode 100644 index 0000000..d7bbc15 --- /dev/null +++ b/src/Lualibs/CustomTextButton.d.ts @@ -0,0 +1,5 @@ +declare class CustomTextButtonClass { + constructor(buttonName: string, labelText: string); + GetButton(): Instance; +} +export = CustomTextButtonClass; diff --git a/src/Lualibs/CustomTextButton.lua b/src/Lualibs/CustomTextButton.lua new file mode 100644 index 0000000..2d19062 --- /dev/null +++ b/src/Lualibs/CustomTextButton.lua @@ -0,0 +1,94 @@ +---------------------------------------- +-- +-- CustomTextButton.lua +-- +-- Creates text button with custom look & feel, hover/click effects. +-- +---------------------------------------- +GuiUtilities = require(script.Parent.GuiUtilities) + +local kButtonImageIdDefault = "rbxasset://textures/TerrainTools/button_default.png" +local kButtonImageIdHovered = "rbxasset://textures/TerrainTools/button_hover.png" +local kButtonImageIdPressed = "rbxasset://textures/TerrainTools/button_pressed.png" + +CustomTextButtonClass = {} +CustomTextButtonClass.__index = CustomTextButtonClass + +function CustomTextButtonClass.new(buttonName, labelText) + local self = {} + setmetatable(self, CustomTextButtonClass) + + local button = Instance.new('ImageButton') + button.Name = buttonName + button.Image = kButtonImageIdDefault + button.BackgroundTransparency = 1 + button.ScaleType = Enum.ScaleType.Slice + button.SliceCenter = Rect.new(7, 7, 156, 36) + button.AutoButtonColor = false + + local label = Instance.new('TextLabel') + label.Text = labelText + label.BackgroundTransparency = 1 + label.Size = UDim2.new(1, 0, 1, GuiUtilities.kButtonVerticalFudge) + label.Font = Enum.Font.SourceSans + label.TextSize = 15 + label.Parent = button + + self._label = label + self._button = button + + self._clicked = false + self._hovered = false + + button.InputBegan:connect(function(input) + if (input.UserInputType == Enum.UserInputType.MouseMovement) then + self._hovered = true + self:_updateButtonVisual() + end + end) + + + button.InputEnded:connect(function(input) + if (input.UserInputType == Enum.UserInputType.MouseMovement) then + self._hovered = false + self._clicked = false + self:_updateButtonVisual() + end + end) + + button.MouseButton1Down:connect(function() + self._clicked = true + self:_updateButtonVisual() + end) + + button.MouseButton1Up:connect(function() + self._clicked = false + self:_updateButtonVisual() + end) + + self:_updateButtonVisual() + + return self +end + +function CustomTextButtonClass:_updateButtonVisual() + if (self._clicked) then + self._button.Image = kButtonImageIdPressed + self._label.TextColor3 = GuiUtilities.kPressedButtonTextColor + elseif (self._hovered) then + self._button.Image = kButtonImageIdHovered + self._label.TextColor3 = GuiUtilities.kStandardButtonTextColor + else + self._button.Image = kButtonImageIdDefault + self._label.TextColor3 = GuiUtilities.kStandardButtonTextColor + end +end + +-- Backwards compatibility (should be removed in the future) +-- CustomTextButtonClass.getButton = CustomTextButtonClass.GetButton + +function CustomTextButtonClass:GetButton() + return self._button +end + +return CustomTextButtonClass \ No newline at end of file diff --git a/src/Lualibs/GuiUtilities.lua b/src/Lualibs/GuiUtilities.lua new file mode 100644 index 0000000..8c7fe54 --- /dev/null +++ b/src/Lualibs/GuiUtilities.lua @@ -0,0 +1,247 @@ +local module = {} + + +module.kTitleBarHeight = 27 +module.kInlineTitleBarHeight = 24 + +module.kStandardContentAreaWidth = 180 + +module.kStandardPropertyHeight = 30 +module.kSubSectionLabelHeight = 30 + +module.kStandardVMargin = 7 +module.kStandardHMargin = 16 + +module.kCheckboxMinLabelWidth = 52 +module.kCheckboxMinMargin = 12 +module.kCheckboxWidth = 12 + +module.kRadioButtonsHPadding = 24 + +module.StandardLineLabelLeftMargin = module.kTitleBarHeight +module.StandardLineElementLeftMargin = (module.StandardLineLabelLeftMargin + module.kCheckboxMinLabelWidth ++ module.kCheckboxMinMargin + module.kCheckboxWidth + module.kRadioButtonsHPadding) +module.StandardLineLabelWidth = (module.StandardLineElementLeftMargin - module.StandardLineLabelLeftMargin - 10 ) + +module.kDropDownHeight = 55 + +module.kBottomButtonsFrameHeight = 50 +module.kBottomButtonsHeight = 28 + +module.kShapeButtonSize = 32 +module.kTextVerticalFudge = -3 +module.kButtonVerticalFudge = -5 + +module.kBottomButtonsWidth = 100 + +module.kDisabledTextColor = Color3.new(.4, .4, .4) --todo: input spec disabled text color +module.kStandardButtonTextColor = Color3.new(0, 0, 0) --todo: input spec disabled text color +module.kPressedButtonTextColor = Color3.new(1, 1, 1) --todo: input spec disabled text color + +module.kButtonStandardBackgroundColor = Color3.new(1, 1, 1) --todo: sync with spec +module.kButtonStandardBorderColor = Color3.new(.4,.4,.4) --todo: sync with spec +module.kButtonDisabledBackgroundColor = Color3.new(.7,.7,.7) --todo: sync with spec +module.kButtonDisabledBorderColor = Color3.new(.6,.6,.6) --todo: sync with spec + +module.kButtonBackgroundTransparency = 0.5 +module.kButtonBackgroundIntenseTransparency = 0.4 + +module.kMainFrame = nil + +function module.ShouldUseIconsForDarkerBackgrounds() + local mainColor = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainBackground) + return (mainColor.r + mainColor.g + mainColor.b) / 3 < 0.5 +end + +function module.SetMainFrame(frame) + module.kMainFrame = frame +end + +function module.syncGuiElementTitleColor(guiElement) + local function setColors() + guiElement.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.Titlebar) + end + settings().Studio.ThemeChanged:connect(setColors) + setColors() +end + +function module.syncGuiElementInputFieldColor(guiElement) + local function setColors() + guiElement.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.InputFieldBackground) + end + settings().Studio.ThemeChanged:connect(setColors) + setColors() +end + +function module.syncGuiElementBackgroundColor(guiElement) + local function setColors() + guiElement.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainBackground) + end + settings().Studio.ThemeChanged:connect(setColors) + setColors() +end + +function module.syncGuiElementStripeColor(guiElement) + local function setColors() + if ((guiElement.LayoutOrder + 1) % 2 == 0) then + guiElement.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainBackground) + else + guiElement.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.CategoryItem) + end + end + settings().Studio.ThemeChanged:connect(setColors) + setColors() +end + +function module.syncGuiElementBorderColor(guiElement) + local function setColors() + guiElement.BorderColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.Border) + end + settings().Studio.ThemeChanged:connect(setColors) + setColors() +end + +function module.syncGuiElementFontColor(guiElement) + local function setColors() + guiElement.TextColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainText) + end + settings().Studio.ThemeChanged:connect(setColors) + setColors() +end + +function module.syncGuiElementScrollColor(guiElement) + local function setColors() + guiElement.ScrollBarImageColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.ScrollBar) + end + settings().Studio.ThemeChanged:connect(setColors) + setColors() +end + +-- A frame with standard styling. +function module.MakeFrame(name) + local frame = Instance.new("Frame") + frame.Name = name + frame.BackgroundTransparency = 0 + frame.BorderSizePixel = 0 + + module.syncGuiElementBackgroundColor(frame) + + return frame +end + + +-- A frame that is a whole line, containing some arbitrary sized widget. +function module.MakeFixedHeightFrame(name, height) + local frame = module.MakeFrame(name) + frame.Size = UDim2.new(1, 0, 0, height) + + return frame +end + +-- A frame that is one standard-sized line, containing some standard-sized widget (label, edit box, dropdown, +-- checkbox) +function module.MakeStandardFixedHeightFrame(name) + return module.MakeFixedHeightFrame(name, module.kStandardPropertyHeight) +end + +function module.AdjustHeightDynamicallyToLayout(frame, uiLayout, optPadding) + if (not optPadding) then + optPadding = 0 + end + + local function updateSizes() + frame.Size = UDim2.new(1, 0, 0, uiLayout.AbsoluteContentSize.Y + optPadding) + end + uiLayout:GetPropertyChangedSignal("AbsoluteContentSize"):connect(updateSizes) + updateSizes() +end + +-- Assumes input frame has a List layout with sort order layout order. +-- Add frames in order as siblings of list layout, they will be laid out in order. +-- Color frame background accordingly. +function module.AddStripedChildrenToListFrame(listFrame, frames) + for index, frame in ipairs(frames) do + frame.Parent = listFrame + frame.LayoutOrder = index + frame.BackgroundTransparency = 0 + frame.BorderSizePixel = 1 + module.syncGuiElementStripeColor(frame) + module.syncGuiElementBorderColor(frame) + end +end + +local function MakeSectionInternal(parentGui, name, title, contentHeight) + local frame = Instance.new("Frame") + frame.Name = name + frame.BackgroundTransparency = 1 + frame.Parent = parentGui + frame.BackgroundTransparency = 1 + frame.BorderSizePixel = 0 + + -- If title is "nil', no title bar. + local contentYOffset = 0 + local titleBar = nil + if (title ~= nil) then + local titleBarFrame = Instance.new("Frame") + titleBarFrame.Name = "TitleBarFrame" + titleBarFrame.Parent = frame + titleBarFrame.Position = UDim2.new(0, 0, 0, 0) + titleBarFrame.LayoutOrder = 0 + + local titleBar = Instance.new("TextLabel") + titleBar.Name = "TitleBarLabel" + titleBar.Text = title + titleBar.Parent = titleBarFrame + titleBar.BackgroundTransparency = 1 + titleBar.Position = UDim2.new(0, module.kStandardHMargin, 0, 0) + + module.syncGuiElementFontColor(titleBar) + + contentYOffset = contentYOffset + module.kTitleBarHeight + end + + frame.Size = UDim2.new(1, 0, 0, contentYOffset + contentHeight) + + return frame +end + +function module.MakeStandardPropertyLabel(text, opt_ignoreThemeUpdates) + local label = Instance.new('TextLabel') + label.Name = 'Label' + label.BackgroundTransparency = 1 + label.Font = Enum.Font.SourceSans --todo: input spec font + label.TextSize = 15 --todo: input spec font size + label.TextXAlignment = Enum.TextXAlignment.Left + label.Text = text + label.AnchorPoint = Vector2.new(0, 0.5) + label.Position = UDim2.new(0, module.StandardLineLabelLeftMargin, 0.5, module.kTextVerticalFudge) + label.Size = UDim2.new(0, module.StandardLineLabelWidth, 1, 0) + + if (not opt_ignoreThemeUpdates) then + module.syncGuiElementFontColor(label) + end + + return label +end + +function module.MakeFrameWithSubSectionLabel(name, text) + local row = module.MakeFixedHeightFrame(name, module.kSubSectionLabelHeight) + row.BackgroundTransparency = 1 + + local label = module.MakeStandardPropertyLabel(text) + label.BackgroundTransparency = 1 + label.Parent = row + + return row +end + +function module.MakeFrameAutoScalingList(frame) + local uiListLayout = Instance.new("UIListLayout") + uiListLayout.Parent = frame + uiListLayout.SortOrder = Enum.SortOrder.LayoutOrder + + module.AdjustHeightDynamicallyToLayout(frame, uiListLayout) +end + + +return module \ No newline at end of file diff --git a/src/Lualibs/ImageButtonWithText.d.ts b/src/Lualibs/ImageButtonWithText.d.ts new file mode 100644 index 0000000..a55be2e --- /dev/null +++ b/src/Lualibs/ImageButtonWithText.d.ts @@ -0,0 +1,17 @@ +declare class ImageButtonWithTextClass { + constructor( + name: string, + layoutOrder: number, + icon: string, + text: string, + buttonSize: UDim2, + imageSize: UDim2, + imagePos: UDim2, + textSize: UDim2, + textPos: UDim2, + ); + GetButton(): Instance; + SetSelected(selected: boolean): void; + GetSelected(): boolean; +} +export = ImageButtonWithTextClass; diff --git a/src/Lualibs/ImageButtonWithText.lua b/src/Lualibs/ImageButtonWithText.lua new file mode 100644 index 0000000..ae57bfc --- /dev/null +++ b/src/Lualibs/ImageButtonWithText.lua @@ -0,0 +1,158 @@ +---------------------------------------- +-- +-- ImageButtonWithText.lua +-- +-- An image button with text underneath. Standardized hover, clicked, and +-- selected states. +-- +---------------------------------------- +GuiUtilities = require(script.Parent.GuiUtilities) + +ImageButtonWithTextClass = {} +ImageButtonWithTextClass.__index = ImageButtonWithTextClass + +local kSelectedBaseTransparency = 0.2 +local kAdditionalTransparency = 0.1 + +function ImageButtonWithTextClass.new(name, + layoutOrder, + icon, + text, + buttonSize, + imageSize, + imagePos, + textSize, + textPos) + local self = {} + setmetatable(self, ImageButtonWithTextClass) + + local button = Instance.new("ImageButton") + button.Name = name + button.AutoButtonColor = false + button.Size = buttonSize + button.BorderSizePixel = 1 + -- Image-with-text button has translucent background and "selected" background color. + -- When selected we set transluency to not-zero so we see selected color. + button.BackgroundTransparency = 1 + + button.LayoutOrder = layoutOrder + + local buttonIcon = Instance.new("ImageLabel") + buttonIcon.BackgroundTransparency = 1 + buttonIcon.Image = icon or "" + buttonIcon.Size = imageSize + buttonIcon.Position = imagePos + buttonIcon.Parent = button + + local textLabel = Instance.new("TextLabel") + textLabel.BackgroundTransparency = 1 + textLabel.Text = text + textLabel.Size = textSize + textLabel.Position = textPos + textLabel.TextScaled = true + textLabel.Font = Enum.Font.SourceSans + textLabel.Parent = button + + GuiUtilities.syncGuiElementFontColor(textLabel) + + local uiTextSizeConstraint = Instance.new("UITextSizeConstraint") + -- Spec asks for fontsize of 12 pixels, but in Roblox the text font sizes look smaller than the mock + --Note: For this font the Roblox text size is 25.7% larger than the design spec. + uiTextSizeConstraint.MaxTextSize = 15 + uiTextSizeConstraint.Parent = textLabel + + self._button = button + self._clicked = false + self._hovered = false + self._selected = false + + button.InputBegan:Connect(function(input) + if (input.UserInputType == Enum.UserInputType.MouseMovement) then + self._hovered = true + self:_updateButtonVisual() + end + end) + + + button.InputEnded:Connect(function(input) + if (input.UserInputType == Enum.UserInputType.MouseMovement) then + self._hovered = false + self._clicked = false + self:_updateButtonVisual() + end + end) + + button.MouseButton1Down:Connect(function() + self._clicked = true + self:_updateButtonVisual() + end) + + button.MouseButton1Up:Connect(function() + self._clicked = false + self:_updateButtonVisual() + end) + + function updateButtonVisual() + self:_updateButtonVisual() + end + settings().Studio.ThemeChanged:connect(updateButtonVisual) + + self:_updateButtonVisual() + + return self +end + +function ImageButtonWithTextClass:_updateButtonVisual() + -- Possibilties: + if (self._clicked) then + -- This covers 'clicked and selected' or 'clicked' + self._button.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.Button, + Enum.StudioStyleGuideModifier.Selected) + self._button.BorderColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.Border, + Enum.StudioStyleGuideModifier.Selected) + if (self._selected) then + self._button.BackgroundTransparency = GuiUtilities.kButtonBackgroundIntenseTransparency + else + self._button.BackgroundTransparency = GuiUtilities.kButtonBackgroundTransparency + end + elseif (self._hovered) then + -- This covers 'hovered and selected' or 'hovered' + self._button.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.Button, + Enum.StudioStyleGuideModifier.Hover) + self._button.BorderColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.Border, + Enum.StudioStyleGuideModifier.Hover) + if (self._selected) then + self._button.BackgroundTransparency = GuiUtilities.kButtonBackgroundIntenseTransparency + else + self._button.BackgroundTransparency = GuiUtilities.kButtonBackgroundTransparency + end + elseif (self._selected) then + -- This covers 'selected' + self._button.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.Button, + Enum.StudioStyleGuideModifier.Selected) + self._button.BorderColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.Border, + Enum.StudioStyleGuideModifier.Selected) + self._button.BackgroundTransparency = GuiUtilities.kButtonBackgroundTransparency + else + -- This covers 'no special state' + self._button.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.Button) + self._button.BorderColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.Border) + self._button.BackgroundTransparency = 1 + end +end + +function ImageButtonWithTextClass:GetButton() + return self._button +end + +function ImageButtonWithTextClass:SetSelected(selected) + self._selected = selected + self:_updateButtonVisual() +end + +function ImageButtonWithTextClass:GetSelected() + return self._selected +end + + +return ImageButtonWithTextClass \ No newline at end of file diff --git a/src/Lualibs/LabeledCheckbox.d.ts b/src/Lualibs/LabeledCheckbox.d.ts new file mode 100644 index 0000000..67af600 --- /dev/null +++ b/src/Lualibs/LabeledCheckbox.d.ts @@ -0,0 +1,14 @@ +declare class LabeledCheckboxClass { + constructor(nameSuffix: string, labelText: string, initValue?: boolean, initDisabled?: boolean); + GetFrame(): Instance; + GetValue(): boolean; + GetLabel(): Instance; + GetButton(): Instance; + SetValueChangedFunction(fn: (value: boolean) => void): void; + SetDisabled(disabled: boolean): void; + GetDisabled(): boolean; + SetValue(value: boolean): void; + UseSmallSize(): void; + DisableWithOverrideValue(overrideValue: boolean): void; +} +export = LabeledCheckboxClass; diff --git a/src/Lualibs/LabeledCheckbox.lua b/src/Lualibs/LabeledCheckbox.lua new file mode 100644 index 0000000..a214c43 --- /dev/null +++ b/src/Lualibs/LabeledCheckbox.lua @@ -0,0 +1,243 @@ +---------------------------------------- +-- +-- LabeledCheckbox.lua +-- +-- Creates a frame containing a label and a checkbox. +-- +---------------------------------------- +GuiUtilities = require(script.Parent.GuiUtilities) + +local kCheckboxWidth = GuiUtilities.kCheckboxWidth + +local kMinTextSize = 14 +local kMinHeight = 24 +local kMinLabelWidth = GuiUtilities.kCheckboxMinLabelWidth +local kMinMargin = GuiUtilities.kCheckboxMinMargin +local kMinButtonWidth = kCheckboxWidth; + +local kMinLabelSize = UDim2.new(0, kMinLabelWidth, 0, kMinHeight) +local kMinLabelPos = UDim2.new(0, kMinButtonWidth + kMinMargin, 0, kMinHeight/2) + +local kMinButtonSize = UDim2.new(0, kMinButtonWidth, 0, kMinButtonWidth) +local kMinButtonPos = UDim2.new(0, 0, 0, kMinHeight/2) + +local kCheckImageWidth = 8 +local kMinCheckImageWidth = kCheckImageWidth + +local kCheckImageSize = UDim2.new(0, kCheckImageWidth, 0, kCheckImageWidth) +local kMinCheckImageSize = UDim2.new(0, kMinCheckImageWidth, 0, kMinCheckImageWidth) + +local kEnabledCheckImage = "rbxasset://textures/TerrainTools/icon_tick.png" +local kDisabledCheckImage = "rbxasset://textures/TerrainTools/icon_tick_grey.png" +local kCheckboxFrameImage = "rbxasset://textures/TerrainTools/checkbox_square.png" +LabeledCheckboxClass = {} +LabeledCheckboxClass.__index = LabeledCheckboxClass + +LabeledCheckboxClass.kMinFrameSize = UDim2.new(0, kMinLabelWidth + kMinMargin + kMinButtonWidth, 0, kMinHeight) + + +function LabeledCheckboxClass.new(nameSuffix, labelText, initValue, initDisabled) + local self = {} + setmetatable(self, LabeledCheckboxClass) + + local initValue = not not initValue + local initDisabled = not not initDisabled + + local frame = GuiUtilities.MakeStandardFixedHeightFrame("CBF" .. nameSuffix) + + local fullBackgroundButton = Instance.new("TextButton") + fullBackgroundButton.Name = "FullBackground" + fullBackgroundButton.Parent = frame + fullBackgroundButton.BackgroundTransparency = 1 + fullBackgroundButton.Size = UDim2.new(1, 0, 1, 0) + fullBackgroundButton.Position = UDim2.new(0, 0, 0, 0) + fullBackgroundButton.Text = "" + + local label = GuiUtilities.MakeStandardPropertyLabel(labelText, true) + label.Parent = fullBackgroundButton + + local button = Instance.new('ImageButton') + button.Name = 'Button' + button.Size = UDim2.new(0, kCheckboxWidth, 0, kCheckboxWidth) + button.AnchorPoint = Vector2.new(0, .5) + button.BackgroundTransparency = 0 + button.Position = UDim2.new(0, GuiUtilities.StandardLineElementLeftMargin, .5, 0) + button.Parent = fullBackgroundButton + button.Image = kCheckboxFrameImage + button.BorderSizePixel = 0 + button.AutoButtonColor = false + + local checkImage = Instance.new("ImageLabel") + checkImage.Name = "CheckImage" + checkImage.Parent = button + checkImage.Image = kEnabledCheckImage + checkImage.Visible = false + checkImage.Size = kCheckImageSize + checkImage.AnchorPoint = Vector2.new(0.5, 0.5) + checkImage.Position = UDim2.new(0.5, 0, 0.5, 0) + checkImage.BackgroundTransparency = 1 + checkImage.BorderSizePixel = 0 + + self._frame = frame + self._button = button + self._label = label + self._checkImage = checkImage + self._fullBackgroundButton = fullBackgroundButton + self._useDisabledOverride = false + self._disabledOverride = false + self:SetDisabled(initDisabled) + + self._value = not initValue + self:SetValue(initValue) + + self:_SetupMouseClickHandling() + + local function updateFontColors() + self:UpdateFontColors() + end + settings().Studio.ThemeChanged:connect(updateFontColors) + updateFontColors() + + return self +end + + +function LabeledCheckboxClass:_MaybeToggleState() + if not self._disabled then + self:SetValue(not self._value) + end +end + +function LabeledCheckboxClass:_SetupMouseClickHandling() + self._button.MouseButton1Down:connect(function() + self:_MaybeToggleState() + end) + + self._fullBackgroundButton.MouseButton1Down:connect(function() + self:_MaybeToggleState() + end) +end + +function LabeledCheckboxClass:_HandleUpdatedValue() + self._checkImage.Visible = self:GetValue() + + if (self._valueChangedFunction) then + self._valueChangedFunction(self:GetValue()) + end +end + +-- Small checkboxes are a different entity. +-- All the bits are smaller. +-- Fixed width instead of flood-fill. +-- Box comes first, then label. +function LabeledCheckboxClass:UseSmallSize() + self._label.TextSize = kMinTextSize + self._label.Size = kMinLabelSize + self._label.Position = kMinLabelPos + self._label.TextXAlignment = Enum.TextXAlignment.Left + + self._button.Size = kMinButtonSize + self._button.Position = kMinButtonPos + + self._checkImage.Size = kMinCheckImageSize + + self._frame.Size = LabeledCheckboxClass.kMinFrameSize + self._frame.BackgroundTransparency = 1 +end + +function LabeledCheckboxClass:GetFrame() + return self._frame +end + +function LabeledCheckboxClass:GetValue() + -- If button is disabled, and we should be using a disabled override, + -- use the disabled override. + if (self._disabled and self._useDisabledOverride) then + return self._disabledOverride + else + return self._value + end +end + +function LabeledCheckboxClass:GetLabel() + return self._label +end + +function LabeledCheckboxClass:GetButton() + return self._button +end + +function LabeledCheckboxClass:SetValueChangedFunction(vcFunction) + self._valueChangedFunction = vcFunction +end + +function LabeledCheckboxClass:SetDisabled(newDisabled) + local newDisabled = not not newDisabled + + local originalValue = self:GetValue() + + if newDisabled ~= self._disabled then + self._disabled = newDisabled + + -- if we are no longer disabled, then we don't need or want + -- the override any more. Forget it. + if (not self._disabled) then + self._useDisabledOverride = false + end + + if (newDisabled) then + self._checkImage.Image = kDisabledCheckImage + else + self._checkImage.Image = kEnabledCheckImage + end + + self:UpdateFontColors() + self._button.BackgroundColor3 = self._disabled and GuiUtilities.kButtonDisabledBackgroundColor or GuiUtilities.kButtonStandardBackgroundColor + self._button.BorderColor3 = self._disabled and GuiUtilities.kButtonDisabledBorderColor or GuiUtilities.kButtonStandardBorderColor + if self._disabledChangedFunction then + self._disabledChangedFunction(self._disabled) + end + end + + local newValue = self:GetValue() + if (newValue ~= originalValue) then + self:_HandleUpdatedValue() + end +end + +function LabeledCheckboxClass:UpdateFontColors() + if self._disabled then + self._label.TextColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.DimmedText) + else + self._label.TextColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainText) + end +end + +function LabeledCheckboxClass:DisableWithOverrideValue(overrideValue) + -- Disable this checkbox. While disabled, force value to override + -- value. + local oldValue = self:GetValue() + self._useDisabledOverride = true + self._disabledOverride = overrideValue + self:SetDisabled(true) + local newValue = self:GetValue() + if (oldValue ~= newValue) then + self:_HandleUpdatedValue() + end +end + +function LabeledCheckboxClass:GetDisabled() + return self._disabled +end + +function LabeledCheckboxClass:SetValue(newValue) + local newValue = not not newValue + + if newValue ~= self._value then + self._value = newValue + + self:_HandleUpdatedValue() + end +end + +return LabeledCheckboxClass \ No newline at end of file diff --git a/src/Lualibs/LabeledMultiChoice.d.ts b/src/Lualibs/LabeledMultiChoice.d.ts new file mode 100644 index 0000000..471363c --- /dev/null +++ b/src/Lualibs/LabeledMultiChoice.d.ts @@ -0,0 +1,12 @@ +interface LabeledMultiChoiceChoice { + Id: string; + Text: string; +} +declare class LabeledMultiChoiceClass { + constructor(nameSuffix: string, labelText: string, choices: LabeledMultiChoiceChoice[], initChoiceIndex?: number); + SetSelectedIndex(index: number): void; + GetSelectedIndex(): number; + SetValueChangedFunction(fn: (index: number) => void): void; + GetFrame(): Instance; +} +export = LabeledMultiChoiceClass; diff --git a/src/Lualibs/LabeledMultiChoice.lua b/src/Lualibs/LabeledMultiChoice.lua new file mode 100644 index 0000000..91df529 --- /dev/null +++ b/src/Lualibs/LabeledMultiChoice.lua @@ -0,0 +1,132 @@ +---------------------------------------- +-- +-- LabeledMultiChoice.lua +-- +-- Creates a frame containing a label and list of choices, of which exactly one +-- is always selected. +-- +---------------------------------------- +GuiUtilities = require(script.Parent.GuiUtilities) +LabeledRadioButton = require(script.Parent.LabeledRadioButton) +LabeledCheckbox = require(script.Parent.LabeledCheckbox) +VerticallyScalingListFrame = require(script.Parent.VerticallyScalingListFrame) + +local kRadioButtonsHPadding = GuiUtilities.kRadioButtonsHPadding + +LabeledMultiChoiceClass = {} +LabeledMultiChoiceClass.__index = LabeledMultiChoiceClass + + +-- Note: +-- "choices" is an array of entries. +-- each entry must have at least 2 fields: +-- "Id" - a unique (in the scope of choices) string id. Not visible to user. +-- "Text" - user-facing string: the label for the choice. +function LabeledMultiChoiceClass.new(nameSuffix, labelText, choices, initChoiceIndex) + local self = {} + setmetatable(self, LabeledMultiChoiceClass) + + self._buttonObjsByIndex = {} + + if (not initChoiceIndex ) then + initChoiceIndex = 1 + end + if (initChoiceIndex > #choices) then + initChoiceIndex = #choices + end + + + local vsl = VerticallyScalingListFrame.new("MCC_" .. nameSuffix) + vsl:AddBottomPadding() + + local titleLabel = GuiUtilities.MakeFrameWithSubSectionLabel("Title", labelText) + vsl:AddChild(titleLabel) + + -- Container for cells. + local cellFrame = self:_MakeRadioButtons(choices) + vsl:AddChild(cellFrame) + + self._vsl = vsl + + self:SetSelectedIndex(initChoiceIndex) + + return self +end + +function LabeledMultiChoiceClass:SetSelectedIndex(selectedIndex) + self._selectedIndex = selectedIndex + for i = 1, #self._buttonObjsByIndex do + self._buttonObjsByIndex[i]:SetValue(i == selectedIndex) + end + + if (self._valueChangedFunction) then + self._valueChangedFunction(self._selectedIndex) + end +end + +function LabeledMultiChoiceClass:GetSelectedIndex() + return self._selectedIndex +end + +function LabeledMultiChoiceClass:SetValueChangedFunction(vcf) + self._valueChangedFunction = vcf +end + +function LabeledMultiChoiceClass:GetFrame() + return self._vsl:GetFrame() +end + + +-- Small checkboxes are a different entity. +-- All the bits are smaller. +-- Fixed width instead of flood-fill. +-- Box comes first, then label. +function LabeledMultiChoiceClass:_MakeRadioButtons(choices) + local frame = GuiUtilities.MakeFrame("RadioButtons") + frame.BackgroundTransparency = 1 + + local padding = Instance.new("UIPadding") + padding.PaddingLeft = UDim.new(0, GuiUtilities.StandardLineLabelLeftMargin) + padding.PaddingRight = UDim.new(0, GuiUtilities.StandardLineLabelLeftMargin) + padding.Parent = frame + + -- Make a grid to put checkboxes in. + local uiGridLayout = Instance.new("UIGridLayout") + uiGridLayout.CellSize = LabeledCheckbox.kMinFrameSize + uiGridLayout.CellPadding = UDim2.new(0, + kRadioButtonsHPadding, + 0, + GuiUtilities.kStandardVMargin) + uiGridLayout.HorizontalAlignment = Enum.HorizontalAlignment.Left + uiGridLayout.VerticalAlignment = Enum.VerticalAlignment.Top + uiGridLayout.Parent = frame + uiGridLayout.SortOrder = Enum.SortOrder.LayoutOrder + + for i, choiceData in ipairs(choices) do + self:_AddRadioButton(frame, i, choiceData) + end + + -- Sync size with content size. + GuiUtilities.AdjustHeightDynamicallyToLayout(frame, uiGridLayout) + + return frame +end + +function LabeledMultiChoiceClass:_AddRadioButton(parentFrame, index, choiceData) + local radioButtonObj = LabeledRadioButton.new(choiceData.Id, choiceData.Text) + self._buttonObjsByIndex[index] = radioButtonObj + + radioButtonObj:SetValueChangedFunction(function(value) + -- If we notice the button going from off to on, and it disagrees with + -- our current notion of selection, update selection. + if (value and self._selectedIndex ~= index) then + self:SetSelectedIndex(index) + end + end) + + radioButtonObj:GetFrame().LayoutOrder = index + radioButtonObj:GetFrame().Parent = parentFrame +end + + +return LabeledMultiChoiceClass \ No newline at end of file diff --git a/src/Lualibs/LabeledRadioButton.d.ts b/src/Lualibs/LabeledRadioButton.d.ts new file mode 100644 index 0000000..ba8df1f --- /dev/null +++ b/src/Lualibs/LabeledRadioButton.d.ts @@ -0,0 +1,8 @@ +declare class LabeledRadioButtonClass { + constructor(nameSuffix: string, labelText: string); + GetFrame(): Instance; + GetValue(): boolean; + SetValueChangedFunction(fn: (value: boolean) => void): void; + SetValue(value: boolean): void; +} +export = LabeledRadioButtonClass; diff --git a/src/Lualibs/LabeledRadioButton.lua b/src/Lualibs/LabeledRadioButton.lua new file mode 100644 index 0000000..c38c97a --- /dev/null +++ b/src/Lualibs/LabeledRadioButton.lua @@ -0,0 +1,60 @@ +---------------------------------------- +-- +-- LabeledRadioButton.lua +-- +-- Creates a frame containing a label and a radio button. +-- +---------------------------------------- +GuiUtilities = require(script.Parent.GuiUtilities) +LabeledCheckbox = require(script.Parent.LabeledCheckbox) + +local kButtonImage = "rbxasset://textures/TerrainTools/radio_button_frame.png" +local kBulletImage = "rbxasset://textures/TerrainTools/radio_button_bullet.png" + +local kButtonImageDark = "rbxasset://textures/TerrainTools/radio_button_frame_dark.png" +local kBulletImageDark = "rbxasset://textures/TerrainTools/radio_button_bullet_dark.png" + +local kFrameSize = 12 +local kBulletSize = 14 + +LabeledRadioButtonClass = {} +LabeledRadioButtonClass.__index = LabeledRadioButtonClass +setmetatable(LabeledRadioButtonClass, LabeledCheckbox) + +function LabeledRadioButtonClass.new(nameSuffix, labelText) + local newButton = LabeledCheckbox.new(nameSuffix, labelText, false) + setmetatable(newButton, LabeledRadioButtonClass) + + newButton:UseSmallSize() + newButton._checkImage.Position = UDim2.new(0.5, 0, 0.5, 0) + newButton._checkImage.Image = kBulletImage + newButton._checkImage.Size = UDim2.new(0, kBulletSize, 0, kBulletSize) + + newButton._button.Image = kButtonImage + newButton._button.Size = UDim2.new(0, kFrameSize, 0, kFrameSize) + newButton._button.BackgroundTransparency = 1 + + local function updateImages() + if (GuiUtilities:ShouldUseIconsForDarkerBackgrounds()) then + newButton._checkImage.Image = kBulletImageDark + newButton._button.Image = kButtonImageDark + else + newButton._checkImage.Image = kBulletImage + newButton._button.Image = kButtonImage + end + end + settings().Studio.ThemeChanged:connect(updateImages) + updateImages() + + return newButton +end + +function LabeledRadioButtonClass:_MaybeToggleState() + -- A checkbox can never be toggled off. + -- Only turns off because another one turns on. + if (not self._disabled and not self._value) then + self:SetValue(not self._value) + end +end + +return LabeledRadioButtonClass \ No newline at end of file diff --git a/src/Lualibs/LabeledSlider.d.ts b/src/Lualibs/LabeledSlider.d.ts new file mode 100644 index 0000000..a5dee5b --- /dev/null +++ b/src/Lualibs/LabeledSlider.d.ts @@ -0,0 +1,8 @@ +declare class LabeledSliderClass { + constructor(nameSuffix: string, labelText: string, sliderIntervals?: number, defaultValue?: number); + SetValueChangedFunction(fn: (value: number) => void): void; + GetFrame(): Instance; + SetValue(value: number): void; + GetValue(): number; +} +export = LabeledSliderClass; diff --git a/src/Lualibs/LabeledSlider.lua b/src/Lualibs/LabeledSlider.lua new file mode 100644 index 0000000..2020f21 --- /dev/null +++ b/src/Lualibs/LabeledSlider.lua @@ -0,0 +1,122 @@ +---------------------------------------- +-- +-- LabeledSlider.lua +-- +-- Creates a frame containing a label and a slider control. +-- +---------------------------------------- +GuiUtilities = require(script.Parent.GuiUtilities) +rbxGuiLibrary = require(script.Parent.RbxGui) + +local kSliderWidth = 100 + +local kSliderThumbImage = "rbxasset://textures/TerrainTools/sliderbar_button.png" +local kPreThumbImage = "rbxasset://textures/TerrainTools/sliderbar_blue.png" +local kPostThumbImage = "rbxasset://textures/TerrainTools/sliderbar_grey.png" + +local kThumbSize = 13 + +local kSteps = 100 + +LabeledSliderClass = {} +LabeledSliderClass.__index = LabeledSliderClass + +function LabeledSliderClass.new(nameSuffix, labelText, sliderIntervals, defaultValue) + local self = {} + setmetatable(self, LabeledSliderClass) + + self._valueChangedFunction = nil + + local sliderIntervals = sliderIntervals or 100 + local defaultValue = defaultValue or 1 + + local frame = GuiUtilities.MakeStandardFixedHeightFrame('Slider' .. nameSuffix) + self._frame = frame + + local label = GuiUtilities.MakeStandardPropertyLabel(labelText) + label.Parent = frame + self._label = label + + self._value = defaultValue + + --steps, width, position + local slider, sliderValue = rbxGuiLibrary.CreateSlider(sliderIntervals, + kSteps, + UDim2.new(0, 0, .5, -3)) + self._slider = slider + self._sliderValue = sliderValue + -- Some tweaks to make slider look nice. + -- Hide the existing bar. + slider.Bar.BackgroundTransparency = 1 + -- Replace slider thumb image. + self._thumb = slider.Bar.Slider + self._thumb.Image = kSliderThumbImage + self._thumb.AnchorPoint = Vector2.new(0.5, 0.5) + self._thumb.Size = UDim2.new(0, kThumbSize, 0, kThumbSize) + + -- Add images on bar. + self._preThumbImage = Instance.new("ImageLabel") + self._preThumbImage.Name = "PreThumb" + self._preThumbImage.Parent = slider.Bar + self._preThumbImage.Size = UDim2.new(1, 0, 1, 0) + self._preThumbImage.Position = UDim2.new(0, 0, 0, 0) + self._preThumbImage.Image = kPreThumbImage + self._preThumbImage.BorderSizePixel = 0 + + self._postThumbImage = Instance.new("ImageLabel") + self._postThumbImage.Name = "PostThumb" + self._postThumbImage.Parent = slider.Bar + self._postThumbImage.Size = UDim2.new(1, 0, 1, 0) + self._postThumbImage.Position = UDim2.new(0, 0, 0, 0) + self._postThumbImage.Image = kPostThumbImage + self._postThumbImage.BorderSizePixel = 0 + + sliderValue.Changed:connect(function() + self._value = sliderValue.Value + + -- Min value is 1. + -- Max value is sliderIntervals. + -- So scale is... + local scale = (self._value - 1)/(sliderIntervals-1) + + self._preThumbImage.Size = UDim2.new(scale, 0, 1, 0) + self._postThumbImage.Size = UDim2.new(1 - scale, 0, 1, 0) + self._postThumbImage.Position = UDim2.new(scale, 0, 0, 0) + + self._thumb.Position = UDim2.new(scale, 0, + 0.5, 0) + + if self._valueChangedFunction then + self._valueChangedFunction(self._value) + end + end) + + self:SetValue(defaultValue) + slider.AnchorPoint = Vector2.new(0, 0.5) + slider.Size = UDim2.new(0, kSliderWidth, 1, 0) + slider.Position = UDim2.new(0, GuiUtilities.StandardLineElementLeftMargin, 0, GuiUtilities.kStandardPropertyHeight/2) + slider.Parent = frame + + return self +end + +function LabeledSliderClass:SetValueChangedFunction(vcf) + self._valueChangedFunction = vcf +end + +function LabeledSliderClass:GetFrame() + return self._frame +end + +function LabeledSliderClass:SetValue(newValue) + if self._sliderValue.Value ~= newValue then + self._sliderValue.Value = newValue + end +end + +function LabeledSliderClass:GetValue() + return self._sliderValue.Value +end + + +return LabeledSliderClass \ No newline at end of file diff --git a/src/Lualibs/LabeledTextInput.d.ts b/src/Lualibs/LabeledTextInput.d.ts new file mode 100644 index 0000000..fcfaeef --- /dev/null +++ b/src/Lualibs/LabeledTextInput.d.ts @@ -0,0 +1,10 @@ +declare class LabeledTextInput { + constructor(nameSuffix: string, labelText: string, defaultValue?: string); + SetValueChangedFunction(fn: (value: string) => void): void; + GetFrame(): Instance; + GetValue(): string; + GetMaxGraphemes(): number; + SetMaxGraphemes(value: number): void; + SetValue(value: string): void; +} +export = LabeledTextInput; diff --git a/src/Lualibs/LabeledTextInput.lua b/src/Lualibs/LabeledTextInput.lua new file mode 100644 index 0000000..8bb8f03 --- /dev/null +++ b/src/Lualibs/LabeledTextInput.lua @@ -0,0 +1,122 @@ +---------------------------------------- +-- +-- LabeledTextInput.lua +-- +-- Creates a frame containing a label and a text input control. +-- +---------------------------------------- +GuiUtilities = require(script.Parent.GuiUtilities) + +local kTextInputWidth = 100 +local kTextBoxInternalPadding = 4 + +LabeledTextInputClass = {} +LabeledTextInputClass.__index = LabeledTextInputClass + +function LabeledTextInputClass.new(nameSuffix, labelText, defaultValue) + local self = {} + setmetatable(self, LabeledTextInputClass) + + -- Note: we are using "graphemes" instead of characters. + -- In modern text-manipulation-fu, what with internationalization, + -- emojis, etc, it's not enough to count characters, particularly when + -- concerned with "how many am I rendering?". + -- We are using the + self._MaxGraphemes = 10 + + self._valueChangedFunction = nil + + local defaultValue = defaultValue or "" + + local frame = GuiUtilities.MakeStandardFixedHeightFrame('TextInput ' .. nameSuffix) + self._frame = frame + + local label = GuiUtilities.MakeStandardPropertyLabel(labelText) + label.Parent = frame + self._label = label + + self._value = defaultValue + + -- Dumb hack to add padding to text box, + local textBoxWrapperFrame = Instance.new("Frame") + textBoxWrapperFrame.Name = "Wrapper" + textBoxWrapperFrame.Size = UDim2.new(0, kTextInputWidth, 0.6, 0) + textBoxWrapperFrame.Position = UDim2.new(0, GuiUtilities.StandardLineElementLeftMargin, .5, 0) + textBoxWrapperFrame.AnchorPoint = Vector2.new(0, .5) + textBoxWrapperFrame.Parent = frame + GuiUtilities.syncGuiElementInputFieldColor(textBoxWrapperFrame) + GuiUtilities.syncGuiElementBorderColor(textBoxWrapperFrame) + + local textBox = Instance.new("TextBox") + textBox.Parent = textBoxWrapperFrame + textBox.Name = "TextBox" + textBox.Text = defaultValue + textBox.Font = Enum.Font.SourceSans + textBox.TextSize = 15 + textBox.BackgroundTransparency = 1 + textBox.TextXAlignment = Enum.TextXAlignment.Left + textBox.Size = UDim2.new(1, -kTextBoxInternalPadding, 1, GuiUtilities.kTextVerticalFudge) + textBox.Position = UDim2.new(0, kTextBoxInternalPadding, 0, 0) + textBox.ClipsDescendants = true + + GuiUtilities.syncGuiElementFontColor(textBox) + + textBox:GetPropertyChangedSignal("Text"):connect(function() + -- Never let the text be too long. + -- Careful here: we want to measure number of graphemes, not characters, + -- in the text, and we want to clamp on graphemes as well. + if (utf8.len(self._textBox.Text) > self._MaxGraphemes) then + local count = 0 + for start, stop in utf8.graphemes(self._textBox.Text) do + count = count + 1 + if (count > self._MaxGraphemes) then + -- We have gone one too far. + -- clamp just before the beginning of this grapheme. + self._textBox.Text = string.sub(self._textBox.Text, 1, start-1) + break + end + end + -- Don't continue with rest of function: the resetting of "Text" field + -- above will trigger re-entry. We don't need to trigger value + -- changed function twice. + return + end + + self._value = self._textBox.Text + if (self._valueChangedFunction) then + self._valueChangedFunction(self._value) + end + end) + + self._textBox = textBox + + return self +end + +function LabeledTextInputClass:SetValueChangedFunction(vcf) + self._valueChangedFunction = vcf +end + +function LabeledTextInputClass:GetFrame() + return self._frame +end + +function LabeledTextInputClass:GetValue() + return self._value +end + +function LabeledTextInputClass:GetMaxGraphemes() + return self._MaxGraphemes +end + +function LabeledTextInputClass:SetMaxGraphemes(newValue) + self._MaxGraphemes = newValue +end + +function LabeledTextInputClass:SetValue(newValue) + if self._value ~= newValue then + self._textBox.Text = newValue + end +end + +return LabeledTextInputClass \ No newline at end of file diff --git a/src/Lualibs/RbxGui.lua b/src/Lualibs/RbxGui.lua new file mode 100644 index 0000000..ea58445 --- /dev/null +++ b/src/Lualibs/RbxGui.lua @@ -0,0 +1,4214 @@ +local t = {} + +local function ScopedConnect(parentInstance, instance, event, signalFunc, syncFunc, removeFunc) + local eventConnection = nil + + --Connection on parentInstance is scoped by parentInstance (when destroyed, it goes away) + local tryConnect = function() + if game:IsAncestorOf(parentInstance) then + --Entering the world, make sure we are connected/synced + if not eventConnection then + eventConnection = instance[event]:connect(signalFunc) + if syncFunc then syncFunc() end + end + else + --Probably leaving the world, so disconnect for now + if eventConnection then + eventConnection:disconnect() + if removeFunc then removeFunc() end + end + end + end + + --Hook it up to ancestryChanged signal + local connection = parentInstance.AncestryChanged:connect(tryConnect) + + --Now connect us if we're already in the world + tryConnect() + + return connection +end + +local function getLayerCollectorAncestor(instance) + local localInstance = instance + while localInstance and not localInstance:IsA("LayerCollector") do + localInstance = localInstance.Parent + end + return localInstance +end + +local function CreateButtons(frame, buttons, yPos, ySize) + local buttonNum = 1 + local buttonObjs = {} + for i, obj in ipairs(buttons) do + local button = Instance.new("TextButton") + button.Name = "Button" .. buttonNum + button.Font = Enum.Font.Arial + button.FontSize = Enum.FontSize.Size18 + button.AutoButtonColor = true + button.Modal = true + if obj["Style"] then + button.Style = obj.Style + else + button.Style = Enum.ButtonStyle.RobloxButton + end + if obj["ZIndex"] then + button.ZIndex = obj.ZIndex + end + button.Text = obj.Text + button.TextColor3 = Color3.new(1,1,1) + button.MouseButton1Click:connect(obj.Function) + button.Parent = frame + buttonObjs[buttonNum] = button + + buttonNum = buttonNum + 1 + end + local numButtons = buttonNum-1 + + if numButtons == 1 then + frame.Button1.Position = UDim2.new(0.35, 0, yPos.Scale, yPos.Offset) + frame.Button1.Size = UDim2.new(.4,0,ySize.Scale, ySize.Offset) + elseif numButtons == 2 then + frame.Button1.Position = UDim2.new(0.1, 0, yPos.Scale, yPos.Offset) + frame.Button1.Size = UDim2.new(.8/3,0, ySize.Scale, ySize.Offset) + + frame.Button2.Position = UDim2.new(0.55, 0, yPos.Scale, yPos.Offset) + frame.Button2.Size = UDim2.new(.35,0, ySize.Scale, ySize.Offset) + elseif numButtons >= 3 then + local spacing = .1 / numButtons + local buttonSize = .9 / numButtons + + buttonNum = 1 + while buttonNum <= numButtons do + buttonObjs[buttonNum].Position = UDim2.new(spacing*buttonNum + (buttonNum-1) * buttonSize, 0, yPos.Scale, yPos.Offset) + buttonObjs[buttonNum].Size = UDim2.new(buttonSize, 0, ySize.Scale, ySize.Offset) + buttonNum = buttonNum + 1 + end + end +end + +local function setSliderPos(newAbsPosX,slider,sliderPosition,bar,steps) + + local newStep = steps - 1 --otherwise we really get one more step than we want + local relativePosX = math.min(1, math.max(0, (newAbsPosX - bar.AbsolutePosition.X) / bar.AbsoluteSize.X )) + local wholeNum, remainder = math.modf(relativePosX * newStep) + if remainder > 0.5 then + wholeNum = wholeNum + 1 + end + relativePosX = wholeNum/newStep + + local result = math.ceil(relativePosX * newStep) + if sliderPosition.Value ~= (result + 1) then --only update if we moved a step + sliderPosition.Value = result + 1 + slider.Position = UDim2.new(relativePosX,-slider.AbsoluteSize.X/2,slider.Position.Y.Scale,slider.Position.Y.Offset) + end + +end + +local function cancelSlide(areaSoak) + areaSoak.Visible = false +end + +t.CreateStyledMessageDialog = function(title, message, style, buttons) + local frame = Instance.new("Frame") + frame.Size = UDim2.new(0.5, 0, 0, 165) + frame.Position = UDim2.new(0.25, 0, 0.5, -72.5) + frame.Name = "MessageDialog" + frame.Active = true + frame.Style = Enum.FrameStyle.RobloxRound + + local styleImage = Instance.new("ImageLabel") + styleImage.Name = "StyleImage" + styleImage.BackgroundTransparency = 1 + styleImage.Position = UDim2.new(0,5,0,15) + if style == "error" or style == "Error" then + styleImage.Size = UDim2.new(0, 71, 0, 71) + styleImage.Image = "https://www.roblox.com/asset/?id=42565285" + elseif style == "notify" or style == "Notify" then + styleImage.Size = UDim2.new(0, 71, 0, 71) + styleImage.Image = "https://www.roblox.com/asset/?id=42604978" + elseif style == "confirm" or style == "Confirm" then + styleImage.Size = UDim2.new(0, 74, 0, 76) + styleImage.Image = "https://www.roblox.com/asset/?id=42557901" + else + return t.CreateMessageDialog(title,message,buttons) + end + styleImage.Parent = frame + + local titleLabel = Instance.new("TextLabel") + titleLabel.Name = "Title" + titleLabel.Text = title + titleLabel.TextStrokeTransparency = 0 + titleLabel.BackgroundTransparency = 1 + titleLabel.TextColor3 = Color3.new(221/255,221/255,221/255) + titleLabel.Position = UDim2.new(0, 80, 0, 0) + titleLabel.Size = UDim2.new(1, -80, 0, 40) + titleLabel.Font = Enum.Font.ArialBold + titleLabel.FontSize = Enum.FontSize.Size36 + titleLabel.TextXAlignment = Enum.TextXAlignment.Center + titleLabel.TextYAlignment = Enum.TextYAlignment.Center + titleLabel.Parent = frame + + local messageLabel = Instance.new("TextLabel") + messageLabel.Name = "Message" + messageLabel.Text = message + messageLabel.TextStrokeTransparency = 0 + messageLabel.TextColor3 = Color3.new(221/255,221/255,221/255) + messageLabel.Position = UDim2.new(0.025, 80, 0, 45) + messageLabel.Size = UDim2.new(0.95, -80, 0, 55) + messageLabel.BackgroundTransparency = 1 + messageLabel.Font = Enum.Font.Arial + messageLabel.FontSize = Enum.FontSize.Size18 + messageLabel.TextWrap = true + messageLabel.TextXAlignment = Enum.TextXAlignment.Left + messageLabel.TextYAlignment = Enum.TextYAlignment.Top + messageLabel.Parent = frame + + CreateButtons(frame, buttons, UDim.new(0, 105), UDim.new(0, 40) ) + + return frame +end + +t.CreateMessageDialog = function(title, message, buttons) + local frame = Instance.new("Frame") + frame.Size = UDim2.new(0.5, 0, 0.5, 0) + frame.Position = UDim2.new(0.25, 0, 0.25, 0) + frame.Name = "MessageDialog" + frame.Active = true + frame.Style = Enum.FrameStyle.RobloxRound + + local titleLabel = Instance.new("TextLabel") + titleLabel.Name = "Title" + titleLabel.Text = title + titleLabel.BackgroundTransparency = 1 + titleLabel.TextColor3 = Color3.new(221/255,221/255,221/255) + titleLabel.Position = UDim2.new(0, 0, 0, 0) + titleLabel.Size = UDim2.new(1, 0, 0.15, 0) + titleLabel.Font = Enum.Font.ArialBold + titleLabel.FontSize = Enum.FontSize.Size36 + titleLabel.TextXAlignment = Enum.TextXAlignment.Center + titleLabel.TextYAlignment = Enum.TextYAlignment.Center + titleLabel.Parent = frame + + local messageLabel = Instance.new("TextLabel") + messageLabel.Name = "Message" + messageLabel.Text = message + messageLabel.TextColor3 = Color3.new(221/255,221/255,221/255) + messageLabel.Position = UDim2.new(0.025, 0, 0.175, 0) + messageLabel.Size = UDim2.new(0.95, 0, .55, 0) + messageLabel.BackgroundTransparency = 1 + messageLabel.Font = Enum.Font.Arial + messageLabel.FontSize = Enum.FontSize.Size18 + messageLabel.TextWrap = true + messageLabel.TextXAlignment = Enum.TextXAlignment.Left + messageLabel.TextYAlignment = Enum.TextYAlignment.Top + messageLabel.Parent = frame + + CreateButtons(frame, buttons, UDim.new(0.8,0), UDim.new(0.15, 0)) + + return frame +end + +-- written by jmargh +-- to be used for the new settings menu +t.CreateScrollingDropDownMenu = function(onSelectedCallback, size, position, baseZ) + local maxVisibleList = 6 + local baseZIndex = 0 + if type(baseZ) == 'number' then + baseZIndex = baseZ + end + + local dropDownMenu = {} + local currentList = nil + + local updateFunc = nil + local frame = Instance.new('Frame') + frame.Name = "DropDownMenuFrame" + frame.Size = size + frame.Position = position + frame.BackgroundTransparency = 1 + dropDownMenu.Frame = frame + + local currentSelectionName = Instance.new('TextButton') + currentSelectionName.Name = "CurrentSelectionName" + currentSelectionName.Size = UDim2.new(1, 0, 1, 0) + currentSelectionName.BackgroundTransparency = 1 + currentSelectionName.Font = Enum.Font.SourceSansBold + currentSelectionName.FontSize = Enum.FontSize.Size18 + currentSelectionName.TextXAlignment = Enum.TextXAlignment.Left + currentSelectionName.TextYAlignment = Enum.TextYAlignment.Center + currentSelectionName.TextColor3 = Color3.new(0.5, 0.5, 0.5) + currentSelectionName.TextWrap = true + currentSelectionName.ZIndex = baseZIndex + currentSelectionName.Style = Enum.ButtonStyle.RobloxRoundDropdownButton + currentSelectionName.Text = "Choose One" + currentSelectionName.Parent = frame + dropDownMenu.CurrentSelectionButton = currentSelectionName + + local icon = Instance.new('ImageLabel') + icon.Name = "DropDownIcon" + icon.Size = UDim2.new(0, 16, 0, 12) + icon.Position = UDim2.new(1, -17, 0.5, -6) + icon.Image = 'rbxasset://textures/ui/dropdown_arrow.png' + icon.BackgroundTransparency = 1 + icon.ZIndex = baseZIndex + icon.Parent = currentSelectionName + + local listMenu = nil + local scrollingBackground = nil + local visibleCount = 0 + local isOpen = false + + local function onEntrySelected() + icon.Rotation = 0 + scrollingBackground:TweenSize(UDim2.new(1, 0, 0, currentSelectionName.AbsoluteSize.y), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.15, true) + -- + listMenu.ScrollBarThickness = 0 + listMenu:TweenSize(UDim2.new(1, -16, 0, 24), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.15, true, function() + if not isOpen then + listMenu.Visible = false + scrollingBackground.Visible = false + end + end) + isOpen = false + end + + currentSelectionName.MouseButton1Click:connect(function() + if not currentSelectionName.Active or #currentList == 0 then return end + if isOpen then + onEntrySelected() + return + end + -- + isOpen = true + icon.Rotation = 180 + if listMenu then listMenu.Visible = true end + if scrollingBackground then scrollingBackground.Visible = true end + -- + if scrollingBackground then + scrollingBackground:TweenSize(UDim2.new(1, 0, 0, visibleCount * 24 + 8), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.15, true) + end + if listMenu then + listMenu:TweenSize(UDim2.new(1, -16, 0, visibleCount * 24), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.15, true, function() + listMenu.ScrollBarThickness = 6 + end) + end + end) + + --[[ Public API ]]-- + dropDownMenu.IsOpen = function() + return isOpen + end + + dropDownMenu.Close = function() + onEntrySelected() + end + + dropDownMenu.Reset = function() + isOpen = false + icon.Rotation = 0 + listMenu.ScrollBarThickness = 0 + listMenu.Size = UDim2.new(1, -16, 0, 24) + listMenu.Visible = false + scrollingBackground.Visible = false + end + + dropDownMenu.SetVisible = function(isVisible) + if frame then + frame.Visible = isVisible + end + end + + dropDownMenu.UpdateZIndex = function(newZIndexBase) + currentSelectionName.ZIndex = newZIndexBase + icon.ZIndex = newZIndexBase + if scrollingBackground then scrollingBackground.ZIndex = newZIndexBase + 1 end + if listMenu then + listMenu.ZIndex = newZIndexBase + 2 + for _,child in pairs(listMenu:GetChildren()) do + child.ZIndex = newZIndexBase + 4 + end + end + end + + dropDownMenu.SetActive = function(isActive) + currentSelectionName.Active = isActive + end + + dropDownMenu.SetSelectionText = function(text) + currentSelectionName.Text = text + end + + dropDownMenu.CreateList = function(list) + currentSelectionName.Text = "Choose One" + if listMenu then listMenu:Destroy() end + if scrollingBackground then scrollingBackground:Destroy() end + -- + currentList = list + local length = #list + visibleCount = math.min(maxVisibleList, length) + local listMenuOffset = visibleCount * 24 + + listMenu = Instance.new('ScrollingFrame') + listMenu.Name = "ListMenu" + listMenu.Size = UDim2.new(1, -16, 0, 24) + listMenu.Position = UDim2.new(0, 12, 0, 32) + listMenu.CanvasSize = UDim2.new(0, 0, 0, length * 24) + listMenu.BackgroundTransparency = 1 + listMenu.BorderSizePixel = 0 + listMenu.ZIndex = baseZIndex + 2 + listMenu.Visible = false + listMenu.Active = true + listMenu.BottomImage = 'rbxasset://textures/ui/scroll-bottom.png' + listMenu.MidImage = 'rbxasset://textures/ui/scroll-middle.png' + listMenu.TopImage = 'rbxasset://textures/ui/scroll-top.png' + listMenu.ScrollBarThickness = 0 + listMenu.Parent = frame + + scrollingBackground = Instance.new('TextButton') + scrollingBackground.Name = "ScrollingBackground" + scrollingBackground.Size = UDim2.new(1, 0, 0, currentSelectionName.AbsoluteSize.y) + scrollingBackground.Position = UDim2.new(0, 0, 0, 28) + scrollingBackground.BackgroundColor3 = Color3.new(1, 1, 1) + scrollingBackground.Style = Enum.ButtonStyle.RobloxRoundDropdownButton + scrollingBackground.ZIndex = baseZIndex + 1 + scrollingBackground.Text = "" + scrollingBackground.Visible = false + scrollingBackground.AutoButtonColor = false + scrollingBackground.Parent = frame + + for i = 1, length do + local entry = list[i] + local btn = Instance.new('TextButton') + btn.Name = entry + btn.Size = UDim2.new(1, 0, 0, 24) + btn.Position = UDim2.new(0, 0, 0, (i - 1) * 24) + btn.BackgroundTransparency = 0 + btn.BackgroundColor3 = Color3.new(1, 1, 1) + btn.BorderSizePixel = 0 + btn.Font = Enum.Font.SourceSans + btn.FontSize = Enum.FontSize.Size18 + btn.TextColor3 = Color3.new(0.5, 0.5, 0.5) + btn.TextXAlignment = Enum.TextXAlignment.Left + btn.TextYAlignment = Enum.TextYAlignment.Center + btn.Text = entry + btn.ZIndex = baseZIndex + 4 + btn.AutoButtonColor = false + btn.Parent = listMenu + + btn.MouseButton1Click:connect(function() + currentSelectionName.Text = btn.Text + onEntrySelected() + btn.Font = Enum.Font.SourceSans + btn.TextColor3 = Color3.new(0.5, 0.5, 0.5) + btn.BackgroundColor3 = Color3.new(1, 1, 1) + onSelectedCallback(btn.Text) + end) + + btn.MouseEnter:connect(function() + btn.TextColor3 = Color3.new(1, 1, 1) + btn.BackgroundColor3 = Color3.new(0.75, 0.75, 0.75) + end) + btn.MouseLeave:connect(function() + btn.TextColor3 = Color3.new(0.5, 0.5, 0.5) + btn.BackgroundColor3 = Color3.new(1, 1, 1) + end) + end + end + + return dropDownMenu +end + +t.CreateDropDownMenu = function(items, onSelect, forRoblox, whiteSkin, baseZ) + local baseZIndex = 0 + if (type(baseZ) == "number") then + baseZIndex = baseZ + end + local width = UDim.new(0, 100) + local height = UDim.new(0, 32) + + local xPos = 0.055 + local frame = Instance.new("Frame") + local textColor = Color3.new(1,1,1) + if (whiteSkin) then + textColor = Color3.new(0.5, 0.5, 0.5) + end + frame.Name = "DropDownMenu" + frame.BackgroundTransparency = 1 + frame.Size = UDim2.new(width, height) + + local dropDownMenu = Instance.new("TextButton") + dropDownMenu.Name = "DropDownMenuButton" + dropDownMenu.TextWrap = true + dropDownMenu.TextColor3 = textColor + dropDownMenu.Text = "Choose One" + dropDownMenu.Font = Enum.Font.ArialBold + dropDownMenu.FontSize = Enum.FontSize.Size18 + dropDownMenu.TextXAlignment = Enum.TextXAlignment.Left + dropDownMenu.TextYAlignment = Enum.TextYAlignment.Center + dropDownMenu.BackgroundTransparency = 1 + dropDownMenu.AutoButtonColor = true + if (whiteSkin) then + dropDownMenu.Style = Enum.ButtonStyle.RobloxRoundDropdownButton + else + dropDownMenu.Style = Enum.ButtonStyle.RobloxButton + end + dropDownMenu.Size = UDim2.new(1,0,1,0) + dropDownMenu.Parent = frame + dropDownMenu.ZIndex = 2 + baseZIndex + + local dropDownIcon = Instance.new("ImageLabel") + dropDownIcon.Name = "Icon" + dropDownIcon.Active = false + if (whiteSkin) then + dropDownIcon.Image = "rbxasset://textures/ui/dropdown_arrow.png" + dropDownIcon.Size = UDim2.new(0,16,0,12) + dropDownIcon.Position = UDim2.new(1,-17,0.5, -6) + else + dropDownIcon.Image = "https://www.roblox.com/asset/?id=45732894" + dropDownIcon.Size = UDim2.new(0,11,0,6) + dropDownIcon.Position = UDim2.new(1,-11,0.5, -2) + end + dropDownIcon.BackgroundTransparency = 1 + dropDownIcon.Parent = dropDownMenu + dropDownIcon.ZIndex = 2 + baseZIndex + + local itemCount = #items + local dropDownItemCount = #items + local useScrollButtons = false + if dropDownItemCount > 6 then + useScrollButtons = true + dropDownItemCount = 6 + end + + local droppedDownMenu = Instance.new("TextButton") + droppedDownMenu.Name = "List" + droppedDownMenu.Text = "" + droppedDownMenu.BackgroundTransparency = 1 + --droppedDownMenu.AutoButtonColor = true + if (whiteSkin) then + droppedDownMenu.Style = Enum.ButtonStyle.RobloxRoundDropdownButton + else + droppedDownMenu.Style = Enum.ButtonStyle.RobloxButton + end + droppedDownMenu.Visible = false + droppedDownMenu.Active = true --Blocks clicks + droppedDownMenu.Position = UDim2.new(0,0,0,0) + droppedDownMenu.Size = UDim2.new(1,0, (1 + dropDownItemCount)*.8, 0) + droppedDownMenu.Parent = frame + droppedDownMenu.ZIndex = 2 + baseZIndex + + local choiceButton = Instance.new("TextButton") + choiceButton.Name = "ChoiceButton" + choiceButton.BackgroundTransparency = 1 + choiceButton.BorderSizePixel = 0 + choiceButton.Text = "ReplaceMe" + choiceButton.TextColor3 = textColor + choiceButton.TextXAlignment = Enum.TextXAlignment.Left + choiceButton.TextYAlignment = Enum.TextYAlignment.Center + choiceButton.BackgroundColor3 = Color3.new(1, 1, 1) + choiceButton.Font = Enum.Font.Arial + choiceButton.FontSize = Enum.FontSize.Size18 + if useScrollButtons then + choiceButton.Size = UDim2.new(1,-13, .8/((dropDownItemCount + 1)*.8),0) + else + choiceButton.Size = UDim2.new(1, 0, .8/((dropDownItemCount + 1)*.8),0) + end + choiceButton.TextWrap = true + choiceButton.ZIndex = 2 + baseZIndex + + local areaSoak = Instance.new("TextButton") + areaSoak.Name = "AreaSoak" + areaSoak.Text = "" + areaSoak.BackgroundTransparency = 1 + areaSoak.Active = true + areaSoak.Size = UDim2.new(1,0,1,0) + areaSoak.Visible = false + areaSoak.ZIndex = 3 + baseZIndex + + local dropDownSelected = false + + local scrollUpButton + local scrollDownButton + local scrollMouseCount = 0 + + local setZIndex = function(baseZIndex) + droppedDownMenu.ZIndex = baseZIndex +1 + if scrollUpButton then + scrollUpButton.ZIndex = baseZIndex + 3 + end + if scrollDownButton then + scrollDownButton.ZIndex = baseZIndex + 3 + end + + local children = droppedDownMenu:GetChildren() + if children then + for i, child in ipairs(children) do + if child.Name == "ChoiceButton" then + child.ZIndex = baseZIndex + 2 + elseif child.Name == "ClickCaptureButton" then + child.ZIndex = baseZIndex + end + end + end + end + + local scrollBarPosition = 1 + local updateScroll = function() + if scrollUpButton then + scrollUpButton.Active = scrollBarPosition > 1 + end + if scrollDownButton then + scrollDownButton.Active = scrollBarPosition + dropDownItemCount <= itemCount + end + + local children = droppedDownMenu:GetChildren() + if not children then return end + + local childNum = 1 + for i, obj in ipairs(children) do + if obj.Name == "ChoiceButton" then + if childNum < scrollBarPosition or childNum >= scrollBarPosition + dropDownItemCount then + obj.Visible = false + else + obj.Position = UDim2.new(0,0,((childNum-scrollBarPosition+1)*.8)/((dropDownItemCount+1)*.8),0) + obj.Visible = true + end + obj.TextColor3 = textColor + obj.BackgroundTransparency = 1 + + childNum = childNum + 1 + end + end + end + local toggleVisibility = function() + dropDownSelected = not dropDownSelected + + areaSoak.Visible = not areaSoak.Visible + dropDownMenu.Visible = not dropDownSelected + droppedDownMenu.Visible = dropDownSelected + if dropDownSelected then + setZIndex(4 + baseZIndex) + else + setZIndex(2 + baseZIndex) + end + if useScrollButtons then + updateScroll() + end + end + droppedDownMenu.MouseButton1Click:connect(toggleVisibility) + + local updateSelection = function(text) + local foundItem = false + local children = droppedDownMenu:GetChildren() + local childNum = 1 + if children then + for i, obj in ipairs(children) do + if obj.Name == "ChoiceButton" then + if obj.Text == text then + obj.Font = Enum.Font.ArialBold + foundItem = true + scrollBarPosition = childNum + if (whiteSkin) then + obj.TextColor3 = Color3.new(90/255,142/255,233/255) + end + else + obj.Font = Enum.Font.Arial + if (whiteSkin) then + obj.TextColor3 = textColor + end + end + childNum = childNum + 1 + end + end + end + if not text then + dropDownMenu.Text = "Choose One" + scrollBarPosition = 1 + else + if not foundItem then + error("Invalid Selection Update -- " .. text) + end + + if scrollBarPosition + dropDownItemCount > itemCount + 1 then + scrollBarPosition = itemCount - dropDownItemCount + 1 + end + + dropDownMenu.Text = text + end + end + + local function scrollDown() + if scrollBarPosition + dropDownItemCount <= itemCount then + scrollBarPosition = scrollBarPosition + 1 + updateScroll() + return true + end + return false + end + local function scrollUp() + if scrollBarPosition > 1 then + scrollBarPosition = scrollBarPosition - 1 + updateScroll() + return true + end + return false + end + + if useScrollButtons then + --Make some scroll buttons + scrollUpButton = Instance.new("ImageButton") + scrollUpButton.Name = "ScrollUpButton" + scrollUpButton.BackgroundTransparency = 1 + scrollUpButton.Image = "rbxasset://textures/ui/scrollbuttonUp.png" + scrollUpButton.Size = UDim2.new(0,17,0,17) + scrollUpButton.Position = UDim2.new(1,-11,(1*.8)/((dropDownItemCount+1)*.8),0) + scrollUpButton.MouseButton1Click:connect( + function() + scrollMouseCount = scrollMouseCount + 1 + end) + scrollUpButton.MouseLeave:connect( + function() + scrollMouseCount = scrollMouseCount + 1 + end) + scrollUpButton.MouseButton1Down:connect( + function() + scrollMouseCount = scrollMouseCount + 1 + + scrollUp() + local val = scrollMouseCount + wait(0.5) + while val == scrollMouseCount do + if scrollUp() == false then + break + end + wait(0.1) + end + end) + + scrollUpButton.Parent = droppedDownMenu + + scrollDownButton = Instance.new("ImageButton") + scrollDownButton.Name = "ScrollDownButton" + scrollDownButton.BackgroundTransparency = 1 + scrollDownButton.Image = "rbxasset://textures/ui/scrollbuttonDown.png" + scrollDownButton.Size = UDim2.new(0,17,0,17) + scrollDownButton.Position = UDim2.new(1,-11,1,-11) + scrollDownButton.Parent = droppedDownMenu + scrollDownButton.MouseButton1Click:connect( + function() + scrollMouseCount = scrollMouseCount + 1 + end) + scrollDownButton.MouseLeave:connect( + function() + scrollMouseCount = scrollMouseCount + 1 + end) + scrollDownButton.MouseButton1Down:connect( + function() + scrollMouseCount = scrollMouseCount + 1 + + scrollDown() + local val = scrollMouseCount + wait(0.5) + while val == scrollMouseCount do + if scrollDown() == false then + break + end + wait(0.1) + end + end) + + local scrollbar = Instance.new("ImageLabel") + scrollbar.Name = "ScrollBar" + scrollbar.Image = "rbxasset://textures/ui/scrollbar.png" + scrollbar.BackgroundTransparency = 1 + scrollbar.Size = UDim2.new(0, 18, (dropDownItemCount*.8)/((dropDownItemCount+1)*.8), -(17) - 11 - 4) + scrollbar.Position = UDim2.new(1,-11,(1*.8)/((dropDownItemCount+1)*.8),17+2) + scrollbar.Parent = droppedDownMenu + end + + for i,item in ipairs(items) do + -- needed to maintain local scope for items in event listeners below + local button = choiceButton:clone() + if forRoblox then + button.RobloxLocked = true + end + button.Text = item + button.Parent = droppedDownMenu + if (whiteSkin) then + button.TextColor3 = textColor + end + + button.MouseButton1Click:connect(function() + --Remove Highlight + if (not whiteSkin) then + button.TextColor3 = Color3.new(1,1,1) + end + button.BackgroundTransparency = 1 + + updateSelection(item) + onSelect(item) + + toggleVisibility() + end) + button.MouseEnter:connect(function() + --Add Highlight + if (not whiteSkin) then + button.TextColor3 = Color3.new(0,0,0) + end + button.BackgroundTransparency = 0 + end) + + button.MouseLeave:connect(function() + --Remove Highlight + if (not whiteSkin) then + button.TextColor3 = Color3.new(1,1,1) + end + button.BackgroundTransparency = 1 + end) + end + + --This does the initial layout of the buttons + updateScroll() + + frame.AncestryChanged:connect(function(child,parent) + if parent == nil then + areaSoak.Parent = nil + else + areaSoak.Parent = getLayerCollectorAncestor(frame) + end + end) + + dropDownMenu.MouseButton1Click:connect(toggleVisibility) + areaSoak.MouseButton1Click:connect(toggleVisibility) + return frame, updateSelection +end + +t.CreatePropertyDropDownMenu = function(instance, property, enum) + + local items = enum:GetEnumItems() + local names = {} + local nameToItem = {} + for i,obj in ipairs(items) do + names[i] = obj.Name + nameToItem[obj.Name] = obj + end + + local frame + local updateSelection + frame, updateSelection = t.CreateDropDownMenu(names, function(text) instance[property] = nameToItem[text] end) + + ScopedConnect(frame, instance, "Changed", + function(prop) + if prop == property then + updateSelection(instance[property].Name) + end + end, + function() + updateSelection(instance[property].Name) + end) + + return frame +end + +t.GetFontHeight = function(font, fontSize) + if font == nil or fontSize == nil then + error("Font and FontSize must be non-nil") + end + + local fontSizeInt = tonumber(fontSize.Name:match("%d+")) -- Clever hack to extract the size from the enum itself. + + if font == Enum.Font.Legacy then -- Legacy has a 50% bigger size. + return math.ceil(fontSizeInt*1.5) + else -- Size is literally just the fontSizeInt + return fontSizeInt + end +end + +local function layoutGuiObjectsHelper(frame, guiObjects, settingsTable) + local totalPixels = frame.AbsoluteSize.Y + local pixelsRemaining = frame.AbsoluteSize.Y + for i, child in ipairs(guiObjects) do + if child:IsA("TextLabel") or child:IsA("TextButton") then + local isLabel = child:IsA("TextLabel") + if isLabel then + pixelsRemaining = pixelsRemaining - settingsTable["TextLabelPositionPadY"] + else + pixelsRemaining = pixelsRemaining - settingsTable["TextButtonPositionPadY"] + end + child.Position = UDim2.new(child.Position.X.Scale, child.Position.X.Offset, 0, totalPixels - pixelsRemaining) + child.Size = UDim2.new(child.Size.X.Scale, child.Size.X.Offset, 0, pixelsRemaining) + + if child.TextFits and child.TextBounds.Y < pixelsRemaining then + child.Visible = true + if isLabel then + child.Size = UDim2.new(child.Size.X.Scale, child.Size.X.Offset, 0, child.TextBounds.Y + settingsTable["TextLabelSizePadY"]) + else + child.Size = UDim2.new(child.Size.X.Scale, child.Size.X.Offset, 0, child.TextBounds.Y + settingsTable["TextButtonSizePadY"]) + end + + while not child.TextFits do + child.Size = UDim2.new(child.Size.X.Scale, child.Size.X.Offset, 0, child.AbsoluteSize.Y + 1) + end + pixelsRemaining = pixelsRemaining - child.AbsoluteSize.Y + + if isLabel then + pixelsRemaining = pixelsRemaining - settingsTable["TextLabelPositionPadY"] + else + pixelsRemaining = pixelsRemaining - settingsTable["TextButtonPositionPadY"] + end + else + child.Visible = false + pixelsRemaining = -1 + end + + else + --GuiObject + child.Position = UDim2.new(child.Position.X.Scale, child.Position.X.Offset, 0, totalPixels - pixelsRemaining) + pixelsRemaining = pixelsRemaining - child.AbsoluteSize.Y + child.Visible = (pixelsRemaining >= 0) + end + end +end + +t.LayoutGuiObjects = function(frame, guiObjects, settingsTable) + if not frame:IsA("GuiObject") then + error("Frame must be a GuiObject") + end + for i, child in ipairs(guiObjects) do + if not child:IsA("GuiObject") then + error("All elements that are layed out must be of type GuiObject") + end + end + + if not settingsTable then + settingsTable = {} + end + + if not settingsTable["TextLabelSizePadY"] then + settingsTable["TextLabelSizePadY"] = 0 + end + if not settingsTable["TextLabelPositionPadY"] then + settingsTable["TextLabelPositionPadY"] = 0 + end + if not settingsTable["TextButtonSizePadY"] then + settingsTable["TextButtonSizePadY"] = 12 + end + if not settingsTable["TextButtonPositionPadY"] then + settingsTable["TextButtonPositionPadY"] = 2 + end + + --Wrapper frame takes care of styled objects + local wrapperFrame = Instance.new("Frame") + wrapperFrame.Name = "WrapperFrame" + wrapperFrame.BackgroundTransparency = 1 + wrapperFrame.Size = UDim2.new(1,0,1,0) + wrapperFrame.Parent = frame + + for i, child in ipairs(guiObjects) do + child.Parent = wrapperFrame + end + + local recalculate = function() + wait() + layoutGuiObjectsHelper(wrapperFrame, guiObjects, settingsTable) + end + + frame.Changed:connect( + function(prop) + if prop == "AbsoluteSize" then + --Wait a heartbeat for it to sync in + recalculate(nil) + end + end) + frame.AncestryChanged:connect(recalculate) + + layoutGuiObjectsHelper(wrapperFrame, guiObjects, settingsTable) +end + + +t.CreateSlider = function(steps,width,position) + local sliderGui = Instance.new("Frame") + sliderGui.Size = UDim2.new(1,0,1,0) + sliderGui.BackgroundTransparency = 1 + sliderGui.Name = "SliderGui" + + local sliderSteps = Instance.new("IntValue") + sliderSteps.Name = "SliderSteps" + sliderSteps.Value = steps + sliderSteps.Parent = sliderGui + + local areaSoak = Instance.new("TextButton") + areaSoak.Name = "AreaSoak" + areaSoak.Text = "" + areaSoak.BackgroundTransparency = 1 + areaSoak.Active = false + areaSoak.Size = UDim2.new(1,0,1,0) + areaSoak.Visible = false + areaSoak.ZIndex = 4 + + sliderGui.AncestryChanged:connect(function(child,parent) + if parent == nil then + areaSoak.Parent = nil + else + areaSoak.Parent = getLayerCollectorAncestor(sliderGui) + end + end) + + local sliderPosition = Instance.new("IntValue") + sliderPosition.Name = "SliderPosition" + sliderPosition.Value = 0 + sliderPosition.Parent = sliderGui + + local id = math.random(1,100) + + local bar = Instance.new("TextButton") + bar.Text = "" + bar.AutoButtonColor = false + bar.Name = "Bar" + bar.BackgroundColor3 = Color3.new(0,0,0) + if type(width) == "number" then + bar.Size = UDim2.new(0,width,0,5) + else + bar.Size = UDim2.new(0,200,0,5) + end + bar.BorderColor3 = Color3.new(95/255,95/255,95/255) + bar.ZIndex = 2 + bar.Parent = sliderGui + + if position["X"] and position["X"]["Scale"] and position["X"]["Offset"] and position["Y"] and position["Y"]["Scale"] and position["Y"]["Offset"] then + bar.Position = position + end + + local slider = Instance.new("ImageButton") + slider.Name = "Slider" + slider.BackgroundTransparency = 1 + slider.Image = "rbxasset://textures/ui/Slider.png" + slider.Position = UDim2.new(0,0,0.5,-10) + slider.Size = UDim2.new(0,20,0,20) + slider.ZIndex = 3 + slider.Parent = bar + + local areaSoakMouseMoveCon = nil + + areaSoak.MouseLeave:connect(function() + if areaSoak.Visible then + cancelSlide(areaSoak) + end + end) + areaSoak.MouseButton1Up:connect(function() + if areaSoak.Visible then + cancelSlide(areaSoak) + end + end) + + slider.MouseButton1Down:connect(function() + areaSoak.Visible = true + if areaSoakMouseMoveCon then areaSoakMouseMoveCon:disconnect() end + areaSoakMouseMoveCon = areaSoak.MouseMoved:connect(function(x,y) + setSliderPos(x,slider,sliderPosition,bar,steps) + end) + end) + + slider.MouseButton1Up:connect(function() cancelSlide(areaSoak) end) + + sliderPosition.Changed:connect(function(prop) + sliderPosition.Value = math.min(steps, math.max(1,sliderPosition.Value)) + local relativePosX = (sliderPosition.Value - 1) / (steps - 1) + slider.Position = UDim2.new(relativePosX,-slider.AbsoluteSize.X/2,slider.Position.Y.Scale,slider.Position.Y.Offset) + end) + + bar.MouseButton1Down:connect(function(x,y) + setSliderPos(x,slider,sliderPosition,bar,steps) + end) + + return sliderGui, sliderPosition, sliderSteps + +end + + + +t.CreateSliderNew = function(steps,width,position) + local sliderGui = Instance.new("Frame") + sliderGui.Size = UDim2.new(1,0,1,0) + sliderGui.BackgroundTransparency = 1 + sliderGui.Name = "SliderGui" + + local sliderSteps = Instance.new("IntValue") + sliderSteps.Name = "SliderSteps" + sliderSteps.Value = steps + sliderSteps.Parent = sliderGui + + local areaSoak = Instance.new("TextButton") + areaSoak.Name = "AreaSoak" + areaSoak.Text = "" + areaSoak.BackgroundTransparency = 1 + areaSoak.Active = false + areaSoak.Size = UDim2.new(1,0,1,0) + areaSoak.Visible = false + areaSoak.ZIndex = 6 + + sliderGui.AncestryChanged:connect(function(child,parent) + if parent == nil then + areaSoak.Parent = nil + else + areaSoak.Parent = getLayerCollectorAncestor(sliderGui) + end + end) + + local sliderPosition = Instance.new("IntValue") + sliderPosition.Name = "SliderPosition" + sliderPosition.Value = 0 + sliderPosition.Parent = sliderGui + + local id = math.random(1,100) + + local sliderBarImgHeight = 7 + local sliderBarCapImgWidth = 4 + + local bar = Instance.new("ImageButton") + bar.BackgroundTransparency = 1 + bar.Image = "rbxasset://textures/ui/Slider-BKG-Center.png" + bar.Name = "Bar" + local displayWidth = 200 + if type(width) == "number" then + bar.Size = UDim2.new(0,width - (sliderBarCapImgWidth * 2),0,sliderBarImgHeight) + displayWidth = width - (sliderBarCapImgWidth * 2) + else + bar.Size = UDim2.new(0,200,0,sliderBarImgHeight) + end + bar.ZIndex = 3 + bar.Parent = sliderGui + if position["X"] and position["X"]["Scale"] and position["X"]["Offset"] and position["Y"] and position["Y"]["Scale"] and position["Y"]["Offset"] then + bar.Position = position + end + + local barLeft = bar:clone() + barLeft.Name = "BarLeft" + barLeft.Image = "rbxasset://textures/ui/Slider-BKG-Left-Cap.png" + barLeft.Size = UDim2.new(0, sliderBarCapImgWidth, 0, sliderBarImgHeight) + barLeft.Position = UDim2.new(position.X.Scale, position.X.Offset - sliderBarCapImgWidth, position.Y.Scale, position.Y.Offset) + barLeft.Parent = sliderGui + barLeft.ZIndex = 3 + + local barRight = barLeft:clone() + barRight.Name = "BarRight" + barRight.Image = "rbxasset://textures/ui/Slider-BKG-Right-Cap.png" + barRight.Position = UDim2.new(position.X.Scale, position.X.Offset + displayWidth, position.Y.Scale, position.Y.Offset) + barRight.Parent = sliderGui + + local fillLeft = barLeft:clone() + fillLeft.Name = "FillLeft" + fillLeft.Image = "rbxasset://textures/ui/Slider-Fill-Left-Cap.png" + fillLeft.Parent = sliderGui + fillLeft.ZIndex = 4 + + local fill = fillLeft:clone() + fill.Name = "Fill" + fill.Image = "rbxasset://textures/ui/Slider-Fill-Center.png" + fill.Parent = bar + fill.ZIndex = 4 + fill.Position = UDim2.new(0, 0, 0, 0) + fill.Size = UDim2.new(0.5, 0, 1, 0) + + +-- bar.Visible = false + + local slider = Instance.new("ImageButton") + slider.Name = "Slider" + slider.BackgroundTransparency = 1 + slider.Image = "rbxasset://textures/ui/slider_new_tab.png" + slider.Position = UDim2.new(0,0,0.5,-14) + slider.Size = UDim2.new(0,28,0,28) + slider.ZIndex = 5 + slider.Parent = bar + + local areaSoakMouseMoveCon = nil + + areaSoak.MouseLeave:connect(function() + if areaSoak.Visible then + cancelSlide(areaSoak) + end + end) + areaSoak.MouseButton1Up:connect(function() + if areaSoak.Visible then + cancelSlide(areaSoak) + end + end) + + slider.MouseButton1Down:connect(function() + areaSoak.Visible = true + if areaSoakMouseMoveCon then areaSoakMouseMoveCon:disconnect() end + areaSoakMouseMoveCon = areaSoak.MouseMoved:connect(function(x,y) + setSliderPos(x,slider,sliderPosition,bar,steps) + end) + end) + + slider.MouseButton1Up:connect(function() cancelSlide(areaSoak) end) + + sliderPosition.Changed:connect(function(prop) + sliderPosition.Value = math.min(steps, math.max(1,sliderPosition.Value)) + local relativePosX = (sliderPosition.Value - 1) / (steps - 1) + slider.Position = UDim2.new(relativePosX,-slider.AbsoluteSize.X/2,slider.Position.Y.Scale,slider.Position.Y.Offset) + fill.Size = UDim2.new(relativePosX, 0, 1, 0) + end) + + bar.MouseButton1Down:connect(function(x,y) + setSliderPos(x,slider,sliderPosition,bar,steps) + end) + + fill.MouseButton1Down:connect(function(x,y) + setSliderPos(x,slider,sliderPosition,bar,steps) + end) + + fillLeft.MouseButton1Down:connect(function(x,y) + setSliderPos(x,slider,sliderPosition,bar,steps) + end) + + + return sliderGui, sliderPosition, sliderSteps + +end + + + + + +t.CreateTrueScrollingFrame = function() + local lowY = nil + local highY = nil + + local dragCon = nil + local upCon = nil + + local internalChange = false + + local descendantsChangeConMap = {} + + local scrollingFrame = Instance.new("Frame") + scrollingFrame.Name = "ScrollingFrame" + scrollingFrame.Active = true + scrollingFrame.Size = UDim2.new(1,0,1,0) + scrollingFrame.ClipsDescendants = true + + local controlFrame = Instance.new("Frame") + controlFrame.Name = "ControlFrame" + controlFrame.BackgroundTransparency = 1 + controlFrame.Size = UDim2.new(0,18,1,0) + controlFrame.Position = UDim2.new(1,-20,0,0) + controlFrame.Parent = scrollingFrame + + local scrollBottom = Instance.new("BoolValue") + scrollBottom.Value = false + scrollBottom.Name = "ScrollBottom" + scrollBottom.Parent = controlFrame + + local scrollUp = Instance.new("BoolValue") + scrollUp.Value = false + scrollUp.Name = "scrollUp" + scrollUp.Parent = controlFrame + + local scrollUpButton = Instance.new("TextButton") + scrollUpButton.Name = "ScrollUpButton" + scrollUpButton.Text = "" + scrollUpButton.AutoButtonColor = false + scrollUpButton.BackgroundColor3 = Color3.new(0,0,0) + scrollUpButton.BorderColor3 = Color3.new(1,1,1) + scrollUpButton.BackgroundTransparency = 0.5 + scrollUpButton.Size = UDim2.new(0,18,0,18) + scrollUpButton.ZIndex = 2 + scrollUpButton.Parent = controlFrame + for i = 1, 6 do + local triFrame = Instance.new("Frame") + triFrame.BorderColor3 = Color3.new(1,1,1) + triFrame.Name = "tri" .. tostring(i) + triFrame.ZIndex = 3 + triFrame.BackgroundTransparency = 0.5 + triFrame.Size = UDim2.new(0,12 - ((i -1) * 2),0,0) + triFrame.Position = UDim2.new(0,3 + (i -1),0.5,2 - (i -1)) + triFrame.Parent = scrollUpButton + end + scrollUpButton.MouseEnter:connect(function() + scrollUpButton.BackgroundTransparency = 0.1 + local upChildren = scrollUpButton:GetChildren() + for i = 1, #upChildren do + upChildren[i].BackgroundTransparency = 0.1 + end + end) + scrollUpButton.MouseLeave:connect(function() + scrollUpButton.BackgroundTransparency = 0.5 + local upChildren = scrollUpButton:GetChildren() + for i = 1, #upChildren do + upChildren[i].BackgroundTransparency = 0.5 + end + end) + + local scrollDownButton = scrollUpButton:clone() + scrollDownButton.Name = "ScrollDownButton" + scrollDownButton.Position = UDim2.new(0,0,1,-18) + local downChildren = scrollDownButton:GetChildren() + for i = 1, #downChildren do + downChildren[i].Position = UDim2.new(0,3 + (i -1),0.5,-2 + (i - 1)) + end + scrollDownButton.MouseEnter:connect(function() + scrollDownButton.BackgroundTransparency = 0.1 + local downChildren = scrollDownButton:GetChildren() + for i = 1, #downChildren do + downChildren[i].BackgroundTransparency = 0.1 + end + end) + scrollDownButton.MouseLeave:connect(function() + scrollDownButton.BackgroundTransparency = 0.5 + local downChildren = scrollDownButton:GetChildren() + for i = 1, #downChildren do + downChildren[i].BackgroundTransparency = 0.5 + end + end) + scrollDownButton.Parent = controlFrame + + local scrollTrack = Instance.new("Frame") + scrollTrack.Name = "ScrollTrack" + scrollTrack.BackgroundTransparency = 1 + scrollTrack.Size = UDim2.new(0,18,1,-38) + scrollTrack.Position = UDim2.new(0,0,0,19) + scrollTrack.Parent = controlFrame + + local scrollbar = Instance.new("TextButton") + scrollbar.BackgroundColor3 = Color3.new(0,0,0) + scrollbar.BorderColor3 = Color3.new(1,1,1) + scrollbar.BackgroundTransparency = 0.5 + scrollbar.AutoButtonColor = false + scrollbar.Text = "" + scrollbar.Active = true + scrollbar.Name = "ScrollBar" + scrollbar.ZIndex = 2 + scrollbar.BackgroundTransparency = 0.5 + scrollbar.Size = UDim2.new(0, 18, 0.1, 0) + scrollbar.Position = UDim2.new(0,0,0,0) + scrollbar.Parent = scrollTrack + + local scrollNub = Instance.new("Frame") + scrollNub.Name = "ScrollNub" + scrollNub.BorderColor3 = Color3.new(1,1,1) + scrollNub.Size = UDim2.new(0,10,0,0) + scrollNub.Position = UDim2.new(0.5,-5,0.5,0) + scrollNub.ZIndex = 2 + scrollNub.BackgroundTransparency = 0.5 + scrollNub.Parent = scrollbar + + local newNub = scrollNub:clone() + newNub.Position = UDim2.new(0.5,-5,0.5,-2) + newNub.Parent = scrollbar + + local lastNub = scrollNub:clone() + lastNub.Position = UDim2.new(0.5,-5,0.5,2) + lastNub.Parent = scrollbar + + scrollbar.MouseEnter:connect(function() + scrollbar.BackgroundTransparency = 0.1 + scrollNub.BackgroundTransparency = 0.1 + newNub.BackgroundTransparency = 0.1 + lastNub.BackgroundTransparency = 0.1 + end) + scrollbar.MouseLeave:connect(function() + scrollbar.BackgroundTransparency = 0.5 + scrollNub.BackgroundTransparency = 0.5 + newNub.BackgroundTransparency = 0.5 + lastNub.BackgroundTransparency = 0.5 + end) + + local mouseDrag = Instance.new("ImageButton") + mouseDrag.Active = false + mouseDrag.Size = UDim2.new(1.5, 0, 1.5, 0) + mouseDrag.AutoButtonColor = false + mouseDrag.BackgroundTransparency = 1 + mouseDrag.Name = "mouseDrag" + mouseDrag.Position = UDim2.new(-0.25, 0, -0.25, 0) + mouseDrag.ZIndex = 10 + + local function positionScrollBar(x,y,offset) + local oldPos = scrollbar.Position + + if y < scrollTrack.AbsolutePosition.y then + scrollbar.Position = UDim2.new(scrollbar.Position.X.Scale,scrollbar.Position.X.Offset,0,0) + return (oldPos ~= scrollbar.Position) + end + + local relativeSize = scrollbar.AbsoluteSize.Y/scrollTrack.AbsoluteSize.Y + + if y > (scrollTrack.AbsolutePosition.y + scrollTrack.AbsoluteSize.y) then + scrollbar.Position = UDim2.new(scrollbar.Position.X.Scale,scrollbar.Position.X.Offset,1 - relativeSize,0) + return (oldPos ~= scrollbar.Position) + end + local newScaleYPos = (y - scrollTrack.AbsolutePosition.y - offset)/scrollTrack.AbsoluteSize.y + if newScaleYPos + relativeSize > 1 then + newScaleYPos = 1 - relativeSize + scrollBottom.Value = true + scrollUp.Value = false + elseif newScaleYPos <= 0 then + newScaleYPos = 0 + scrollUp.Value = true + scrollBottom.Value = false + else + scrollUp.Value = false + scrollBottom.Value = false + end + scrollbar.Position = UDim2.new(scrollbar.Position.X.Scale,scrollbar.Position.X.Offset,newScaleYPos,0) + + return (oldPos ~= scrollbar.Position) + end + + local function drillDownSetHighLow(instance) + if not instance or not instance:IsA("GuiObject") then return end + if instance == controlFrame then return end + if instance:IsDescendantOf(controlFrame) then return end + if not instance.Visible then return end + + if lowY and lowY > instance.AbsolutePosition.Y then + lowY = instance.AbsolutePosition.Y + elseif not lowY then + lowY = instance.AbsolutePosition.Y + end + if highY and highY < (instance.AbsolutePosition.Y + instance.AbsoluteSize.Y) then + highY = instance.AbsolutePosition.Y + instance.AbsoluteSize.Y + elseif not highY then + highY = instance.AbsolutePosition.Y + instance.AbsoluteSize.Y + end + local children = instance:GetChildren() + for i = 1, #children do + drillDownSetHighLow(children[i]) + end + end + + local function resetHighLow() + local firstChildren = scrollingFrame:GetChildren() + + for i = 1, #firstChildren do + drillDownSetHighLow(firstChildren[i]) + end + end + + local function recalculate() + internalChange = true + + local percentFrame = 0 + if scrollbar.Position.Y.Scale > 0 then + if scrollbar.Visible then + percentFrame = scrollbar.Position.Y.Scale/((scrollTrack.AbsoluteSize.Y - scrollbar.AbsoluteSize.Y)/scrollTrack.AbsoluteSize.Y) + else + percentFrame = 0 + end + end + if percentFrame > 0.99 then percentFrame = 1 end + + local hiddenYAmount = (scrollingFrame.AbsoluteSize.Y - (highY - lowY)) * percentFrame + + local guiChildren = scrollingFrame:GetChildren() + for i = 1, #guiChildren do + if guiChildren[i] ~= controlFrame then + guiChildren[i].Position = UDim2.new(guiChildren[i].Position.X.Scale,guiChildren[i].Position.X.Offset, + 0, math.ceil(guiChildren[i].AbsolutePosition.Y) - math.ceil(lowY) + hiddenYAmount) + end + end + + lowY = nil + highY = nil + resetHighLow() + internalChange = false + end + + local function setSliderSizeAndPosition() + if not highY or not lowY then return end + + local totalYSpan = math.abs(highY - lowY) + if totalYSpan == 0 then + scrollbar.Visible = false + scrollDownButton.Visible = false + scrollUpButton.Visible = false + + if dragCon then dragCon:disconnect() dragCon = nil end + if upCon then upCon:disconnect() upCon = nil end + return + end + + local percentShown = scrollingFrame.AbsoluteSize.Y/totalYSpan + if percentShown >= 1 then + scrollbar.Visible = false + scrollDownButton.Visible = false + scrollUpButton.Visible = false + recalculate() + else + scrollbar.Visible = true + scrollDownButton.Visible = true + scrollUpButton.Visible = true + + scrollbar.Size = UDim2.new(scrollbar.Size.X.Scale,scrollbar.Size.X.Offset,percentShown,0) + end + + local percentPosition = (scrollingFrame.AbsolutePosition.Y - lowY)/totalYSpan + scrollbar.Position = UDim2.new(scrollbar.Position.X.Scale,scrollbar.Position.X.Offset,percentPosition,-scrollbar.AbsoluteSize.X/2) + + if scrollbar.AbsolutePosition.y < scrollTrack.AbsolutePosition.y then + scrollbar.Position = UDim2.new(scrollbar.Position.X.Scale,scrollbar.Position.X.Offset,0,0) + end + + if (scrollbar.AbsolutePosition.y + scrollbar.AbsoluteSize.Y) > (scrollTrack.AbsolutePosition.y + scrollTrack.AbsoluteSize.y) then + local relativeSize = scrollbar.AbsoluteSize.Y/scrollTrack.AbsoluteSize.Y + scrollbar.Position = UDim2.new(scrollbar.Position.X.Scale,scrollbar.Position.X.Offset,1 - relativeSize,0) + end + end + + local buttonScrollAmountPixels = 7 + local reentrancyGuardScrollUp = false + local function doScrollUp() + if reentrancyGuardScrollUp then return end + + reentrancyGuardScrollUp = true + if positionScrollBar(0,scrollbar.AbsolutePosition.Y - buttonScrollAmountPixels,0) then + recalculate() + end + reentrancyGuardScrollUp = false + end + + local reentrancyGuardScrollDown = false + local function doScrollDown() + if reentrancyGuardScrollDown then return end + + reentrancyGuardScrollDown = true + if positionScrollBar(0,scrollbar.AbsolutePosition.Y + buttonScrollAmountPixels,0) then + recalculate() + end + reentrancyGuardScrollDown = false + end + + local function scrollUp(mouseYPos) + if scrollUpButton.Active then + scrollStamp = tick() + local current = scrollStamp + local upCon + upCon = mouseDrag.MouseButton1Up:connect(function() + scrollStamp = tick() + mouseDrag.Parent = nil + upCon:disconnect() + end) + mouseDrag.Parent = getLayerCollectorAncestor(scrollbar) + doScrollUp() + wait(0.2) + local t = tick() + local w = 0.1 + while scrollStamp == current do + doScrollUp() + if mouseYPos and mouseYPos > scrollbar.AbsolutePosition.y then + break + end + if not scrollUpButton.Active then break end + if tick()-t > 5 then + w = 0 + elseif tick()-t > 2 then + w = 0.06 + end + wait(w) + end + end + end + + local function scrollDown(mouseYPos) + if scrollDownButton.Active then + scrollStamp = tick() + local current = scrollStamp + local downCon + downCon = mouseDrag.MouseButton1Up:connect(function() + scrollStamp = tick() + mouseDrag.Parent = nil + downCon:disconnect() + end) + mouseDrag.Parent = getLayerCollectorAncestor(scrollbar) + doScrollDown() + wait(0.2) + local t = tick() + local w = 0.1 + while scrollStamp == current do + doScrollDown() + if mouseYPos and mouseYPos < (scrollbar.AbsolutePosition.y + scrollbar.AbsoluteSize.x) then + break + end + if not scrollDownButton.Active then break end + if tick()-t > 5 then + w = 0 + elseif tick()-t > 2 then + w = 0.06 + end + wait(w) + end + end + end + + scrollbar.MouseButton1Down:connect(function(x,y) + if scrollbar.Active then + scrollStamp = tick() + local mouseOffset = y - scrollbar.AbsolutePosition.y + if dragCon then dragCon:disconnect() dragCon = nil end + if upCon then upCon:disconnect() upCon = nil end + local prevY = y + local reentrancyGuardMouseScroll = false + dragCon = mouseDrag.MouseMoved:connect(function(x,y) + if reentrancyGuardMouseScroll then return end + + reentrancyGuardMouseScroll = true + if positionScrollBar(x,y,mouseOffset) then + recalculate() + end + reentrancyGuardMouseScroll = false + + end) + upCon = mouseDrag.MouseButton1Up:connect(function() + scrollStamp = tick() + mouseDrag.Parent = nil + dragCon:disconnect(); dragCon = nil + upCon:disconnect(); drag = nil + end) + mouseDrag.Parent = getLayerCollectorAncestor(scrollbar) + end + end) + + local scrollMouseCount = 0 + + scrollUpButton.MouseButton1Down:connect(function() + scrollUp() + end) + scrollUpButton.MouseButton1Up:connect(function() + scrollStamp = tick() + end) + + scrollDownButton.MouseButton1Up:connect(function() + scrollStamp = tick() + end) + scrollDownButton.MouseButton1Down:connect(function() + scrollDown() + end) + + scrollbar.MouseButton1Up:connect(function() + scrollStamp = tick() + end) + + local function heightCheck(instance) + if highY and (instance.AbsolutePosition.Y + instance.AbsoluteSize.Y) > highY then + highY = instance.AbsolutePosition.Y + instance.AbsoluteSize.Y + elseif not highY then + highY = instance.AbsolutePosition.Y + instance.AbsoluteSize.Y + end + setSliderSizeAndPosition() + end + + local function highLowRecheck() + local oldLowY = lowY + local oldHighY = highY + lowY = nil + highY = nil + resetHighLow() + + if (lowY ~= oldLowY) or (highY ~= oldHighY) then + setSliderSizeAndPosition() + end + end + + local function descendantChanged(this, prop) + if internalChange then return end + if not this.Visible then return end + + if prop == "Size" or prop == "Position" then + wait() + highLowRecheck() + end + end + + scrollingFrame.DescendantAdded:connect(function(instance) + if not instance:IsA("GuiObject") then return end + + if instance.Visible then + wait() -- wait a heartbeat for sizes to reconfig + highLowRecheck() + end + + descendantsChangeConMap[instance] = instance.Changed:connect(function(prop) descendantChanged(instance, prop) end) + end) + + scrollingFrame.DescendantRemoving:connect(function(instance) + if not instance:IsA("GuiObject") then return end + if descendantsChangeConMap[instance] then + descendantsChangeConMap[instance]:disconnect() + descendantsChangeConMap[instance] = nil + end + wait() -- wait a heartbeat for sizes to reconfig + highLowRecheck() + end) + + scrollingFrame.Changed:connect(function(prop) + if prop == "AbsoluteSize" then + if not highY or not lowY then return end + + highLowRecheck() + setSliderSizeAndPosition() + end + end) + + return scrollingFrame, controlFrame +end + +t.CreateScrollingFrame = function(orderList,scrollStyle) + local frame = Instance.new("Frame") + frame.Name = "ScrollingFrame" + frame.BackgroundTransparency = 1 + frame.Size = UDim2.new(1,0,1,0) + + local scrollUpButton = Instance.new("ImageButton") + scrollUpButton.Name = "ScrollUpButton" + scrollUpButton.BackgroundTransparency = 1 + scrollUpButton.Image = "rbxasset://textures/ui/scrollbuttonUp.png" + scrollUpButton.Size = UDim2.new(0,17,0,17) + + + local scrollDownButton = Instance.new("ImageButton") + scrollDownButton.Name = "ScrollDownButton" + scrollDownButton.BackgroundTransparency = 1 + scrollDownButton.Image = "rbxasset://textures/ui/scrollbuttonDown.png" + scrollDownButton.Size = UDim2.new(0,17,0,17) + + local scrollbar = Instance.new("ImageButton") + scrollbar.Name = "ScrollBar" + scrollbar.Image = "rbxasset://textures/ui/scrollbar.png" + scrollbar.BackgroundTransparency = 1 + scrollbar.Size = UDim2.new(0, 18, 0, 150) + + local scrollStamp = 0 + + local scrollDrag = Instance.new("ImageButton") + scrollDrag.Image = "https://www.roblox.com/asset/?id=61367186" + scrollDrag.Size = UDim2.new(1, 0, 0, 16) + scrollDrag.BackgroundTransparency = 1 + scrollDrag.Name = "ScrollDrag" + scrollDrag.Active = true + scrollDrag.Parent = scrollbar + + local mouseDrag = Instance.new("ImageButton") + mouseDrag.Active = false + mouseDrag.Size = UDim2.new(1.5, 0, 1.5, 0) + mouseDrag.AutoButtonColor = false + mouseDrag.BackgroundTransparency = 1 + mouseDrag.Name = "mouseDrag" + mouseDrag.Position = UDim2.new(-0.25, 0, -0.25, 0) + mouseDrag.ZIndex = 10 + + local style = "simple" + if scrollStyle and tostring(scrollStyle) then + style = scrollStyle + end + + local scrollPosition = 1 + local rowSize = 0 + local howManyDisplayed = 0 + + local layoutGridScrollBar = function() + howManyDisplayed = 0 + local guiObjects = {} + if orderList then + for i, child in ipairs(orderList) do + if child.Parent == frame then + table.insert(guiObjects, child) + end + end + else + local children = frame:GetChildren() + if children then + for i, child in ipairs(children) do + if child:IsA("GuiObject") then + table.insert(guiObjects, child) + end + end + end + end + if #guiObjects == 0 then + scrollUpButton.Active = false + scrollDownButton.Active = false + scrollDrag.Active = false + scrollPosition = 1 + return + end + + if scrollPosition > #guiObjects then + scrollPosition = #guiObjects + end + + if scrollPosition < 1 then scrollPosition = 1 end + + local totalPixelsY = frame.AbsoluteSize.Y + local pixelsRemainingY = frame.AbsoluteSize.Y + + local totalPixelsX = frame.AbsoluteSize.X + + local xCounter = 0 + local rowSizeCounter = 0 + local setRowSize = true + + local pixelsBelowScrollbar = 0 + local pos = #guiObjects + + local currentRowY = 0 + + pos = scrollPosition + --count up from current scroll position to fill out grid + while pos <= #guiObjects and pixelsBelowScrollbar < totalPixelsY do + xCounter = xCounter + guiObjects[pos].AbsoluteSize.X + --previous pos was the end of a row + if xCounter >= totalPixelsX then + pixelsBelowScrollbar = pixelsBelowScrollbar + currentRowY + currentRowY = 0 + xCounter = guiObjects[pos].AbsoluteSize.X + end + if guiObjects[pos].AbsoluteSize.Y > currentRowY then + currentRowY = guiObjects[pos].AbsoluteSize.Y + end + pos = pos + 1 + end + --Count wherever current row left off + pixelsBelowScrollbar = pixelsBelowScrollbar + currentRowY + currentRowY = 0 + + pos = scrollPosition - 1 + xCounter = 0 + + --objects with varying X,Y dimensions can rarely cause minor errors + --rechecking every new scrollPosition is necessary to avoid 100% of errors + + --count backwards from current scrollPosition to see if we can add more rows + while pixelsBelowScrollbar + currentRowY < totalPixelsY and pos >= 1 do + xCounter = xCounter + guiObjects[pos].AbsoluteSize.X + rowSizeCounter = rowSizeCounter + 1 + if xCounter >= totalPixelsX then + rowSize = rowSizeCounter - 1 + rowSizeCounter = 0 + xCounter = guiObjects[pos].AbsoluteSize.X + if pixelsBelowScrollbar + currentRowY <= totalPixelsY then + --It fits, so back up our scroll position + pixelsBelowScrollbar = pixelsBelowScrollbar + currentRowY + if scrollPosition <= rowSize then + scrollPosition = 1 + break + else + scrollPosition = scrollPosition - rowSize + end + currentRowY = 0 + else + break + end + end + + if guiObjects[pos].AbsoluteSize.Y > currentRowY then + currentRowY = guiObjects[pos].AbsoluteSize.Y + end + + pos = pos - 1 + end + + --Do check last time if pos = 0 + if (pos == 0) and (pixelsBelowScrollbar + currentRowY <= totalPixelsY) then + scrollPosition = 1 + end + + xCounter = 0 + --pos = scrollPosition + rowSizeCounter = 0 + setRowSize = true + local lastChildSize = 0 + + local xOffset,yOffset = 0 + if guiObjects[1] then + yOffset = math.ceil(math.floor(math.fmod(totalPixelsY,guiObjects[1].AbsoluteSize.X))/2) + xOffset = math.ceil(math.floor(math.fmod(totalPixelsX,guiObjects[1].AbsoluteSize.Y))/2) + end + + for i, child in ipairs(guiObjects) do + if i < scrollPosition then + child.Visible = false + else + if pixelsRemainingY < 0 then + child.Visible = false + else + --GuiObject + if setRowSize then rowSizeCounter = rowSizeCounter + 1 end + if xCounter + child.AbsoluteSize.X >= totalPixelsX then + if setRowSize then + rowSize = rowSizeCounter - 1 + setRowSize = false + end + xCounter = 0 + pixelsRemainingY = pixelsRemainingY - child.AbsoluteSize.Y + end + child.Position = UDim2.new(child.Position.X.Scale,xCounter + xOffset, 0, totalPixelsY - pixelsRemainingY + yOffset) + xCounter = xCounter + child.AbsoluteSize.X + child.Visible = ((pixelsRemainingY - child.AbsoluteSize.Y) >= 0) + if child.Visible then + howManyDisplayed = howManyDisplayed + 1 + end + lastChildSize = child.AbsoluteSize + end + end + end + + scrollUpButton.Active = (scrollPosition > 1) + if lastChildSize == 0 then + scrollDownButton.Active = false + else + scrollDownButton.Active = ((pixelsRemainingY - lastChildSize.Y) < 0) + end + scrollDrag.Active = #guiObjects > howManyDisplayed + scrollDrag.Visible = scrollDrag.Active + end + + + + local layoutSimpleScrollBar = function() + local guiObjects = {} + howManyDisplayed = 0 + + if orderList then + for i, child in ipairs(orderList) do + if child.Parent == frame then + table.insert(guiObjects, child) + end + end + else + local children = frame:GetChildren() + if children then + for i, child in ipairs(children) do + if child:IsA("GuiObject") then + table.insert(guiObjects, child) + end + end + end + end + if #guiObjects == 0 then + scrollUpButton.Active = false + scrollDownButton.Active = false + scrollDrag.Active = false + scrollPosition = 1 + return + end + + if scrollPosition > #guiObjects then + scrollPosition = #guiObjects + end + + local totalPixels = frame.AbsoluteSize.Y + local pixelsRemaining = frame.AbsoluteSize.Y + + local pixelsBelowScrollbar = 0 + local pos = #guiObjects + while pixelsBelowScrollbar < totalPixels and pos >= 1 do + if pos >= scrollPosition then + pixelsBelowScrollbar = pixelsBelowScrollbar + guiObjects[pos].AbsoluteSize.Y + else + if pixelsBelowScrollbar + guiObjects[pos].AbsoluteSize.Y <= totalPixels then + --It fits, so back up our scroll position + pixelsBelowScrollbar = pixelsBelowScrollbar + guiObjects[pos].AbsoluteSize.Y + if scrollPosition <= 1 then + scrollPosition = 1 + break + else + --local ("Backing up ScrollPosition from -- " ..scrollPosition) + scrollPosition = scrollPosition - 1 + end + else + break + end + end + pos = pos - 1 + end + + pos = scrollPosition + for i, child in ipairs(guiObjects) do + if i < scrollPosition then + child.Visible = false + else + if pixelsRemaining < 0 then + child.Visible = false + else + --GuiObject + child.Position = UDim2.new(child.Position.X.Scale, child.Position.X.Offset, 0, totalPixels - pixelsRemaining) + pixelsRemaining = pixelsRemaining - child.AbsoluteSize.Y + if (pixelsRemaining >= 0) then + child.Visible = true + howManyDisplayed = howManyDisplayed + 1 + else + child.Visible = false + end + end + end + end + scrollUpButton.Active = (scrollPosition > 1) + scrollDownButton.Active = (pixelsRemaining < 0) + scrollDrag.Active = #guiObjects > howManyDisplayed + scrollDrag.Visible = scrollDrag.Active + end + + + local moveDragger = function() + local guiObjects = 0 + local children = frame:GetChildren() + if children then + for i, child in ipairs(children) do + if child:IsA("GuiObject") then + guiObjects = guiObjects + 1 + end + end + end + + if not scrollDrag.Parent then return end + + local dragSizeY = scrollDrag.Parent.AbsoluteSize.y * (1/(guiObjects - howManyDisplayed + 1)) + if dragSizeY < 16 then dragSizeY = 16 end + scrollDrag.Size = UDim2.new(scrollDrag.Size.X.Scale,scrollDrag.Size.X.Offset,scrollDrag.Size.Y.Scale,dragSizeY) + + local relativeYPos = (scrollPosition - 1)/(guiObjects - (howManyDisplayed)) + if relativeYPos > 1 then relativeYPos = 1 + elseif relativeYPos < 0 then relativeYPos = 0 end + local absYPos = 0 + + if relativeYPos ~= 0 then + absYPos = (relativeYPos * scrollbar.AbsoluteSize.y) - (relativeYPos * scrollDrag.AbsoluteSize.y) + end + + scrollDrag.Position = UDim2.new(scrollDrag.Position.X.Scale,scrollDrag.Position.X.Offset,scrollDrag.Position.Y.Scale,absYPos) + end + + local reentrancyGuard = false + local recalculate = function() + if reentrancyGuard then + return + end + reentrancyGuard = true + wait() + local success, err = nil + if style == "grid" then + success, err = pcall(function() layoutGridScrollBar() end) + elseif style == "simple" then + success, err = pcall(function() layoutSimpleScrollBar() end) + end + if not success then print(err) end + moveDragger() + reentrancyGuard = false + end + + local doScrollUp = function() + scrollPosition = (scrollPosition) - rowSize + if scrollPosition < 1 then scrollPosition = 1 end + recalculate(nil) + end + + local doScrollDown = function() + scrollPosition = (scrollPosition) + rowSize + recalculate(nil) + end + + local scrollUp = function(mouseYPos) + if scrollUpButton.Active then + scrollStamp = tick() + local current = scrollStamp + local upCon + upCon = mouseDrag.MouseButton1Up:connect(function() + scrollStamp = tick() + mouseDrag.Parent = nil + upCon:disconnect() + end) + mouseDrag.Parent = getLayerCollectorAncestor(scrollbar) + doScrollUp() + wait(0.2) + local t = tick() + local w = 0.1 + while scrollStamp == current do + doScrollUp() + if mouseYPos and mouseYPos > scrollDrag.AbsolutePosition.y then + break + end + if not scrollUpButton.Active then break end + if tick()-t > 5 then + w = 0 + elseif tick()-t > 2 then + w = 0.06 + end + wait(w) + end + end + end + + local scrollDown = function(mouseYPos) + if scrollDownButton.Active then + scrollStamp = tick() + local current = scrollStamp + local downCon + downCon = mouseDrag.MouseButton1Up:connect(function() + scrollStamp = tick() + mouseDrag.Parent = nil + downCon:disconnect() + end) + mouseDrag.Parent = getLayerCollectorAncestor(scrollbar) + doScrollDown() + wait(0.2) + local t = tick() + local w = 0.1 + while scrollStamp == current do + doScrollDown() + if mouseYPos and mouseYPos < (scrollDrag.AbsolutePosition.y + scrollDrag.AbsoluteSize.x) then + break + end + if not scrollDownButton.Active then break end + if tick()-t > 5 then + w = 0 + elseif tick()-t > 2 then + w = 0.06 + end + wait(w) + end + end + end + + local y = 0 + scrollDrag.MouseButton1Down:connect(function(x,y) + if scrollDrag.Active then + scrollStamp = tick() + local mouseOffset = y - scrollDrag.AbsolutePosition.y + local dragCon + local upCon + dragCon = mouseDrag.MouseMoved:connect(function(x,y) + local barAbsPos = scrollbar.AbsolutePosition.y + local barAbsSize = scrollbar.AbsoluteSize.y + + local dragAbsSize = scrollDrag.AbsoluteSize.y + local barAbsOne = barAbsPos + barAbsSize - dragAbsSize + y = y - mouseOffset + y = y < barAbsPos and barAbsPos or y > barAbsOne and barAbsOne or y + y = y - barAbsPos + + local guiObjects = 0 + local children = frame:GetChildren() + if children then + for i, child in ipairs(children) do + if child:IsA("GuiObject") then + guiObjects = guiObjects + 1 + end + end + end + + local doublePercent = y/(barAbsSize-dragAbsSize) + local rowDiff = rowSize + local totalScrollCount = guiObjects - (howManyDisplayed - 1) + local newScrollPosition = math.floor((doublePercent * totalScrollCount) + 0.5) + rowDiff + if newScrollPosition < scrollPosition then + rowDiff = -rowDiff + end + + if newScrollPosition < 1 then + newScrollPosition = 1 + end + + scrollPosition = newScrollPosition + recalculate(nil) + end) + upCon = mouseDrag.MouseButton1Up:connect(function() + scrollStamp = tick() + mouseDrag.Parent = nil + dragCon:disconnect(); dragCon = nil + upCon:disconnect(); drag = nil + end) + mouseDrag.Parent = getLayerCollectorAncestor(scrollbar) + end + end) + + local scrollMouseCount = 0 + + scrollUpButton.MouseButton1Down:connect( + function() + scrollUp() + end) + scrollUpButton.MouseButton1Up:connect(function() + scrollStamp = tick() + end) + + + scrollDownButton.MouseButton1Up:connect(function() + scrollStamp = tick() + end) + scrollDownButton.MouseButton1Down:connect( + function() + scrollDown() + end) + + scrollbar.MouseButton1Up:connect(function() + scrollStamp = tick() + end) + scrollbar.MouseButton1Down:connect( + function(x,y) + if y > (scrollDrag.AbsoluteSize.y + scrollDrag.AbsolutePosition.y) then + scrollDown(y) + elseif y < (scrollDrag.AbsolutePosition.y) then + scrollUp(y) + end + end) + + + frame.ChildAdded:connect(function() + recalculate(nil) + end) + + frame.ChildRemoved:connect(function() + recalculate(nil) + end) + + frame.Changed:connect( + function(prop) + if prop == "AbsoluteSize" then + --Wait a heartbeat for it to sync in + recalculate(nil) + end + end) + frame.AncestryChanged:connect(function() recalculate(nil) end) + + return frame, scrollUpButton, scrollDownButton, recalculate, scrollbar +end +local function binaryGrow(min, max, fits) + if min > max then + return min + end + local biggestLegal = min + + while min <= max do + local mid = min + math.floor((max - min) / 2) + if fits(mid) and (biggestLegal == nil or biggestLegal < mid) then + biggestLegal = mid + + --Try growing + min = mid + 1 + else + --Doesn't fit, shrink + max = mid - 1 + end + end + return biggestLegal +end + + +local function binaryShrink(min, max, fits) + if min > max then + return min + end + local smallestLegal = max + + while min <= max do + local mid = min + math.floor((max - min) / 2) + if fits(mid) and (smallestLegal == nil or smallestLegal > mid) then + smallestLegal = mid + + --It fits, shrink + max = mid - 1 + else + --Doesn't fit, grow + min = mid + 1 + end + end + return smallestLegal +end + + +local function getGuiOwner(instance) + while instance ~= nil do + if instance:IsA("ScreenGui") or instance:IsA("BillboardGui") then + return instance + end + instance = instance.Parent + end + return nil +end + +t.AutoTruncateTextObject = function(textLabel) + local text = textLabel.Text + + local fullLabel = textLabel:Clone() + fullLabel.Name = "Full" .. textLabel.Name + fullLabel.BorderSizePixel = 0 + fullLabel.BackgroundTransparency = 0 + fullLabel.Text = text + fullLabel.TextXAlignment = Enum.TextXAlignment.Center + fullLabel.Position = UDim2.new(0,-3,0,0) + fullLabel.Size = UDim2.new(0,100,1,0) + fullLabel.Visible = false + fullLabel.Parent = textLabel + + local shortText = nil + local mouseEnterConnection = nil + local mouseLeaveConnection= nil + + local checkForResize = function() + if getGuiOwner(textLabel) == nil then + return + end + textLabel.Text = text + if textLabel.TextFits then + --Tear down the rollover if it is active + if mouseEnterConnection then + mouseEnterConnection:disconnect() + mouseEnterConnection = nil + end + if mouseLeaveConnection then + mouseLeaveConnection:disconnect() + mouseLeaveConnection = nil + end + else + local len = string.len(text) + textLabel.Text = text .. "~" + + --Shrink the text + local textSize = binaryGrow(0, len, + function(pos) + if pos == 0 then + textLabel.Text = "~" + else + textLabel.Text = string.sub(text, 1, pos) .. "~" + end + return textLabel.TextFits + end) + shortText = string.sub(text, 1, textSize) .. "~" + textLabel.Text = shortText + + --Make sure the fullLabel fits + if not fullLabel.TextFits then + --Already too small, grow it really bit to start + fullLabel.Size = UDim2.new(0, 10000, 1, 0) + end + + --Okay, now try to binary shrink it back down + local fullLabelSize = binaryShrink(textLabel.AbsoluteSize.X,fullLabel.AbsoluteSize.X, + function(size) + fullLabel.Size = UDim2.new(0, size, 1, 0) + return fullLabel.TextFits + end) + fullLabel.Size = UDim2.new(0,fullLabelSize+6,1,0) + + --Now setup the rollover effects, if they are currently off + if mouseEnterConnection == nil then + mouseEnterConnection = textLabel.MouseEnter:connect( + function() + fullLabel.ZIndex = textLabel.ZIndex + 1 + fullLabel.Visible = true + --textLabel.Text = "" + end) + end + if mouseLeaveConnection == nil then + mouseLeaveConnection = textLabel.MouseLeave:connect( + function() + fullLabel.Visible = false + --textLabel.Text = shortText + end) + end + end + end + textLabel.AncestryChanged:connect(checkForResize) + textLabel.Changed:connect( + function(prop) + if prop == "AbsoluteSize" then + checkForResize() + end + end) + + checkForResize() + + local function changeText(newText) + text = newText + fullLabel.Text = text + checkForResize() + end + + return textLabel, changeText +end + +local function TransitionTutorialPages(fromPage, toPage, transitionFrame, currentPageValue) + if fromPage then + fromPage.Visible = false + if transitionFrame.Visible == false then + transitionFrame.Size = fromPage.Size + transitionFrame.Position = fromPage.Position + end + else + if transitionFrame.Visible == false then + transitionFrame.Size = UDim2.new(0.0,50,0.0,50) + transitionFrame.Position = UDim2.new(0.5,-25,0.5,-25) + end + end + transitionFrame.Visible = true + currentPageValue.Value = nil + + local newSize, newPosition + if toPage then + --Make it visible so it resizes + toPage.Visible = true + + newSize = toPage.Size + newPosition = toPage.Position + + toPage.Visible = false + else + newSize = UDim2.new(0.0,50,0.0,50) + newPosition = UDim2.new(0.5,-25,0.5,-25) + end + transitionFrame:TweenSizeAndPosition(newSize, newPosition, Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 0.3, true, + function(state) + if state == Enum.TweenStatus.Completed then + transitionFrame.Visible = false + if toPage then + toPage.Visible = true + currentPageValue.Value = toPage + end + end + end) +end + +t.CreateTutorial = function(name, tutorialKey, createButtons) + local frame = Instance.new("Frame") + frame.Name = "Tutorial-" .. name + frame.BackgroundTransparency = 1 + frame.Size = UDim2.new(0.6, 0, 0.6, 0) + frame.Position = UDim2.new(0.2, 0, 0.2, 0) + + local transitionFrame = Instance.new("Frame") + transitionFrame.Name = "TransitionFrame" + transitionFrame.Style = Enum.FrameStyle.RobloxRound + transitionFrame.Size = UDim2.new(0.6, 0, 0.6, 0) + transitionFrame.Position = UDim2.new(0.2, 0, 0.2, 0) + transitionFrame.Visible = false + transitionFrame.Parent = frame + + local currentPageValue = Instance.new("ObjectValue") + currentPageValue.Name = "CurrentTutorialPage" + currentPageValue.Value = nil + currentPageValue.Parent = frame + + local boolValue = Instance.new("BoolValue") + boolValue.Name = "Buttons" + boolValue.Value = createButtons + boolValue.Parent = frame + + local pages = Instance.new("Frame") + pages.Name = "Pages" + pages.BackgroundTransparency = 1 + pages.Size = UDim2.new(1,0,1,0) + pages.Parent = frame + + local function getVisiblePageAndHideOthers() + local visiblePage = nil + local children = pages:GetChildren() + if children then + for i,child in ipairs(children) do + if child.Visible then + if visiblePage then + child.Visible = false + else + visiblePage = child + end + end + end + end + return visiblePage + end + + local showTutorial = function(alwaysShow) + if alwaysShow or UserSettings().GameSettings:GetTutorialState(tutorialKey) == false then + print("Showing tutorial-",tutorialKey) + local currentTutorialPage = getVisiblePageAndHideOthers() + + local firstPage = pages:FindFirstChild("TutorialPage1") + if firstPage then + TransitionTutorialPages(currentTutorialPage, firstPage, transitionFrame, currentPageValue) + else + error("Could not find TutorialPage1") + end + end + end + + local dismissTutorial = function() + local currentTutorialPage = getVisiblePageAndHideOthers() + + if currentTutorialPage then + TransitionTutorialPages(currentTutorialPage, nil, transitionFrame, currentPageValue) + end + + UserSettings().GameSettings:SetTutorialState(tutorialKey, true) + end + + local gotoPage = function(pageNum) + local page = pages:FindFirstChild("TutorialPage" .. pageNum) + local currentTutorialPage = getVisiblePageAndHideOthers() + TransitionTutorialPages(currentTutorialPage, page, transitionFrame, currentPageValue) + end + + return frame, showTutorial, dismissTutorial, gotoPage +end + +local function CreateBasicTutorialPage(name, handleResize, skipTutorial, giveDoneButton) + local frame = Instance.new("Frame") + frame.Name = "TutorialPage" + frame.Style = Enum.FrameStyle.RobloxRound + frame.Size = UDim2.new(0.6, 0, 0.6, 0) + frame.Position = UDim2.new(0.2, 0, 0.2, 0) + frame.Visible = false + + local frameHeader = Instance.new("TextLabel") + frameHeader.Name = "Header" + frameHeader.Text = name + frameHeader.BackgroundTransparency = 1 + frameHeader.FontSize = Enum.FontSize.Size24 + frameHeader.Font = Enum.Font.ArialBold + frameHeader.TextColor3 = Color3.new(1,1,1) + frameHeader.TextXAlignment = Enum.TextXAlignment.Center + frameHeader.TextWrap = true + frameHeader.Size = UDim2.new(1,-55, 0, 22) + frameHeader.Position = UDim2.new(0,0,0,0) + frameHeader.Parent = frame + + local skipButton = Instance.new("ImageButton") + skipButton.Name = "SkipButton" + skipButton.AutoButtonColor = false + skipButton.BackgroundTransparency = 1 + skipButton.Image = "rbxasset://textures/ui/closeButton.png" + skipButton.MouseButton1Click:connect(function() + skipTutorial() + end) + skipButton.MouseEnter:connect(function() + skipButton.Image = "rbxasset://textures/ui/closeButton_dn.png" + end) + skipButton.MouseLeave:connect(function() + skipButton.Image = "rbxasset://textures/ui/closeButton.png" + end) + skipButton.Size = UDim2.new(0, 25, 0, 25) + skipButton.Position = UDim2.new(1, -25, 0, 0) + skipButton.Parent = frame + + + if giveDoneButton then + local doneButton = Instance.new("TextButton") + doneButton.Name = "DoneButton" + doneButton.Style = Enum.ButtonStyle.RobloxButtonDefault + doneButton.Text = "Done" + doneButton.TextColor3 = Color3.new(1,1,1) + doneButton.Font = Enum.Font.ArialBold + doneButton.FontSize = Enum.FontSize.Size18 + doneButton.Size = UDim2.new(0,100,0,50) + doneButton.Position = UDim2.new(0.5,-50,1,-50) + + if skipTutorial then + doneButton.MouseButton1Click:connect(function() skipTutorial() end) + end + + doneButton.Parent = frame + end + + local innerFrame = Instance.new("Frame") + innerFrame.Name = "ContentFrame" + innerFrame.BackgroundTransparency = 1 + innerFrame.Position = UDim2.new(0,0,0,25) + innerFrame.Parent = frame + + local nextButton = Instance.new("TextButton") + nextButton.Name = "NextButton" + nextButton.Text = "Next" + nextButton.TextColor3 = Color3.new(1,1,1) + nextButton.Font = Enum.Font.Arial + nextButton.FontSize = Enum.FontSize.Size18 + nextButton.Style = Enum.ButtonStyle.RobloxButtonDefault + nextButton.Size = UDim2.new(0,80, 0, 32) + nextButton.Position = UDim2.new(0.5, 5, 1, -32) + nextButton.Active = false + nextButton.Visible = false + nextButton.Parent = frame + + local prevButton = Instance.new("TextButton") + prevButton.Name = "PrevButton" + prevButton.Text = "Previous" + prevButton.TextColor3 = Color3.new(1,1,1) + prevButton.Font = Enum.Font.Arial + prevButton.FontSize = Enum.FontSize.Size18 + prevButton.Style = Enum.ButtonStyle.RobloxButton + prevButton.Size = UDim2.new(0,80, 0, 32) + prevButton.Position = UDim2.new(0.5, -85, 1, -32) + prevButton.Active = false + prevButton.Visible = false + prevButton.Parent = frame + + if giveDoneButton then + innerFrame.Size = UDim2.new(1,0,1,-75) + else + innerFrame.Size = UDim2.new(1,0,1,-22) + end + + local parentConnection = nil + + local function basicHandleResize() + if frame.Visible and frame.Parent then + local maxSize = math.min(frame.Parent.AbsoluteSize.X, frame.Parent.AbsoluteSize.Y) + handleResize(200,maxSize) + end + end + + frame.Changed:connect( + function(prop) + if prop == "Parent" then + if parentConnection ~= nil then + parentConnection:disconnect() + parentConnection = nil + end + if frame.Parent and frame.Parent:IsA("GuiObject") then + parentConnection = frame.Parent.Changed:connect( + function(parentProp) + if parentProp == "AbsoluteSize" then + wait() + basicHandleResize() + end + end) + basicHandleResize() + end + end + + if prop == "Visible" then + basicHandleResize() + end + end) + + return frame, innerFrame +end + +t.CreateTextTutorialPage = function(name, text, skipTutorialFunc) + local frame = nil + local contentFrame = nil + + local textLabel = Instance.new("TextLabel") + textLabel.BackgroundTransparency = 1 + textLabel.TextColor3 = Color3.new(1,1,1) + textLabel.Text = text + textLabel.TextWrap = true + textLabel.TextXAlignment = Enum.TextXAlignment.Left + textLabel.TextYAlignment = Enum.TextYAlignment.Center + textLabel.Font = Enum.Font.Arial + textLabel.FontSize = Enum.FontSize.Size14 + textLabel.Size = UDim2.new(1,0,1,0) + + local function handleResize(minSize, maxSize) + size = binaryShrink(minSize, maxSize, + function(size) + frame.Size = UDim2.new(0, size, 0, size) + return textLabel.TextFits + end) + frame.Size = UDim2.new(0, size, 0, size) + frame.Position = UDim2.new(0.5, -size/2, 0.5, -size/2) + end + + frame, contentFrame = CreateBasicTutorialPage(name, handleResize, skipTutorialFunc) + textLabel.Parent = contentFrame + + return frame +end + +t.CreateImageTutorialPage = function(name, imageAsset, x, y, skipTutorialFunc, giveDoneButton) + local frame = nil + local contentFrame = nil + + local imageLabel = Instance.new("ImageLabel") + imageLabel.BackgroundTransparency = 1 + imageLabel.Image = imageAsset + imageLabel.Size = UDim2.new(0,x,0,y) + imageLabel.Position = UDim2.new(0.5,-x/2,0.5,-y/2) + + local function handleResize(minSize, maxSize) + size = binaryShrink(minSize, maxSize, + function(size) + return size >= x and size >= y + end) + if size >= x and size >= y then + imageLabel.Size = UDim2.new(0,x, 0,y) + imageLabel.Position = UDim2.new(0.5,-x/2, 0.5, -y/2) + else + if x > y then + --X is limiter, so + imageLabel.Size = UDim2.new(1,0,y/x,0) + imageLabel.Position = UDim2.new(0,0, 0.5 - (y/x)/2, 0) + else + --Y is limiter + imageLabel.Size = UDim2.new(x/y,0,1, 0) + imageLabel.Position = UDim2.new(0.5-(x/y)/2, 0, 0, 0) + end + end + size = size + 50 + frame.Size = UDim2.new(0, size, 0, size) + frame.Position = UDim2.new(0.5, -size/2, 0.5, -size/2) + end + + frame, contentFrame = CreateBasicTutorialPage(name, handleResize, skipTutorialFunc, giveDoneButton) + imageLabel.Parent = contentFrame + + return frame +end + +t.AddTutorialPage = function(tutorial, tutorialPage) + local transitionFrame = tutorial.TransitionFrame + local currentPageValue = tutorial.CurrentTutorialPage + + if not tutorial.Buttons.Value then + tutorialPage.NextButton.Parent = nil + tutorialPage.PrevButton.Parent = nil + end + + local children = tutorial.Pages:GetChildren() + if children and #children > 0 then + tutorialPage.Name = "TutorialPage" .. (#children+1) + local previousPage = children[#children] + if not previousPage:IsA("GuiObject") then + error("All elements under Pages must be GuiObjects") + end + + if tutorial.Buttons.Value then + if previousPage.NextButton.Active then + error("NextButton already Active on previousPage, please only add pages with RbxGui.AddTutorialPage function") + end + previousPage.NextButton.MouseButton1Click:connect( + function() + TransitionTutorialPages(previousPage, tutorialPage, transitionFrame, currentPageValue) + end) + previousPage.NextButton.Active = true + previousPage.NextButton.Visible = true + + if tutorialPage.PrevButton.Active then + error("PrevButton already Active on tutorialPage, please only add pages with RbxGui.AddTutorialPage function") + end + tutorialPage.PrevButton.MouseButton1Click:connect( + function() + TransitionTutorialPages(tutorialPage, previousPage, transitionFrame, currentPageValue) + end) + tutorialPage.PrevButton.Active = true + tutorialPage.PrevButton.Visible = true + end + + tutorialPage.Parent = tutorial.Pages + else + --First child + tutorialPage.Name = "TutorialPage1" + tutorialPage.Parent = tutorial.Pages + end +end + +t.CreateSetPanel = function(userIdsForSets, objectSelected, dialogClosed, size, position, showAdminCategories, useAssetVersionId) + + if not userIdsForSets then + error("CreateSetPanel: userIdsForSets (first arg) is nil, should be a table of number ids") + end + if type(userIdsForSets) ~= "table" and type(userIdsForSets) ~= "userdata" then + error("CreateSetPanel: userIdsForSets (first arg) is of type " ..type(userIdsForSets) .. ", should be of type table or userdata") + end + if not objectSelected then + error("CreateSetPanel: objectSelected (second arg) is nil, should be a callback function!") + end + if type(objectSelected) ~= "function" then + error("CreateSetPanel: objectSelected (second arg) is of type " .. type(objectSelected) .. ", should be of type function!") + end + if dialogClosed and type(dialogClosed) ~= "function" then + error("CreateSetPanel: dialogClosed (third arg) is of type " .. type(dialogClosed) .. ", should be of type function!") + end + + if showAdminCategories == nil then -- by default, don't show beta sets + showAdminCategories = false + end + + local arrayPosition = 1 + local insertButtons = {} + local insertButtonCons = {} + local contents = nil + local setGui = nil + + -- used for water selections + local waterForceDirection = "NegX" + local waterForce = "None" + local waterGui, waterTypeChangedEvent = nil + + local Data = {} + Data.CurrentCategory = nil + Data.Category = {} + local SetCache = {} + + local userCategoryButtons = nil + + local buttonWidth = 64 + local buttonHeight = buttonWidth + + local SmallThumbnailUrl = nil + local LargeThumbnailUrl = nil + local BaseUrl = game:GetService("ContentProvider").BaseUrl:lower() + local AssetGameUrl = string.gsub(BaseUrl, "www", "assetgame") + + if useAssetVersionId then + LargeThumbnailUrl = AssetGameUrl .. "Game/Tools/ThumbnailAsset.ashx?fmt=png&wd=420&ht=420&assetversionid=" + SmallThumbnailUrl = AssetGameUrl .. "Game/Tools/ThumbnailAsset.ashx?fmt=png&wd=75&ht=75&assetversionid=" + else + LargeThumbnailUrl = AssetGameUrl .. "Game/Tools/ThumbnailAsset.ashx?fmt=png&wd=420&ht=420&aid=" + SmallThumbnailUrl = AssetGameUrl .. "Game/Tools/ThumbnailAsset.ashx?fmt=png&wd=75&ht=75&aid=" + end + + local function drillDownSetZIndex(parent, index) + local children = parent:GetChildren() + for i = 1, #children do + if children[i]:IsA("GuiObject") then + children[i].ZIndex = index + end + drillDownSetZIndex(children[i], index) + end + end + + -- for terrain stamping + local currTerrainDropDownFrame = nil + local terrainShapes = {"Block","Vertical Ramp","Corner Wedge","Inverse Corner Wedge","Horizontal Ramp","Auto-Wedge"} + local terrainShapeMap = {} + for i = 1, #terrainShapes do + terrainShapeMap[terrainShapes[i]] = i - 1 + end + terrainShapeMap[terrainShapes[#terrainShapes]] = 6 + + local function createWaterGui() + local waterForceDirections = {"NegX","X","NegY","Y","NegZ","Z"} + local waterForces = {"None", "Small", "Medium", "Strong", "Max"} + + local waterFrame = Instance.new("Frame") + waterFrame.Name = "WaterFrame" + waterFrame.Style = Enum.FrameStyle.RobloxSquare + waterFrame.Size = UDim2.new(0,150,0,110) + waterFrame.Visible = false + + local waterForceLabel = Instance.new("TextLabel") + waterForceLabel.Name = "WaterForceLabel" + waterForceLabel.BackgroundTransparency = 1 + waterForceLabel.Size = UDim2.new(1,0,0,12) + waterForceLabel.Font = Enum.Font.ArialBold + waterForceLabel.FontSize = Enum.FontSize.Size12 + waterForceLabel.TextColor3 = Color3.new(1,1,1) + waterForceLabel.TextXAlignment = Enum.TextXAlignment.Left + waterForceLabel.Text = "Water Force" + waterForceLabel.Parent = waterFrame + + local waterForceDirLabel = waterForceLabel:Clone() + waterForceDirLabel.Name = "WaterForceDirectionLabel" + waterForceDirLabel.Text = "Water Force Direction" + waterForceDirLabel.Position = UDim2.new(0,0,0,50) + waterForceDirLabel.Parent = waterFrame + + local waterTypeChangedEvent = Instance.new("BindableEvent") + waterTypeChangedEvent.Name = "WaterTypeChangedEvent" + waterTypeChangedEvent.Parent = waterFrame + + local waterForceDirectionSelectedFunc = function(newForceDirection) + waterForceDirection = newForceDirection + waterTypeChangedEvent:Fire({waterForce, waterForceDirection}) + end + local waterForceSelectedFunc = function(newForce) + waterForce = newForce + waterTypeChangedEvent:Fire({waterForce, waterForceDirection}) + end + + local waterForceDirectionDropDown, forceWaterDirectionSelection = t.CreateDropDownMenu(waterForceDirections, waterForceDirectionSelectedFunc) + waterForceDirectionDropDown.Size = UDim2.new(1,0,0,25) + waterForceDirectionDropDown.Position = UDim2.new(0,0,1,3) + forceWaterDirectionSelection("NegX") + waterForceDirectionDropDown.Parent = waterForceDirLabel + + local waterForceDropDown, forceWaterForceSelection = t.CreateDropDownMenu(waterForces, waterForceSelectedFunc) + forceWaterForceSelection("None") + waterForceDropDown.Size = UDim2.new(1,0,0,25) + waterForceDropDown.Position = UDim2.new(0,0,1,3) + waterForceDropDown.Parent = waterForceLabel + + return waterFrame, waterTypeChangedEvent + end + + -- Helper Function that contructs gui elements + local function createSetGui() + + local setGui = Instance.new("ScreenGui") + setGui.Name = "SetGui" + + local setPanel = Instance.new("Frame") + setPanel.Name = "SetPanel" + setPanel.Active = true + setPanel.BackgroundTransparency = 1 + if position then + setPanel.Position = position + else + setPanel.Position = UDim2.new(0.2, 29, 0.1, 24) + end + if size then + setPanel.Size = size + else + setPanel.Size = UDim2.new(0.6, -58, 0.64, 0) + end + setPanel.Style = Enum.FrameStyle.RobloxRound + setPanel.ZIndex = 6 + setPanel.Parent = setGui + + -- Children of SetPanel + local itemPreview = Instance.new("Frame") + itemPreview.Name = "ItemPreview" + itemPreview.BackgroundTransparency = 1 + itemPreview.Position = UDim2.new(0.8,5,0.085,0) + itemPreview.Size = UDim2.new(0.21,0,0.9,0) + itemPreview.ZIndex = 6 + itemPreview.Parent = setPanel + + -- Children of ItemPreview + local textPanel = Instance.new("Frame") + textPanel.Name = "TextPanel" + textPanel.BackgroundTransparency = 1 + textPanel.Position = UDim2.new(0,0,0.45,0) + textPanel.Size = UDim2.new(1,0,0.55,0) + textPanel.ZIndex = 6 + textPanel.Parent = itemPreview + + -- Children of TextPanel + local rolloverText = Instance.new("TextLabel") + rolloverText.Name = "RolloverText" + rolloverText.BackgroundTransparency = 1 + rolloverText.Size = UDim2.new(1,0,0,48) + rolloverText.ZIndex = 6 + rolloverText.Font = Enum.Font.ArialBold + rolloverText.FontSize = Enum.FontSize.Size24 + rolloverText.Text = "" + rolloverText.TextColor3 = Color3.new(1,1,1) + rolloverText.TextWrap = true + rolloverText.TextXAlignment = Enum.TextXAlignment.Left + rolloverText.TextYAlignment = Enum.TextYAlignment.Top + rolloverText.Parent = textPanel + + local largePreview = Instance.new("ImageLabel") + largePreview.Name = "LargePreview" + largePreview.BackgroundTransparency = 1 + largePreview.Image = "" + largePreview.Size = UDim2.new(1,0,0,170) + largePreview.ZIndex = 6 + largePreview.Parent = itemPreview + + local sets = Instance.new("Frame") + sets.Name = "Sets" + sets.BackgroundTransparency = 1 + sets.Position = UDim2.new(0,0,0,5) + sets.Size = UDim2.new(0.23,0,1,-5) + sets.ZIndex = 6 + sets.Parent = setPanel + + -- Children of Sets + local line = Instance.new("Frame") + line.Name = "Line" + line.BackgroundColor3 = Color3.new(1,1,1) + line.BackgroundTransparency = 0.7 + line.BorderSizePixel = 0 + line.Position = UDim2.new(1,-3,0.06,0) + line.Size = UDim2.new(0,3,0.9,0) + line.ZIndex = 6 + line.Parent = sets + + local setsLists, controlFrame = t.CreateTrueScrollingFrame() + setsLists.Size = UDim2.new(1,-6,0.94,0) + setsLists.Position = UDim2.new(0,0,0.06,0) + setsLists.BackgroundTransparency = 1 + setsLists.Name = "SetsLists" + setsLists.ZIndex = 6 + setsLists.Parent = sets + drillDownSetZIndex(controlFrame, 7) + + local setsHeader = Instance.new("TextLabel") + setsHeader.Name = "SetsHeader" + setsHeader.BackgroundTransparency = 1 + setsHeader.Size = UDim2.new(0,47,0,24) + setsHeader.ZIndex = 6 + setsHeader.Font = Enum.Font.ArialBold + setsHeader.FontSize = Enum.FontSize.Size24 + setsHeader.Text = "Sets" + setsHeader.TextColor3 = Color3.new(1,1,1) + setsHeader.TextXAlignment = Enum.TextXAlignment.Left + setsHeader.TextYAlignment = Enum.TextYAlignment.Top + setsHeader.Parent = sets + + local cancelButton = Instance.new("TextButton") + cancelButton.Name = "CancelButton" + cancelButton.Position = UDim2.new(1,-32,0,-2) + cancelButton.Size = UDim2.new(0,34,0,34) + cancelButton.Style = Enum.ButtonStyle.RobloxButtonDefault + cancelButton.ZIndex = 6 + cancelButton.Text = "" + cancelButton.Modal = true + cancelButton.Parent = setPanel + + -- Children of Cancel Button + local cancelImage = Instance.new("ImageLabel") + cancelImage.Name = "CancelImage" + cancelImage.BackgroundTransparency = 1 + cancelImage.Image = "https://www.roblox.com/asset/?id=54135717" + cancelImage.Position = UDim2.new(0,-2,0,-2) + cancelImage.Size = UDim2.new(0,16,0,16) + cancelImage.ZIndex = 6 + cancelImage.Parent = cancelButton + + return setGui + end + + local function createSetButton(text) + local setButton = Instance.new("TextButton") + + if text then setButton.Text = text + else setButton.Text = "" end + + setButton.AutoButtonColor = false + setButton.BackgroundTransparency = 1 + setButton.BackgroundColor3 = Color3.new(1,1,1) + setButton.BorderSizePixel = 0 + setButton.Size = UDim2.new(1,-5,0,18) + setButton.ZIndex = 6 + setButton.Visible = false + setButton.Font = Enum.Font.Arial + setButton.FontSize = Enum.FontSize.Size18 + setButton.TextColor3 = Color3.new(1,1,1) + setButton.TextXAlignment = Enum.TextXAlignment.Left + + return setButton + end + + local function buildSetButton(name, setId, setImageId, i, count) + local button = createSetButton(name) + button.Text = name + button.Name = "SetButton" + button.Visible = true + + local setValue = Instance.new("IntValue") + setValue.Name = "SetId" + setValue.Value = setId + setValue.Parent = button + + local setName = Instance.new("StringValue") + setName.Name = "SetName" + setName.Value = name + setName.Parent = button + + return button + end + + local function processCategory(sets) + local setButtons = {} + local numSkipped = 0 + for i = 1, #sets do + if not showAdminCategories and sets[i].Name == "Beta" then + numSkipped = numSkipped + 1 + else + setButtons[i - numSkipped] = buildSetButton(sets[i].Name, sets[i].CategoryId, sets[i].ImageAssetId, i - numSkipped, #sets) + end + end + return setButtons + end + + local function handleResize() + wait() -- neccessary to insure heartbeat happened + + local itemPreview = setGui.SetPanel.ItemPreview + + itemPreview.LargePreview.Size = UDim2.new(1,0,0,itemPreview.AbsoluteSize.X) + itemPreview.LargePreview.Position = UDim2.new(0.5,-itemPreview.LargePreview.AbsoluteSize.X/2,0,0) + itemPreview.TextPanel.Position = UDim2.new(0,0,0,itemPreview.LargePreview.AbsoluteSize.Y) + itemPreview.TextPanel.Size = UDim2.new(1,0,0,itemPreview.AbsoluteSize.Y - itemPreview.LargePreview.AbsoluteSize.Y) + end + + local function makeInsertAssetButton() + local insertAssetButtonExample = Instance.new("Frame") + insertAssetButtonExample.Name = "InsertAssetButtonExample" + insertAssetButtonExample.Position = UDim2.new(0,128,0,64) + insertAssetButtonExample.Size = UDim2.new(0,64,0,64) + insertAssetButtonExample.BackgroundTransparency = 1 + insertAssetButtonExample.ZIndex = 6 + insertAssetButtonExample.Visible = false + + local assetId = Instance.new("IntValue") + assetId.Name = "AssetId" + assetId.Value = 0 + assetId.Parent = insertAssetButtonExample + + local assetName = Instance.new("StringValue") + assetName.Name = "AssetName" + assetName.Value = "" + assetName.Parent = insertAssetButtonExample + + local button = Instance.new("TextButton") + button.Name = "Button" + button.Text = "" + button.Style = Enum.ButtonStyle.RobloxButton + button.Position = UDim2.new(0.025,0,0.025,0) + button.Size = UDim2.new(0.95,0,0.95,0) + button.ZIndex = 6 + button.Parent = insertAssetButtonExample + + local buttonImage = Instance.new("ImageLabel") + buttonImage.Name = "ButtonImage" + buttonImage.Image = "" + buttonImage.Position = UDim2.new(0,-7,0,-7) + buttonImage.Size = UDim2.new(1,14,1,14) + buttonImage.BackgroundTransparency = 1 + buttonImage.ZIndex = 7 + buttonImage.Parent = button + + local configIcon = buttonImage:clone() + configIcon.Name = "ConfigIcon" + configIcon.Visible = false + configIcon.Position = UDim2.new(1,-23,1,-24) + configIcon.Size = UDim2.new(0,16,0,16) + configIcon.Image = "" + configIcon.ZIndex = 6 + configIcon.Parent = insertAssetButtonExample + + return insertAssetButtonExample + end + + local function showLargePreview(insertButton) + if insertButton:FindFirstChild("AssetId") then + delay(0,function() + game:GetService("ContentProvider"):Preload(LargeThumbnailUrl .. tostring(insertButton.AssetId.Value)) + setGui.SetPanel.ItemPreview.LargePreview.Image = LargeThumbnailUrl .. tostring(insertButton.AssetId.Value) + end) + end + if insertButton:FindFirstChild("AssetName") then + setGui.SetPanel.ItemPreview.TextPanel.RolloverText.Text = insertButton.AssetName.Value + end + end + + local function selectTerrainShape(shape) + if currTerrainDropDownFrame then + objectSelected(tostring(currTerrainDropDownFrame.AssetName.Value), tonumber(currTerrainDropDownFrame.AssetId.Value), shape) + end + end + + local function createTerrainTypeButton(name, parent) + local dropDownTextButton = Instance.new("TextButton") + dropDownTextButton.Name = name .. "Button" + dropDownTextButton.Font = Enum.Font.ArialBold + dropDownTextButton.FontSize = Enum.FontSize.Size14 + dropDownTextButton.BorderSizePixel = 0 + dropDownTextButton.TextColor3 = Color3.new(1,1,1) + dropDownTextButton.Text = name + dropDownTextButton.TextXAlignment = Enum.TextXAlignment.Left + dropDownTextButton.BackgroundTransparency = 1 + dropDownTextButton.ZIndex = parent.ZIndex + 1 + dropDownTextButton.Size = UDim2.new(0,parent.Size.X.Offset - 2,0,16) + dropDownTextButton.Position = UDim2.new(0,1,0,0) + + dropDownTextButton.MouseEnter:connect(function() + dropDownTextButton.BackgroundTransparency = 0 + dropDownTextButton.TextColor3 = Color3.new(0,0,0) + end) + + dropDownTextButton.MouseLeave:connect(function() + dropDownTextButton.BackgroundTransparency = 1 + dropDownTextButton.TextColor3 = Color3.new(1,1,1) + end) + + dropDownTextButton.MouseButton1Click:connect(function() + dropDownTextButton.BackgroundTransparency = 1 + dropDownTextButton.TextColor3 = Color3.new(1,1,1) + if dropDownTextButton.Parent and dropDownTextButton.Parent:IsA("GuiObject") then + dropDownTextButton.Parent.Visible = false + end + selectTerrainShape(terrainShapeMap[dropDownTextButton.Text]) + end) + + return dropDownTextButton + end + + local function createTerrainDropDownMenu(zIndex) + local dropDown = Instance.new("Frame") + dropDown.Name = "TerrainDropDown" + dropDown.BackgroundColor3 = Color3.new(0,0,0) + dropDown.BorderColor3 = Color3.new(1,0,0) + dropDown.Size = UDim2.new(0,200,0,0) + dropDown.Visible = false + dropDown.ZIndex = zIndex + dropDown.Parent = setGui + + for i = 1, #terrainShapes do + local shapeButton = createTerrainTypeButton(terrainShapes[i],dropDown) + shapeButton.Position = UDim2.new(0,1,0,(i - 1) * (shapeButton.Size.Y.Offset)) + shapeButton.Parent = dropDown + dropDown.Size = UDim2.new(0,200,0,dropDown.Size.Y.Offset + (shapeButton.Size.Y.Offset)) + end + + dropDown.MouseLeave:connect(function() + dropDown.Visible = false + end) + end + + + local function createDropDownMenuButton(parent) + local dropDownButton = Instance.new("ImageButton") + dropDownButton.Name = "DropDownButton" + dropDownButton.Image = "https://www.roblox.com/asset/?id=67581509" + dropDownButton.BackgroundTransparency = 1 + dropDownButton.Size = UDim2.new(0,16,0,16) + dropDownButton.Position = UDim2.new(1,-24,0,6) + dropDownButton.ZIndex = parent.ZIndex + 2 + dropDownButton.Parent = parent + + if not setGui:FindFirstChild("TerrainDropDown") then + createTerrainDropDownMenu(8) + end + + dropDownButton.MouseButton1Click:connect(function() + setGui.TerrainDropDown.Visible = true + setGui.TerrainDropDown.Position = UDim2.new(0,parent.AbsolutePosition.X,0,parent.AbsolutePosition.Y) + currTerrainDropDownFrame = parent + end) + end + + local function buildInsertButton() + local insertButton = makeInsertAssetButton() + insertButton.Name = "InsertAssetButton" + insertButton.Visible = true + + if Data.Category[Data.CurrentCategory].SetName == "High Scalability" then + createDropDownMenuButton(insertButton) + end + + local lastEnter = nil + local mouseEnterCon = insertButton.MouseEnter:connect(function() + lastEnter = insertButton + delay(0.1,function() + if lastEnter == insertButton then + showLargePreview(insertButton) + end + end) + end) + return insertButton, mouseEnterCon + end + + local function realignButtonGrid(columns) + local x = 0 + local y = 0 + for i = 1, #insertButtons do + insertButtons[i].Position = UDim2.new(0, buttonWidth * x, 0, buttonHeight * y) + x = x + 1 + if x >= columns then + x = 0 + y = y + 1 + end + end + end + + local function setInsertButtonImageBehavior(insertFrame, visible, name, assetId) + if visible then + insertFrame.AssetName.Value = name + insertFrame.AssetId.Value = assetId + local newImageUrl = SmallThumbnailUrl .. assetId + if newImageUrl ~= insertFrame.Button.ButtonImage.Image then + delay(0,function() + game:GetService("ContentProvider"):Preload(SmallThumbnailUrl .. assetId) + if insertFrame:findFirstChild("Button") then + insertFrame.Button.ButtonImage.Image = SmallThumbnailUrl .. assetId + end + end) + end + table.insert(insertButtonCons, + insertFrame.Button.MouseButton1Click:connect(function() + -- special case for water, show water selection gui + local isWaterSelected = (name == "Water") and (Data.Category[Data.CurrentCategory].SetName == "High Scalability") + waterGui.Visible = isWaterSelected + if isWaterSelected then + objectSelected(name, tonumber(assetId), nil) + else + objectSelected(name, tonumber(assetId)) + end + end) + ) + insertFrame.Visible = true + else + insertFrame.Visible = false + end + end + + local function loadSectionOfItems(setGui, rows, columns) + local pageSize = rows * columns + + if arrayPosition > #contents then return end + + local origArrayPos = arrayPosition + + local yCopy = 0 + for i = 1, pageSize + 1 do + if arrayPosition >= #contents + 1 then + break + end + + local buttonCon + insertButtons[arrayPosition], buttonCon = buildInsertButton() + table.insert(insertButtonCons,buttonCon) + insertButtons[arrayPosition].Parent = setGui.SetPanel.ItemsFrame + arrayPosition = arrayPosition + 1 + end + realignButtonGrid(columns) + + local indexCopy = origArrayPos + for index = origArrayPos, arrayPosition do + if insertButtons[index] then + if contents[index] then + + -- we don't want water to have a drop down button + if contents[index].Name == "Water" then + if Data.Category[Data.CurrentCategory].SetName == "High Scalability" then + insertButtons[index]:FindFirstChild("DropDownButton",true):Destroy() + end + end + + local assetId + if useAssetVersionId then + assetId = contents[index].AssetVersionId + else + assetId = contents[index].AssetId + end + setInsertButtonImageBehavior(insertButtons[index], true, contents[index].Name, assetId) + else + break + end + else + break + end + indexCopy = index + end + end + + local function setSetIndex() + Data.Category[Data.CurrentCategory].Index = 0 + + rows = 7 + columns = math.floor(setGui.SetPanel.ItemsFrame.AbsoluteSize.X/buttonWidth) + + contents = Data.Category[Data.CurrentCategory].Contents + if contents then + -- destroy our buttons and their connections + for i = 1, #insertButtons do + insertButtons[i]:Destroy() + end + + for i = 1, #insertButtonCons do + if insertButtonCons[i] then insertButtonCons[i]:disconnect() end + end + + insertButtonCons = {} + insertButtons = {} + + arrayPosition = 1 + loadSectionOfItems(setGui, rows, columns) + end + end + + local function selectSet(button, setName, setId, setIndex) + if button and Data.Category[Data.CurrentCategory] ~= nil then + if button ~= Data.Category[Data.CurrentCategory].Button then + Data.Category[Data.CurrentCategory].Button = button + + if SetCache[setId] == nil then + SetCache[setId] = game:GetService("InsertService"):GetCollection(setId) + end + Data.Category[Data.CurrentCategory].Contents = SetCache[setId] + + Data.Category[Data.CurrentCategory].SetName = setName + Data.Category[Data.CurrentCategory].SetId = setId + end + setSetIndex() + end + end + + local function selectCategoryPage(buttons, page) + if buttons ~= Data.CurrentCategory then + if Data.CurrentCategory then + for key, button in pairs(Data.CurrentCategory) do + button.Visible = false + end + end + + Data.CurrentCategory = buttons + if Data.Category[Data.CurrentCategory] == nil then + Data.Category[Data.CurrentCategory] = {} + if #buttons > 0 then + selectSet(buttons[1], buttons[1].SetName.Value, buttons[1].SetId.Value, 0) + end + else + Data.Category[Data.CurrentCategory].Button = nil + selectSet(Data.Category[Data.CurrentCategory].ButtonFrame, Data.Category[Data.CurrentCategory].SetName, Data.Category[Data.CurrentCategory].SetId, Data.Category[Data.CurrentCategory].Index) + end + end + end + + local function selectCategory(category) + selectCategoryPage(category, 0) + end + + local function resetAllSetButtonSelection() + local setButtons = setGui.SetPanel.Sets.SetsLists:GetChildren() + for i = 1, #setButtons do + if setButtons[i]:IsA("TextButton") then + setButtons[i].Selected = false + setButtons[i].BackgroundTransparency = 1 + setButtons[i].TextColor3 = Color3.new(1,1,1) + setButtons[i].BackgroundColor3 = Color3.new(1,1,1) + end + end + end + + local function populateSetsFrame() + local currRow = 0 + for i = 1, #userCategoryButtons do + local button = userCategoryButtons[i] + button.Visible = true + button.Position = UDim2.new(0,5,0,currRow * button.Size.Y.Offset) + button.Parent = setGui.SetPanel.Sets.SetsLists + + if i == 1 then -- we will have this selected by default, so show it + button.Selected = true + button.BackgroundColor3 = Color3.new(0,204/255,0) + button.TextColor3 = Color3.new(0,0,0) + button.BackgroundTransparency = 0 + end + + button.MouseEnter:connect(function() + if not button.Selected then + button.BackgroundTransparency = 0 + button.TextColor3 = Color3.new(0,0,0) + end + end) + button.MouseLeave:connect(function() + if not button.Selected then + button.BackgroundTransparency = 1 + button.TextColor3 = Color3.new(1,1,1) + end + end) + button.MouseButton1Click:connect(function() + resetAllSetButtonSelection() + button.Selected = not button.Selected + button.BackgroundColor3 = Color3.new(0,204/255,0) + button.TextColor3 = Color3.new(0,0,0) + button.BackgroundTransparency = 0 + selectSet(button, button.Text, userCategoryButtons[i].SetId.Value, 0) + end) + + currRow = currRow + 1 + end + + local buttons = setGui.SetPanel.Sets.SetsLists:GetChildren() + + -- set first category as loaded for default + if buttons then + for i = 1, #buttons do + if buttons[i]:IsA("TextButton") then + selectSet(buttons[i], buttons[i].Text, userCategoryButtons[i].SetId.Value, 0) + selectCategory(userCategoryButtons) + break + end + end + end + end + + setGui = createSetGui() + waterGui, waterTypeChangedEvent = createWaterGui() + waterGui.Position = UDim2.new(0,55,0,0) + waterGui.Parent = setGui + setGui.Changed:connect(function(prop) -- this resizes the preview image to always be the right size + if prop == "AbsoluteSize" then + handleResize() + setSetIndex() + end + end) + + local scrollFrame, controlFrame = t.CreateTrueScrollingFrame() + scrollFrame.Size = UDim2.new(0.54,0,0.85,0) + scrollFrame.Position = UDim2.new(0.24,0,0.085,0) + scrollFrame.Name = "ItemsFrame" + scrollFrame.ZIndex = 6 + scrollFrame.Parent = setGui.SetPanel + scrollFrame.BackgroundTransparency = 1 + + drillDownSetZIndex(controlFrame,7) + + controlFrame.Parent = setGui.SetPanel + controlFrame.Position = UDim2.new(0.76, 5, 0, 0) + + local debounce = false + controlFrame.ScrollBottom.Changed:connect(function(prop) + if controlFrame.ScrollBottom.Value == true then + if debounce then return end + debounce = true + loadSectionOfItems(setGui, rows, columns) + debounce = false + end + end) + + local userData = {} + for id = 1, #userIdsForSets do + local newUserData = game:GetService("InsertService"):GetUserSets(userIdsForSets[id]) + if newUserData and #newUserData > 2 then + -- start at #3 to skip over My Decals and My Models for each account + for category = 3, #newUserData do + if newUserData[category].Name == "High Scalability" then -- we want high scalability parts to show first + table.insert(userData,1,newUserData[category]) + else + table.insert(userData, newUserData[category]) + end + end + end + + end + if userData then + userCategoryButtons = processCategory(userData) + end + + rows = math.floor(setGui.SetPanel.ItemsFrame.AbsoluteSize.Y/buttonHeight) + columns = math.floor(setGui.SetPanel.ItemsFrame.AbsoluteSize.X/buttonWidth) + + populateSetsFrame() + + setGui.SetPanel.CancelButton.MouseButton1Click:connect(function() + setGui.SetPanel.Visible = false + if dialogClosed then dialogClosed() end + end) + + local setVisibilityFunction = function(visible) + if visible then + setGui.SetPanel.Visible = true + else + setGui.SetPanel.Visible = false + end + end + + local getVisibilityFunction = function() + if setGui then + if setGui:FindFirstChild("SetPanel") then + return setGui.SetPanel.Visible + end + end + + return false + end + + return setGui, setVisibilityFunction, getVisibilityFunction, waterTypeChangedEvent +end + +t.CreateTerrainMaterialSelector = function(size,position) + local terrainMaterialSelectionChanged = Instance.new("BindableEvent") + terrainMaterialSelectionChanged.Name = "TerrainMaterialSelectionChanged" + + local selectedButton = nil + + local frame = Instance.new("Frame") + frame.Name = "TerrainMaterialSelector" + if size then + frame.Size = size + else + frame.Size = UDim2.new(0, 245, 0, 230) + end + if position then + frame.Position = position + end + frame.BorderSizePixel = 0 + frame.BackgroundColor3 = Color3.new(0,0,0) + frame.Active = true + + terrainMaterialSelectionChanged.Parent = frame + + local waterEnabled = true -- todo: turn this on when water is ready + + local materialToImageMap = {} + local materialNames = {"Grass", "Sand", "Brick", "Granite", "Asphalt", "Iron", "Aluminum", "Gold", "Plank", "Log", "Gravel", "Cinder Block", "Stone Wall", "Concrete", "Plastic (red)", "Plastic (blue)"} + if waterEnabled then + table.insert(materialNames,"Water") + end + local currentMaterial = 1 + + function getEnumFromName(choice) + if choice == "Grass" then return 1 end + if choice == "Sand" then return 2 end + if choice == "Erase" then return 0 end + if choice == "Brick" then return 3 end + if choice == "Granite" then return 4 end + if choice == "Asphalt" then return 5 end + if choice == "Iron" then return 6 end + if choice == "Aluminum" then return 7 end + if choice == "Gold" then return 8 end + if choice == "Plank" then return 9 end + if choice == "Log" then return 10 end + if choice == "Gravel" then return 11 end + if choice == "Cinder Block" then return 12 end + if choice == "Stone Wall" then return 13 end + if choice == "Concrete" then return 14 end + if choice == "Plastic (red)" then return 15 end + if choice == "Plastic (blue)" then return 16 end + if choice == "Water" then return 17 end + end + + function getNameFromEnum(choice) + if choice == Enum.CellMaterial.Grass or choice == 1 then return "Grass"end + if choice == Enum.CellMaterial.Sand or choice == 2 then return "Sand" end + if choice == Enum.CellMaterial.Empty or choice == 0 then return "Erase" end + if choice == Enum.CellMaterial.Brick or choice == 3 then return "Brick" end + if choice == Enum.CellMaterial.Granite or choice == 4 then return "Granite" end + if choice == Enum.CellMaterial.Asphalt or choice == 5 then return "Asphalt" end + if choice == Enum.CellMaterial.Iron or choice == 6 then return "Iron" end + if choice == Enum.CellMaterial.Aluminum or choice == 7 then return "Aluminum" end + if choice == Enum.CellMaterial.Gold or choice == 8 then return "Gold" end + if choice == Enum.CellMaterial.WoodPlank or choice == 9 then return "Plank" end + if choice == Enum.CellMaterial.WoodLog or choice == 10 then return "Log" end + if choice == Enum.CellMaterial.Gravel or choice == 11 then return "Gravel" end + if choice == Enum.CellMaterial.CinderBlock or choice == 12 then return "Cinder Block" end + if choice == Enum.CellMaterial.MossyStone or choice == 13 then return "Stone Wall" end + if choice == Enum.CellMaterial.Cement or choice == 14 then return "Concrete" end + if choice == Enum.CellMaterial.RedPlastic or choice == 15 then return "Plastic (red)" end + if choice == Enum.CellMaterial.BluePlastic or choice == 16 then return "Plastic (blue)" end + + if waterEnabled then + if choice == Enum.CellMaterial.Water or choice == 17 then return "Water" end + end + end + + + local function updateMaterialChoice(choice) + currentMaterial = getEnumFromName(choice) + terrainMaterialSelectionChanged:Fire(currentMaterial) + end + + -- we so need a better way to do this + for i,v in pairs(materialNames) do + materialToImageMap[v] = {} + if v == "Grass" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=56563112" + elseif v == "Sand" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=62356652" + elseif v == "Brick" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=65961537" + elseif v == "Granite" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=67532153" + elseif v == "Asphalt" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=67532038" + elseif v == "Iron" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=67532093" + elseif v == "Aluminum" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=67531995" + elseif v == "Gold" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=67532118" + elseif v == "Plastic (red)" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=67531848" + elseif v == "Plastic (blue)" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=67531924" + elseif v == "Plank" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=67532015" + elseif v == "Log" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=67532051" + elseif v == "Gravel" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=67532206" + elseif v == "Cinder Block" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=67532103" + elseif v == "Stone Wall" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=67531804" + elseif v == "Concrete" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=67532059" + elseif v == "Water" then materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=81407474" + else materialToImageMap[v].Regular = "https://www.roblox.com/asset/?id=66887593" -- fill in the rest here!! + end + end + + local scrollFrame, scrollUp, scrollDown, recalculateScroll = t.CreateScrollingFrame(nil,"grid") + scrollFrame.Size = UDim2.new(0.85,0,1,0) + scrollFrame.Position = UDim2.new(0,0,0,0) + scrollFrame.Parent = frame + + scrollUp.Parent = frame + scrollUp.Visible = true + scrollUp.Position = UDim2.new(1,-19,0,0) + + scrollDown.Parent = frame + scrollDown.Visible = true + scrollDown.Position = UDim2.new(1,-19,1,-17) + + local function goToNewMaterial(buttonWrap, materialName) + updateMaterialChoice(materialName) + buttonWrap.BackgroundTransparency = 0 + selectedButton.BackgroundTransparency = 1 + selectedButton = buttonWrap + end + + local function createMaterialButton(name) + local buttonWrap = Instance.new("TextButton") + buttonWrap.Text = "" + buttonWrap.Size = UDim2.new(0,32,0,32) + buttonWrap.BackgroundColor3 = Color3.new(1,1,1) + buttonWrap.BorderSizePixel = 0 + buttonWrap.BackgroundTransparency = 1 + buttonWrap.AutoButtonColor = false + buttonWrap.Name = tostring(name) + + local imageButton = Instance.new("ImageButton") + imageButton.AutoButtonColor = false + imageButton.BackgroundTransparency = 1 + imageButton.Size = UDim2.new(0,30,0,30) + imageButton.Position = UDim2.new(0,1,0,1) + imageButton.Name = tostring(name) + imageButton.Parent = buttonWrap + imageButton.Image = materialToImageMap[name].Regular + + local enumType = Instance.new("NumberValue") + enumType.Name = "EnumType" + enumType.Parent = buttonWrap + enumType.Value = 0 + + imageButton.MouseEnter:connect(function() + buttonWrap.BackgroundTransparency = 0 + end) + imageButton.MouseLeave:connect(function() + if selectedButton ~= buttonWrap then + buttonWrap.BackgroundTransparency = 1 + end + end) + imageButton.MouseButton1Click:connect(function() + if selectedButton ~= buttonWrap then + goToNewMaterial(buttonWrap, tostring(name)) + end + end) + + return buttonWrap + end + + for i = 1, #materialNames do + local imageButton = createMaterialButton(materialNames[i]) + + if materialNames[i] == "Grass" then -- always start with grass as the default + selectedButton = imageButton + imageButton.BackgroundTransparency = 0 + end + + imageButton.Parent = scrollFrame + end + + local forceTerrainMaterialSelection = function(newMaterialType) + if not newMaterialType then return end + if currentMaterial == newMaterialType then return end + + local matName = getNameFromEnum(newMaterialType) + local buttons = scrollFrame:GetChildren() + for i = 1, #buttons do + if buttons[i].Name == "Plastic (blue)" and matName == "Plastic (blue)" then goToNewMaterial(buttons[i],matName) return end + if buttons[i].Name == "Plastic (red)" and matName == "Plastic (red)" then goToNewMaterial(buttons[i],matName) return end + if string.find(buttons[i].Name, matName) then + goToNewMaterial(buttons[i],matName) + return + end + end + end + + frame.Changed:connect(function ( prop ) + if prop == "AbsoluteSize" then + recalculateScroll() + end + end) + + recalculateScroll() + return frame, terrainMaterialSelectionChanged, forceTerrainMaterialSelection +end + +t.CreateLoadingFrame = function(name,size,position) + game:GetService("ContentProvider"):Preload("https://www.roblox.com/asset/?id=35238053") + + local loadingFrame = Instance.new("Frame") + loadingFrame.Name = "LoadingFrame" + loadingFrame.Style = Enum.FrameStyle.RobloxRound + + if size then loadingFrame.Size = size + else loadingFrame.Size = UDim2.new(0,300,0,160) end + if position then loadingFrame.Position = position + else loadingFrame.Position = UDim2.new(0.5, -150, 0.5,-80) end + + local loadingBar = Instance.new("Frame") + loadingBar.Name = "LoadingBar" + loadingBar.BackgroundColor3 = Color3.new(0,0,0) + loadingBar.BorderColor3 = Color3.new(79/255,79/255,79/255) + loadingBar.Position = UDim2.new(0,0,0,41) + loadingBar.Size = UDim2.new(1,0,0,30) + loadingBar.Parent = loadingFrame + + local loadingGreenBar = Instance.new("ImageLabel") + loadingGreenBar.Name = "LoadingGreenBar" + loadingGreenBar.Image = "https://www.roblox.com/asset/?id=35238053" + loadingGreenBar.Position = UDim2.new(0,0,0,0) + loadingGreenBar.Size = UDim2.new(0,0,1,0) + loadingGreenBar.Visible = false + loadingGreenBar.Parent = loadingBar + + local loadingPercent = Instance.new("TextLabel") + loadingPercent.Name = "LoadingPercent" + loadingPercent.BackgroundTransparency = 1 + loadingPercent.Position = UDim2.new(0,0,1,0) + loadingPercent.Size = UDim2.new(1,0,0,14) + loadingPercent.Font = Enum.Font.Arial + loadingPercent.Text = "0%" + loadingPercent.FontSize = Enum.FontSize.Size14 + loadingPercent.TextColor3 = Color3.new(1,1,1) + loadingPercent.Parent = loadingBar + + local cancelButton = Instance.new("TextButton") + cancelButton.Name = "CancelButton" + cancelButton.Position = UDim2.new(0.5,-60,1,-40) + cancelButton.Size = UDim2.new(0,120,0,40) + cancelButton.Font = Enum.Font.Arial + cancelButton.FontSize = Enum.FontSize.Size18 + cancelButton.TextColor3 = Color3.new(1,1,1) + cancelButton.Text = "Cancel" + cancelButton.Style = Enum.ButtonStyle.RobloxButton + cancelButton.Parent = loadingFrame + + local loadingName = Instance.new("TextLabel") + loadingName.Name = "loadingName" + loadingName.BackgroundTransparency = 1 + loadingName.Size = UDim2.new(1,0,0,18) + loadingName.Position = UDim2.new(0,0,0,2) + loadingName.Font = Enum.Font.Arial + loadingName.Text = name + loadingName.TextColor3 = Color3.new(1,1,1) + loadingName.TextStrokeTransparency = 1 + loadingName.FontSize = Enum.FontSize.Size18 + loadingName.Parent = loadingFrame + + local cancelButtonClicked = Instance.new("BindableEvent") + cancelButtonClicked.Name = "CancelButtonClicked" + cancelButtonClicked.Parent = cancelButton + cancelButton.MouseButton1Click:connect(function() + cancelButtonClicked:Fire() + end) + + local updateLoadingGuiPercent = function(percent, tweenAction, tweenLength) + if percent and type(percent) ~= "number" then + error("updateLoadingGuiPercent expects number as argument, got",type(percent),"instead") + end + + local newSize = nil + if percent < 0 then + newSize = UDim2.new(0,0,1,0) + elseif percent > 1 then + newSize = UDim2.new(1,0,1,0) + else + newSize = UDim2.new(percent,0,1,0) + end + + if tweenAction then + if not tweenLength then + error("updateLoadingGuiPercent is set to tween new percentage, but got no tween time length! Please pass this in as third argument") + end + + if (newSize.X.Scale > 0) then + loadingGreenBar.Visible = true + loadingGreenBar:TweenSize( newSize, + Enum.EasingDirection.Out, + Enum.EasingStyle.Quad, + tweenLength, + true) + else + loadingGreenBar:TweenSize( newSize, + Enum.EasingDirection.Out, + Enum.EasingStyle.Quad, + tweenLength, + true, + function() + if (newSize.X.Scale < 0) then + loadingGreenBar.Visible = false + end + end) + end + + else + loadingGreenBar.Size = newSize + loadingGreenBar.Visible = (newSize.X.Scale > 0) + end + end + + loadingGreenBar.Changed:connect(function(prop) + if prop == "Size" then + loadingPercent.Text = tostring( math.ceil(loadingGreenBar.Size.X.Scale * 100) ) .. "%" + end + end) + + return loadingFrame, updateLoadingGuiPercent, cancelButtonClicked +end + +t.CreatePluginFrame = function (name,size,position,scrollable,parent) + local function createMenuButton(size,position,text,fontsize,name,parent) + local button = Instance.new("TextButton") + button.AutoButtonColor = false + button.Name = name + button.BackgroundTransparency = 1 + button.Position = position + button.Size = size + button.Font = Enum.Font.ArialBold + button.FontSize = fontsize + button.Text = text + button.TextColor3 = Color3.new(1,1,1) + button.BorderSizePixel = 0 + button.BackgroundColor3 = Color3.new(20/255,20/255,20/255) + button.Parent = parent + + button.MouseEnter:connect(function ( ) + if button.Selected then return end + button.BackgroundTransparency = 0 + end) + button.MouseLeave:connect(function ( ) + if button.Selected then return end + button.BackgroundTransparency = 1 + end) + + return button + + end + + local dragBar = Instance.new("Frame") + dragBar.Name = tostring(name) .. "DragBar" + dragBar.BackgroundColor3 = Color3.new(39/255,39/255,39/255) + dragBar.BorderColor3 = Color3.new(0,0,0) + if size then + dragBar.Size = UDim2.new(size.X.Scale,size.X.Offset,0,20) + UDim2.new(0,20,0,0) + else + dragBar.Size = UDim2.new(0,183,0,20) + end + if position then + dragBar.Position = position + end + dragBar.Active = true + dragBar.Draggable = true + dragBar.Parent = parent + + dragBar.MouseEnter:connect(function ( ) + dragBar.BackgroundColor3 = Color3.new(49/255,49/255,49/255) + end) + dragBar.MouseLeave:connect(function ( ) + dragBar.BackgroundColor3 = Color3.new(39/255,39/255,39/255) + end) + + -- plugin name label + local pluginNameLabel = Instance.new("TextLabel") + pluginNameLabel.Name = "BarNameLabel" + pluginNameLabel.Text = " " .. tostring(name) + pluginNameLabel.TextColor3 = Color3.new(1,1,1) + pluginNameLabel.TextStrokeTransparency = 0 + pluginNameLabel.Size = UDim2.new(1,0,1,0) + pluginNameLabel.Font = Enum.Font.ArialBold + pluginNameLabel.FontSize = Enum.FontSize.Size18 + pluginNameLabel.TextXAlignment = Enum.TextXAlignment.Left + pluginNameLabel.BackgroundTransparency = 1 + pluginNameLabel.Parent = dragBar + + -- close button + local closeButton = createMenuButton(UDim2.new(0,15,0,17),UDim2.new(1,-16,0.5,-8),"X",Enum.FontSize.Size14,"CloseButton",dragBar) + local closeEvent = Instance.new("BindableEvent") + closeEvent.Name = "CloseEvent" + closeEvent.Parent = closeButton + closeButton.MouseButton1Click:connect(function () + closeEvent:Fire() + closeButton.BackgroundTransparency = 1 + end) + + -- help button + local helpButton = createMenuButton(UDim2.new(0,15,0,17),UDim2.new(1,-51,0.5,-8),"?",Enum.FontSize.Size14,"HelpButton",dragBar) + local helpFrame = Instance.new("Frame") + helpFrame.Name = "HelpFrame" + helpFrame.BackgroundColor3 = Color3.new(0,0,0) + helpFrame.Size = UDim2.new(0,300,0,552) + helpFrame.Position = UDim2.new(1,5,0,0) + helpFrame.Active = true + helpFrame.BorderSizePixel = 0 + helpFrame.Visible = false + helpFrame.Parent = dragBar + + helpButton.MouseButton1Click:connect(function( ) + helpFrame.Visible = not helpFrame.Visible + if helpFrame.Visible then + helpButton.Selected = true + helpButton.BackgroundTransparency = 0 + local screenGui = getLayerCollectorAncestor(helpFrame) + if screenGui then + if helpFrame.AbsolutePosition.X + helpFrame.AbsoluteSize.X > screenGui.AbsoluteSize.X then --position on left hand side + helpFrame.Position = UDim2.new(0,-5 - helpFrame.AbsoluteSize.X,0,0) + else -- position on right hand side + helpFrame.Position = UDim2.new(1,5,0,0) + end + else + helpFrame.Position = UDim2.new(1,5,0,0) + end + else + helpButton.Selected = false + helpButton.BackgroundTransparency = 1 + end + end) + + local minimizeButton = createMenuButton(UDim2.new(0,16,0,17),UDim2.new(1,-34,0.5,-8),"-",Enum.FontSize.Size14,"MinimizeButton",dragBar) + minimizeButton.TextYAlignment = Enum.TextYAlignment.Top + + local minimizeFrame = Instance.new("Frame") + minimizeFrame.Name = "MinimizeFrame" + minimizeFrame.BackgroundColor3 = Color3.new(73/255,73/255,73/255) + minimizeFrame.BorderColor3 = Color3.new(0,0,0) + minimizeFrame.Position = UDim2.new(0,0,1,0) + if size then + minimizeFrame.Size = UDim2.new(size.X.Scale,size.X.Offset,0,50) + UDim2.new(0,20,0,0) + else + minimizeFrame.Size = UDim2.new(0,183,0,50) + end + minimizeFrame.Visible = false + minimizeFrame.Parent = dragBar + + local minimizeBigButton = Instance.new("TextButton") + minimizeBigButton.Position = UDim2.new(0.5,-50,0.5,-20) + minimizeBigButton.Name = "MinimizeButton" + minimizeBigButton.Size = UDim2.new(0,100,0,40) + minimizeBigButton.Style = Enum.ButtonStyle.RobloxButton + minimizeBigButton.Font = Enum.Font.ArialBold + minimizeBigButton.FontSize = Enum.FontSize.Size18 + minimizeBigButton.TextColor3 = Color3.new(1,1,1) + minimizeBigButton.Text = "Show" + minimizeBigButton.Parent = minimizeFrame + + local separatingLine = Instance.new("Frame") + separatingLine.Name = "SeparatingLine" + separatingLine.BackgroundColor3 = Color3.new(115/255,115/255,115/255) + separatingLine.BorderSizePixel = 0 + separatingLine.Position = UDim2.new(1,-18,0.5,-7) + separatingLine.Size = UDim2.new(0,1,0,14) + separatingLine.Parent = dragBar + + local otherSeparatingLine = separatingLine:clone() + otherSeparatingLine.Position = UDim2.new(1,-35,0.5,-7) + otherSeparatingLine.Parent = dragBar + + local widgetContainer = Instance.new("Frame") + widgetContainer.Name = "WidgetContainer" + widgetContainer.BackgroundTransparency = 1 + widgetContainer.Position = UDim2.new(0,0,1,0) + widgetContainer.BorderColor3 = Color3.new(0,0,0) + if not scrollable then + widgetContainer.BackgroundTransparency = 0 + widgetContainer.BackgroundColor3 = Color3.new(72/255,72/255,72/255) + end + widgetContainer.Parent = dragBar + + if size then + if scrollable then + widgetContainer.Size = size + else + widgetContainer.Size = UDim2.new(0,dragBar.AbsoluteSize.X,size.Y.Scale,size.Y.Offset) + end + else + if scrollable then + widgetContainer.Size = UDim2.new(0,163,0,400) + else + widgetContainer.Size = UDim2.new(0,dragBar.AbsoluteSize.X,0,400) + end + end + if position then + widgetContainer.Position = position + UDim2.new(0,0,0,20) + end + + local frame,control,verticalDragger = nil + if scrollable then + --frame for widgets + frame,control = t.CreateTrueScrollingFrame() + frame.Size = UDim2.new(1, 0, 1, 0) + frame.BackgroundColor3 = Color3.new(72/255,72/255,72/255) + frame.BorderColor3 = Color3.new(0,0,0) + frame.Active = true + frame.Parent = widgetContainer + control.Parent = dragBar + control.BackgroundColor3 = Color3.new(72/255,72/255,72/255) + control.BorderSizePixel = 0 + control.BackgroundTransparency = 0 + control.Position = UDim2.new(1,-21,1,1) + if size then + control.Size = UDim2.new(0,21,size.Y.Scale,size.Y.Offset) + else + control.Size = UDim2.new(0,21,0,400) + end + control:FindFirstChild("ScrollDownButton").Position = UDim2.new(0,0,1,-20) + + local fakeLine = Instance.new("Frame") + fakeLine.Name = "FakeLine" + fakeLine.BorderSizePixel = 0 + fakeLine.BackgroundColor3 = Color3.new(0,0,0) + fakeLine.Size = UDim2.new(0,1,1,1) + fakeLine.Position = UDim2.new(1,0,0,0) + fakeLine.Parent = control + + verticalDragger = Instance.new("TextButton") + verticalDragger.ZIndex = 2 + verticalDragger.AutoButtonColor = false + verticalDragger.Name = "VerticalDragger" + verticalDragger.BackgroundColor3 = Color3.new(50/255,50/255,50/255) + verticalDragger.BorderColor3 = Color3.new(0,0,0) + verticalDragger.Size = UDim2.new(1,20,0,20) + verticalDragger.Position = UDim2.new(0,0,1,0) + verticalDragger.Active = true + verticalDragger.Text = "" + verticalDragger.Parent = widgetContainer + + local scrubFrame = Instance.new("Frame") + scrubFrame.Name = "ScrubFrame" + scrubFrame.BackgroundColor3 = Color3.new(1,1,1) + scrubFrame.BorderSizePixel = 0 + scrubFrame.Position = UDim2.new(0.5,-5,0.5,0) + scrubFrame.Size = UDim2.new(0,10,0,1) + scrubFrame.ZIndex = 5 + scrubFrame.Parent = verticalDragger + local scrubTwo = scrubFrame:clone() + scrubTwo.Position = UDim2.new(0.5,-5,0.5,-2) + scrubTwo.Parent = verticalDragger + local scrubThree = scrubFrame:clone() + scrubThree.Position = UDim2.new(0.5,-5,0.5,2) + scrubThree.Parent = verticalDragger + + local areaSoak = Instance.new("TextButton",getLayerCollectorAncestor(parent)) + areaSoak.Name = "AreaSoak" + areaSoak.Size = UDim2.new(1,0,1,0) + areaSoak.BackgroundTransparency = 1 + areaSoak.BorderSizePixel = 0 + areaSoak.Text = "" + areaSoak.ZIndex = 10 + areaSoak.Visible = false + areaSoak.Active = true + + local draggingVertical = false + local startYPos = nil + verticalDragger.MouseEnter:connect(function () + verticalDragger.BackgroundColor3 = Color3.new(60/255,60/255,60/255) + end) + verticalDragger.MouseLeave:connect(function () + verticalDragger.BackgroundColor3 = Color3.new(50/255,50/255,50/255) + end) + verticalDragger.MouseButton1Down:connect(function(x,y) + draggingVertical = true + areaSoak.Visible = true + startYPos = y + end) + areaSoak.MouseButton1Up:connect(function ( ) + draggingVertical = false + areaSoak.Visible = false + end) + areaSoak.MouseMoved:connect(function(x,y) + if not draggingVertical then return end + + local yDelta = y - startYPos + if not control.ScrollDownButton.Visible and yDelta > 0 then + return + end + + if (widgetContainer.Size.Y.Offset + yDelta) < 150 then + widgetContainer.Size = UDim2.new(widgetContainer.Size.X.Scale, widgetContainer.Size.X.Offset,widgetContainer.Size.Y.Scale,150) + control.Size = UDim2.new (0,21,0,150) + return + end + + startYPos = y + + if widgetContainer.Size.Y.Offset + yDelta >= 0 then + widgetContainer.Size = UDim2.new(widgetContainer.Size.X.Scale, widgetContainer.Size.X.Offset,widgetContainer.Size.Y.Scale,widgetContainer.Size.Y.Offset + yDelta) + control.Size = UDim2.new(0,21,0,control.Size.Y.Offset + yDelta ) + end + end) + end + + local function switchMinimize() + minimizeFrame.Visible = not minimizeFrame.Visible + if scrollable then + frame.Visible = not frame.Visible + verticalDragger.Visible = not verticalDragger.Visible + control.Visible = not control.Visible + else + widgetContainer.Visible = not widgetContainer.Visible + end + + if minimizeFrame.Visible then + minimizeButton.Text = "+" + else + minimizeButton.Text = "-" + end + end + + minimizeBigButton.MouseButton1Click:connect(function ( ) + switchMinimize() + end) + + minimizeButton.MouseButton1Click:connect(function( ) + switchMinimize() + end) + + if scrollable then + return dragBar, frame, helpFrame, closeEvent + else + return dragBar, widgetContainer, helpFrame, closeEvent + end +end + +t.Help = + function(funcNameOrFunc) + --input argument can be a string or a function. Should return a description (of arguments and expected side effects) + if funcNameOrFunc == "CreatePropertyDropDownMenu" or funcNameOrFunc == t.CreatePropertyDropDownMenu then + return "Function CreatePropertyDropDownMenu. " .. + "Arguments: (instance, propertyName, enumType). " .. + "Side effect: returns a container with a drop-down-box that is linked to the 'property' field of 'instance' which is of type 'enumType'" + end + if funcNameOrFunc == "CreateDropDownMenu" or funcNameOrFunc == t.CreateDropDownMenu then + return "Function CreateDropDownMenu. " .. + "Arguments: (items, onItemSelected). " .. + "Side effect: Returns 2 results, a container to the gui object and a 'updateSelection' function for external updating. The container is a drop-down-box created around a list of items" + end + if funcNameOrFunc == "CreateMessageDialog" or funcNameOrFunc == t.CreateMessageDialog then + return "Function CreateMessageDialog. " .. + "Arguments: (title, message, buttons). " .. + "Side effect: Returns a gui object of a message box with 'title' and 'message' as passed in. 'buttons' input is an array of Tables contains a 'Text' and 'Function' field for the text/callback of each button" + end + if funcNameOrFunc == "CreateStyledMessageDialog" or funcNameOrFunc == t.CreateStyledMessageDialog then + return "Function CreateStyledMessageDialog. " .. + "Arguments: (title, message, style, buttons). " .. + "Side effect: Returns a gui object of a message box with 'title' and 'message' as passed in. 'buttons' input is an array of Tables contains a 'Text' and 'Function' field for the text/callback of each button, 'style' is a string, either Error, Notify or Confirm" + end + if funcNameOrFunc == "GetFontHeight" or funcNameOrFunc == t.GetFontHeight then + return "Function GetFontHeight. " .. + "Arguments: (font, fontSize). " .. + "Side effect: returns the size in pixels of the given font + fontSize" + end + if funcNameOrFunc == "LayoutGuiObjects" or funcNameOrFunc == t.LayoutGuiObjects then + + end + if funcNameOrFunc == "CreateScrollingFrame" or funcNameOrFunc == t.CreateScrollingFrame then + return "Function CreateScrollingFrame. " .. + "Arguments: (orderList, style) " .. + "Side effect: returns 4 objects, (scrollFrame, scrollUpButton, scrollDownButton, recalculateFunction). 'scrollFrame' can be filled with GuiObjects. It will lay them out and allow scrollUpButton/scrollDownButton to interact with them. Orderlist is optional (and specifies the order to layout the children. Without orderlist, it uses the children order. style is also optional, and allows for a 'grid' styling if style is passed 'grid' as a string. recalculateFunction can be called when a relayout is needed (when orderList changes)" + end + if funcNameOrFunc == "CreateTrueScrollingFrame" or funcNameOrFunc == t.CreateTrueScrollingFrame then + return "Function CreateTrueScrollingFrame. " .. + "Arguments: (nil) " .. + "Side effect: returns 2 objects, (scrollFrame, controlFrame). 'scrollFrame' can be filled with GuiObjects, and they will be clipped if not inside the frame's bounds. controlFrame has children scrollup and scrolldown, as well as a slider. controlFrame can be parented to any guiobject and it will readjust itself to fit." + end + if funcNameOrFunc == "AutoTruncateTextObject" or funcNameOrFunc == t.AutoTruncateTextObject then + return "Function AutoTruncateTextObject. " .. + "Arguments: (textLabel) " .. + "Side effect: returns 2 objects, (textLabel, changeText). The 'textLabel' input is modified to automatically truncate text (with ellipsis), if it gets too small to fit. 'changeText' is a function that can be used to change the text, it takes 1 string as an argument" + end + if funcNameOrFunc == "CreateSlider" or funcNameOrFunc == t.CreateSlider then + return "Function CreateSlider. " .. + "Arguments: (steps, width, position) " .. + "Side effect: returns 2 objects, (sliderGui, sliderPosition). The 'steps' argument specifies how many different positions the slider can hold along the bar. 'width' specifies in pixels how wide the bar should be (modifiable afterwards if desired). 'position' argument should be a UDim2 for slider positioning. 'sliderPosition' is an IntValue whose current .Value specifies the specific step the slider is currently on." + end + if funcNameOrFunc == "CreateSliderNew" or funcNameOrFunc == t.CreateSliderNew then + return "Function CreateSliderNew. " .. + "Arguments: (steps, width, position) " .. + "Side effect: returns 2 objects, (sliderGui, sliderPosition). The 'steps' argument specifies how many different positions the slider can hold along the bar. 'width' specifies in pixels how wide the bar should be (modifiable afterwards if desired). 'position' argument should be a UDim2 for slider positioning. 'sliderPosition' is an IntValue whose current .Value specifies the specific step the slider is currently on." + end + if funcNameOrFunc == "CreateLoadingFrame" or funcNameOrFunc == t.CreateLoadingFrame then + return "Function CreateLoadingFrame. " .. + "Arguments: (name, size, position) " .. + "Side effect: Creates a gui that can be manipulated to show progress for a particular action. Name appears above the loading bar, and size and position are udim2 values (both size and position are optional arguments). Returns 3 arguments, the first being the gui created. The second being updateLoadingGuiPercent, which is a bindable function. This function takes one argument (two optionally), which should be a number between 0 and 1, representing the percentage the loading gui should be at. The second argument to this function is a boolean value that if set to true will tween the current percentage value to the new percentage value, therefore our third argument is how long this tween should take. Our third returned argument is a BindableEvent, that when fired means that someone clicked the cancel button on the dialog." + end + if funcNameOrFunc == "CreateTerrainMaterialSelector" or funcNameOrFunc == t.CreateTerrainMaterialSelector then + return "Function CreateTerrainMaterialSelector. " .. + "Arguments: (size, position) " .. + "Side effect: Size and position are UDim2 values that specifies the selector's size and position. Both size and position are optional arguments. This method returns 3 objects (terrainSelectorGui, terrainSelected, forceTerrainSelection). terrainSelectorGui is just the gui object that we generate with this function, parent it as you like. TerrainSelected is a BindableEvent that is fired whenever a new terrain type is selected in the gui. ForceTerrainSelection is a function that takes an argument of Enum.CellMaterial and will force the gui to show that material as currently selected." + end + end + +return t \ No newline at end of file diff --git a/src/Lualibs/StatefulImageButton.d.ts b/src/Lualibs/StatefulImageButton.d.ts new file mode 100644 index 0000000..694889f --- /dev/null +++ b/src/Lualibs/StatefulImageButton.d.ts @@ -0,0 +1,7 @@ +declare class StatefulImageButtonClass { + constructor(buttonName: string, imageAsset: string, buttonSize: UDim2); + setSelected(selected: boolean): void; + getSelected(): boolean; + getButton(): Instance; +} +export = StatefulImageButtonClass; diff --git a/src/Lualibs/StatefulImageButton.lua b/src/Lualibs/StatefulImageButton.lua new file mode 100644 index 0000000..6ee1121 --- /dev/null +++ b/src/Lualibs/StatefulImageButton.lua @@ -0,0 +1,95 @@ +---------------------------------------- +-- +-- StatefulImageButton.lua +-- +-- Image button. +-- Has custom image for when "selected" +-- Uses shading to indicate hover and click states. +-- +---------------------------------------- +GuiUtilities = require(script.Parent.GuiUtilities) + +StatefulImageButtonClass = {} +StatefulImageButtonClass.__index = StatefulImageButtonClass + +function StatefulImageButtonClass.new(buttonName, imageAsset, buttonSize) + local self = {} + setmetatable(self, StatefulImageButtonClass) + + local button = Instance.new("ImageButton") + button.Parent = parent + button.Image = imageAsset + button.BackgroundTransparency = 1 + button.BorderSizePixel = 0 + button.Size = buttonSize + button.Name = buttonName + + self._button = button + + self._hovered = false + self._clicked = false + self._selected = false + + button.InputBegan:connect(function(input) + if (input.UserInputType == Enum.UserInputType.MouseMovement) then + self._hovered = true + self:_updateButtonVisual() + end + end) + + + button.InputEnded:connect(function(input) + if (input.UserInputType == Enum.UserInputType.MouseMovement) then + self._hovered = false + self._clicked = false + self:_updateButtonVisual() + end + end) + + button.MouseButton1Down:connect(function() + self._clicked = true + self:_updateButtonVisual() + end) + + button.MouseButton1Up:connect(function() + self._clicked = false + self:_updateButtonVisual() + end) + + self:_updateButtonVisual() + + return self +end + +function StatefulImageButtonClass:_updateButtonVisual() + if (self._selected) then + self._button.ImageTransparency = 0 + self._button.ImageColor3 = Color3.new(1,1,1) + else + self._button.ImageTransparency = 0.5 + self._button.ImageColor3 = Color3.new(.5,.5,.5) + end + + if (self._clicked) then + self._button.BackgroundTransparency = 0.8 + elseif (self._hovered) then + self._button.BackgroundTransparency = 0.9 + else + self._button.BackgroundTransparency = 1 + end +end + +function StatefulImageButtonClass:setSelected(selected) + self._selected = selected + self:_updateButtonVisual() +end + +function StatefulImageButtonClass:getSelected() + return self._selected +end + +function StatefulImageButtonClass:getButton() + return self._button +end + +return StatefulImageButtonClass \ No newline at end of file diff --git a/src/Lualibs/VerticalScrollingFrame.d.ts b/src/Lualibs/VerticalScrollingFrame.d.ts new file mode 100644 index 0000000..7fb4c8e --- /dev/null +++ b/src/Lualibs/VerticalScrollingFrame.d.ts @@ -0,0 +1,6 @@ +declare class VerticalScrollingFrame { + constructor(suffix: string); + GetContentsFrame(): Instance; + GetSectionFrame(): Instance; +} +export = VerticalScrollingFrame; diff --git a/src/Lualibs/VerticalScrollingFrame.lua b/src/Lualibs/VerticalScrollingFrame.lua new file mode 100644 index 0000000..fa50495 --- /dev/null +++ b/src/Lualibs/VerticalScrollingFrame.lua @@ -0,0 +1,87 @@ +---------------------------------------- +-- +-- VerticalScrollingFrame.lua +-- +-- Creates a scrolling frame that automatically updates canvas size +-- +---------------------------------------- + +local GuiUtilities = require(script.Parent.GuiUtilities) + +local VerticalScrollingFrame = {} +VerticalScrollingFrame.__index = VerticalScrollingFrame + +function VerticalScrollingFrame.new(suffix) + local self = {} + setmetatable(self, VerticalScrollingFrame) + + local section = Instance.new("Frame") + section.BorderSizePixel = 0 + section.Size = UDim2.new(1, 0, 1, 0) + section.Position = UDim2.new(0, 0, 0, 0) + section.BackgroundTransparency = 1 + section.Name = "VerticalScrollFrame" .. suffix + + local scrollBackground = Instance.new("Frame") + scrollBackground.Name = "ScrollbarBackground" + scrollBackground.BackgroundColor3 = Color3.fromRGB(238, 238, 238) + scrollBackground.BorderColor3 = Color3.fromRGB(182, 182, 182) + scrollBackground.Size = UDim2.new(0, 15, 1, -2) + scrollBackground.Position = UDim2.new(1, -16, 0, 1) + scrollBackground.Parent = section + scrollBackground.ZIndex = 2; + + local scrollFrame = Instance.new("ScrollingFrame") + scrollFrame.Name = "ScrollFrame" .. suffix + scrollFrame.VerticalScrollBarPosition = Enum.VerticalScrollBarPosition.Right + scrollFrame.VerticalScrollBarInset = Enum.ScrollBarInset.ScrollBar + scrollFrame.ElasticBehavior = Enum.ElasticBehavior.Never + scrollFrame.ScrollBarThickness = 17 + scrollFrame.BorderSizePixel = 0 + scrollFrame.BackgroundTransparency = 1 + scrollFrame.ZIndex = 2 + scrollFrame.TopImage = "http://www.roblox.com/asset/?id=1533255544" + scrollFrame.MidImage = "http://www.roblox.com/asset/?id=1535685612" + scrollFrame.BottomImage = "http://www.roblox.com/asset/?id=1533256504" + scrollFrame.Size = UDim2.new(1, 0, 1, 0) + scrollFrame.Position = UDim2.new(0, 0, 0, 0) + scrollFrame.Parent = section + + local uiListLayout = Instance.new("UIListLayout") + uiListLayout.SortOrder = Enum.SortOrder.LayoutOrder + uiListLayout.Parent = scrollFrame + + self._section = section + self._scrollFrame = scrollFrame + self._scrollBackground = scrollBackground + self._uiListLayout = uiListLayout + + scrollFrame:GetPropertyChangedSignal("AbsoluteSize"):connect(function() self:_updateScrollingFrameCanvas() end) + uiListLayout:GetPropertyChangedSignal("AbsoluteContentSize"):connect(function() self:_updateScrollingFrameCanvas() end) + self:_updateScrollingFrameCanvas() + + GuiUtilities.syncGuiElementScrollColor(scrollFrame) + GuiUtilities.syncGuiElementBorderColor(scrollBackground) + GuiUtilities.syncGuiElementTitleColor(scrollBackground) + + return self +end + +function VerticalScrollingFrame:_updateScrollbarBackingVisibility() + self._scrollBackground.Visible = self._scrollFrame.AbsoluteSize.y < self._uiListLayout.AbsoluteContentSize.y +end + +function VerticalScrollingFrame:_updateScrollingFrameCanvas() + self._scrollFrame.CanvasSize = UDim2.new(0, 0, 0, self._uiListLayout.AbsoluteContentSize.Y) + self:_updateScrollbarBackingVisibility() +end + +function VerticalScrollingFrame:GetContentsFrame() + return self._scrollFrame +end + +function VerticalScrollingFrame:GetSectionFrame() + return self._section +end + +return VerticalScrollingFrame \ No newline at end of file diff --git a/src/Lualibs/VerticallyScalingListFrame.d.ts b/src/Lualibs/VerticallyScalingListFrame.d.ts new file mode 100644 index 0000000..3af6193 --- /dev/null +++ b/src/Lualibs/VerticallyScalingListFrame.d.ts @@ -0,0 +1,8 @@ +declare class VerticallyScalingListFrame { + constructor(nameSuffix: string); + AddBottomPadding(): void; + GetFrame(): Instance; + AddChild(childFrame: Instance): void; + SetCallbackOnResize(callback: () => void): void; +} +export = VerticallyScalingListFrame; diff --git a/src/Lualibs/VerticallyScalingListFrame.lua b/src/Lualibs/VerticallyScalingListFrame.lua new file mode 100644 index 0000000..030409a --- /dev/null +++ b/src/Lualibs/VerticallyScalingListFrame.lua @@ -0,0 +1,73 @@ +---------------------------------------- +-- +-- VerticallyScalingListFrame +-- +-- Creates a frame that organizes children into a list layout. +-- Will scale dynamically as children grow. +-- +---------------------------------------- +GuiUtilities = require(script.Parent.GuiUtilities) + +VerticallyScalingListFrame = {} +VerticallyScalingListFrame.__index = VerticallyScalingListFrame + +local kBottomPadding = 10 + +function VerticallyScalingListFrame.new(nameSuffix) + local self = {} + setmetatable(self, VerticallyScalingListFrame) + + self._resizeCallback = nil + + local frame = Instance.new('Frame') + frame.Name = 'VSLFrame' .. nameSuffix + frame.Size = UDim2.new(1, 0, 0, height) + frame.BackgroundTransparency = 0 + frame.BorderSizePixel = 0 + GuiUtilities.syncGuiElementBackgroundColor(frame) + + self._frame = frame + + local uiListLayout = Instance.new('UIListLayout') + uiListLayout.SortOrder = Enum.SortOrder.LayoutOrder + uiListLayout.Parent = frame + self._uiListLayout = uiListLayout + + local function updateSizes() + self._frame.Size = UDim2.new(1, 0, 0, uiListLayout.AbsoluteContentSize.Y) + if (self._resizeCallback) then + self._resizeCallback() + end + end + self._uiListLayout:GetPropertyChangedSignal("AbsoluteContentSize"):connect(updateSizes) + updateSizes() + + self._childCount = 0 + + return self +end + +function VerticallyScalingListFrame:AddBottomPadding() + local frame = Instance.new("Frame") + frame.Name = "BottomPadding" + frame.BackgroundTransparency = 1 + frame.Size = UDim2.new(1, 0, 0, kBottomPadding) + frame.LayoutOrder = 1000 + frame.Parent = self._frame +end + +function VerticallyScalingListFrame:GetFrame() + return self._frame +end + +function VerticallyScalingListFrame:AddChild(childFrame) + childFrame.LayoutOrder = self._childCount + self._childCount = self._childCount + 1 + childFrame.Parent = self._frame +end + +function VerticallyScalingListFrame:SetCallbackOnResize(callback) + self._resizeCallback = callback +end + +return VerticallyScalingListFrame \ No newline at end of file diff --git a/src/Toolbar/WidgetButton.ts b/src/Toolbar/WidgetButton.ts new file mode 100644 index 0000000..08db165 --- /dev/null +++ b/src/Toolbar/WidgetButton.ts @@ -0,0 +1,9 @@ +export class WidgetButton { + constructor(toolbar: PluginToolbar, widget: DockWidgetPluginGui, buttonText: string, icon: string) { + const widgetButton = toolbar.CreateButton(buttonText, buttonText, icon); + widgetButton.Click.Connect(() => { + widgetButton.SetActive(!widget.Enabled); + widget.Enabled = !widget.Enabled; + }); + } +} diff --git a/src/Utils/Gui.ts b/src/Utils/Gui.ts new file mode 100644 index 0000000..3716d59 --- /dev/null +++ b/src/Utils/Gui.ts @@ -0,0 +1,30 @@ +export function createAnchor(model: Folder, position: Vector3) { + // Create Anchor for Adornments + const anchor = new Instance("Part"); + anchor.Anchored = true; + anchor.CanCollide = false; + anchor.Transparency = 1; + anchor.Size = new Vector3(0.1, 0.1, 0.1); + anchor.Position = position; + anchor.Parent = model; + anchor.Name = "_GizmoAnchor"; + return anchor; +} + +export function syncGuiColors(...objects: GuiObject[]) { + function setColors() { + for (const guiObject of objects) { + const studio = settings().Studio as Studio & { Theme: StudioTheme }; + pcall(() => { + guiObject.BackgroundColor3 = studio.Theme.GetColor(Enum.StudioStyleGuideColor.MainBackground); + }); + pcall(() => { + if (guiObject.IsA("TextLabel")) { + guiObject.TextColor3 = studio.Theme.GetColor(Enum.StudioStyleGuideColor.MainText); + } + }); + } + } + setColors(); + settings().Studio.ThemeChanged.Connect(setColors); +} diff --git a/src/Utils/Room.ts b/src/Utils/Room.ts new file mode 100644 index 0000000..bda1bd0 --- /dev/null +++ b/src/Utils/Room.ts @@ -0,0 +1,18 @@ +type RoomConfig = Configuration & { + RoomId: IntValue; + RoomType: StringValue; + Origin: Vector3Value; + End: Vector3Value; + [key: `Exit_${number}`]: CFrameValue; +}; + +export function checkRoomConfig(obj: Instance): obj is RoomConfig { + return ( + (obj.IsA("Configuration") && + obj.FindFirstChild("RoomId")?.IsA("IntValue") && + obj.FindFirstChild("RoomType")?.IsA("StringValue") && + obj.FindFirstChild("Origin")?.IsA("Vector3Value") && + obj.FindFirstChild("End")?.IsA("Vector3Value")) ?? + false + ); +} diff --git a/src/Widget/RoomWidget.lua b/src/Widget/RoomWidget.lua new file mode 100644 index 0000000..a2a6fb6 --- /dev/null +++ b/src/Widget/RoomWidget.lua @@ -0,0 +1,209 @@ +local RoomWidget = {} + +local ScrollingFrame = require(script.Parent.Parent.Parent.StudioWidgets.VerticalScrollingFrame) +local VerticallyScalingListFrame = require(script.Parent.Parent.Parent.StudioWidgets.VerticallyScalingListFrame) +local CollapsibleTitledSection = require(script.Parent.Parent.Parent.StudioWidgets.CollapsibleTitledSection) +local LabeledTextInput = require(script.Parent.Parent.Parent.StudioWidgets.LabeledTextInput) +local CustomTextButton = require(script.Parent.Parent.Parent.StudioWidgets.CustomTextButton) + +local guiModule = require(script.Parent.Parent.Parent.Tools.Gui) +local UseLessModule = require(script.Parent.Parent.Parent.Tools.Useless) + + +function RoomWidget:new(plugin:Plugin,adornmentContainer:Folder,pluginModel:Folder) + self = setmetatable({}, {__index = RoomWidget}) + + self.adornmentContainer = adornmentContainer + self.pluginModel = pluginModel + + -- Create Widget + self.info = DockWidgetPluginGuiInfo.new( + Enum.InitialDockState.Left, + false, + false, + 200, + 300, + 150, + 150 + ) + + self.widget = plugin:CreateDockWidgetPluginGui( + "RoomWidget", + self.info + ) + self.widget.Title = "Room Info" + + -- Create Widget Components + -- Create No Room Label + self.noRoomLabel = Instance.new("TextLabel") + self.noRoomLabel.Name = "NoSelect" + self.noRoomLabel.Text = "Select a room to use this widget." + self.noRoomLabel.Size = UDim2.new(1,0,1,0) + guiModule.syncGuiColors({ self.noRoomLabel }) + + -- Create Scrolling Frame + self.scrollFrame = ScrollingFrame.new("RoomScroll") + + -- Create Vertical Scaling List Frame + self.listFrame = VerticallyScalingListFrame.new("RoomWidget") + + -- Create Room Collapse + self.roomCollapse = CollapsibleTitledSection.new( + "suffix", -- name suffix of the gui object + "Room", -- the text displayed beside the collapsible arrow + true, -- have the content frame auto-update its size? + true, -- minimizable? + false -- minimized by default? + ) + + -- Create Exit Collapse + self.exitCollapse = CollapsibleTitledSection.new( + "ExitCollapse", -- name suffix of the gui object + "Exit", -- title text of the collapsible arrow + true, -- have the content frame auto-update its size? + true, -- minimizable? + false -- minimized by default? + ) + + -- Create TextInput + self.roomIdValue = Instance.new("IntValue") + self.roomIdLabel = LabeledTextInput.new( + "RoomId", -- name suffix of gui object + "Room Id", -- title text of the multi choice + "0" -- default value + ) + self.roomIdLabel:SetValueChangedFunction( + function (value) + self.roomIdValue.Value = value + end + ) + + self.typeValue = Instance.new("StringValue") + self.typeLabel = LabeledTextInput.new( + "RoomType", -- name suffix of gui object + "Room Type", -- title text of the multi choice + "" -- default value + ) + self.typeLabel:SetMaxGraphemes(255) + self.typeLabel:SetValueChangedFunction( + function (value) + self.typeValue.Value = value + end + ) + + -- Setup Widget + self.roomIdLabel:GetFrame().Parent = self.roomCollapse:GetContentsFrame() + self.typeLabel:GetFrame().Parent = self.roomCollapse:GetContentsFrame() + self.listFrame:AddChild(self.roomCollapse:GetSectionFrame()) + self.listFrame:AddChild(self.exitCollapse:GetSectionFrame()) + + self.listFrame:AddBottomPadding() + + self.listFrame:GetFrame().Parent = self.scrollFrame:GetContentsFrame() + self.scrollFrame:GetSectionFrame().Parent = self.widget + self.noRoomLabel.Parent = self.widget + + return self +end + +function RoomWidget:UpdateValue(roomIdValue:IntValue,roomTypeValue:StringValue,roomExit:{CFrameValue}) + self.roomIdValue = roomIdValue + self.roomIdLabel:SetValue(roomIdValue.Value) + self.typeValue = roomTypeValue + self.typeLabel:SetValue(roomTypeValue.Value) +end + +function RoomWidget:SetActive(active:boolean) + self.noRoomLabel.Visible = not active + self.scrollFrame.Visible = active +end + +function RoomWidget:_clearAdornment() + self.adornmentContainer:ClearAllChildren() + self.pluginModel:ClearAllChildren() +end + +function RoomWidget:ReloadExit(exits:{CFrameValue}) + self.exitCollapse:GetContentsFrame():ClearAllChildren() + + for _,exit in exits do + local exitCollapse = CollapsibleTitledSection.new( + "ExitCollapse_"..exit.Name, -- name suffix of the gui object + exit.Name, -- the text displayed beside the collapsible arrow + true, -- have the content frame auto-update its size? + true, -- minimizable? + false -- minimized by default? + ) + + local button = CustomTextButton.new( + "edit_button", -- name of the gui object + "Edit" -- the text displayed on the button + ) + button:GetButton().Activated:Connect( + function(inputObject: InputObject, clickCount: number) + + end + ) + + -- Handle widget + exitCollapse:GetContentsFrame().Parent = self.exitCollapse:GetSectionFrame() + end +end + +function RoomWidget:LoadExitMoveHandles(exit: CFrameValue) + self:_clearAdornment() + + local function createAnchor(position: Vector3) + -- Create Anchor for Adornments + local anchor = Instance.new("Part") + anchor.Anchored = true + anchor.CanCollide = false + anchor.Transparency = 1 + anchor.Size = Vector3.new(0.1, 0.1, 0.1) + anchor.Position = position + anchor.Parent = self.pluginModel + anchor.Name = "_GizmoAnchor" + return anchor + end + + local anchor = createAnchor(exit.Value.Position) + local handles = Instance.new("Handles") + handles.Adornee = anchor + handles.Parent = self.adornmentContainer + + local currentVector = Vector3.new(0, 0, 0) + + handles.MouseButton1Down:Connect( + function(face: Enum.NormalId) + currentVector = anchor.Position + end + ) + + handles.MouseDrag:Connect( + function(face: Enum.NormalId, distance: number) + -- Apply the changes to the anchor's position + if face == Enum.NormalId.Top or face == Enum.NormalId.Right or face == Enum.NormalId.Back then + anchor.Position = UseLessModule.roundVector3(currentVector + Vector3.new( + UseLessModule.bton(face == Enum.NormalId.Right) * distance, + UseLessModule.bton(face == Enum.NormalId.Top) * distance, + UseLessModule.bton(face == Enum.NormalId.Back) * distance + )) + else + anchor.Position = UseLessModule.roundVector3(currentVector - Vector3.new( + UseLessModule.bton(face == Enum.NormalId.Left) * distance, + UseLessModule.bton(face == Enum.NormalId.Bottom) * distance, + UseLessModule.bton(face == Enum.NormalId.Front) * distance + )) + end + end + ) + + handles.MouseButton1Up:Connect( + function(face: Enum.NormalId) + local newpos = anchor.Position + position.Value = newpos + end + ) +end + +return RoomWidget \ No newline at end of file diff --git a/src/Widget/RoomWidget.ts b/src/Widget/RoomWidget.ts new file mode 100644 index 0000000..e16594a --- /dev/null +++ b/src/Widget/RoomWidget.ts @@ -0,0 +1,83 @@ +import CollapsibleTitledSection from "Lualibs/CollapsibleTitledSection"; +import LabeledTextInput from "Lualibs/LabeledTextInput"; +import VerticallyScalingListFrame from "Lualibs/VerticallyScalingListFrame"; +import VerticalScrollingFrame from "Lualibs/VerticalScrollingFrame"; +import { syncGuiColors } from "Utils/Gui"; + +export class RoomWidget { + plugin: Plugin; + model: Folder; + info: DockWidgetPluginGuiInfo; + widget: DockWidgetPluginGui; + noRoomLabel: TextLabel; + + scrollFrame = new VerticalScrollingFrame("RoomScroll"); + listFrame = new VerticallyScalingListFrame("RoomWidget"); + roomCollapse = new CollapsibleTitledSection( + "roomCollapse", // name suffix of the gui object + "Room", // the text displayed beside the collapsible arrow + true, // have the content frame auto-update its size? + true, // minimizable? + false, // minimized by default? + ); + exitCollapse = new CollapsibleTitledSection( + "ExitCollapse", // name suffix of the gui object + "Exit", // title text of the collapsible arrow + true, // have the content frame auto-update its size? + true, // minimizable? + false, // minimized by default? + ); + + roomIdValue = new Instance("IntValue"); + roomIdInput = new LabeledTextInput( + "RoomId", // name suffix of gui object + "Room Id", // title text of the multi choice + "0", // default value + ); + roomTypeValue = new Instance("StringValue"); + roomTypeInput = new LabeledTextInput( + "RoomType", // name suffix of gui object + "Room Type", // title text of the multi choice + "", // default value + ); + constructor(plugin: Plugin, model: Folder) { + this.plugin = plugin; + this.model = model; + + this.info = new DockWidgetPluginGuiInfo(Enum.InitialDockState.Left, false, false, 200, 300, 150, 150); + this.widget = plugin.CreateDockWidgetPluginGui("RoomWidget", this.info); + (this.widget as unknown as { Title: string }).Title = "Room Info"; + + this.noRoomLabel = new Instance("TextLabel"); + this.noRoomLabel.Text = "Select a room to use this widget."; + this.noRoomLabel.Size = new UDim2(1, 0, 1, 0); + syncGuiColors(this.noRoomLabel); + + this.roomIdInput.SetValueChangedFunction((value) => { + this.roomIdValue.Value = tonumber(value) ?? 0; + }); + + this.roomTypeInput.SetMaxGraphemes(255); + this.roomTypeInput.SetValueChangedFunction((value) => { + this.roomTypeValue.Value = value; + }); + + // Setup Widget + this.roomIdInput.GetFrame().Parent = this.roomCollapse.GetContentsFrame(); + this.roomTypeInput.GetFrame().Parent = this.roomCollapse.GetContentsFrame(); + this.listFrame.AddChild(this.roomCollapse.GetSectionFrame()); + this.listFrame.AddChild(this.exitCollapse.GetSectionFrame()); + + this.listFrame.AddBottomPadding(); + + this.listFrame.GetFrame().Parent = this.scrollFrame.GetContentsFrame(); + this.scrollFrame.GetSectionFrame().Parent = this.widget; + this.noRoomLabel.Parent = this.widget; + } + UpdateValue() { + + } + SetActive(active: boolean) { + this.noRoomLabel.Visible = !active; + } +} diff --git a/src/index.server.ts b/src/index.server.ts new file mode 100644 index 0000000..363c8ed --- /dev/null +++ b/src/index.server.ts @@ -0,0 +1,55 @@ +import Signal from "@rbxts/signal"; +import { HandlesArea } from "Adornment/Area"; +import { WidgetButton } from "Toolbar/WidgetButton"; +import { checkRoomConfig } from "Utils/Room"; + +// Services +const Selection = game.GetService("Selection"); +const CoreGui = game.GetService("CoreGui"); + +// Module +// const UseLessModule = require(script.Parent.Tools.Useless) +// const RoomWidget = require(script.Parent.Widget.Room.Main) +// const WidgetButton = require(script.Parent.Widget.WidgetTogger) +// const ToolsButtons = require(script.Parent.Buttons.ToolsButtons) + +// Create Widget +// const roomWidget = RoomWidget.new(plugin) + +// Create Toolbar +const toolbar = plugin.CreateToolbar("Next Station Plugin"); + +// Create Buttons +// const roomWidgetButton = new WidgetButton(toolbar, roomWidget.widget, "Room Info", "rbxassetid.//14978048121"); +// const createRoomButton = ToolsButtons.createNewRoomButton(toolbar) + +// Create CoreGui Folders +const pluginModel = new Instance("Folder"); +pluginModel.Name = "_constGizmoContainer"; +pluginModel.Parent = CoreGui; + +plugin.Unloading.Connect(() => { + pluginModel.Destroy(); +}); + +// Selection Room Config Controller +function clearAdornment() { + pluginModel.ClearAllChildren(); +} + +(Selection as unknown as { SelectionChanged: Signal }).SelectionChanged.Connect(() => { + // Get Selection + const selectedObjects = Selection.Get(); + // Reset Adornments + clearAdornment(); + // roomWidget.SetActive(false) + if (!selectedObjects.isEmpty()) { + const selected = selectedObjects[0]; + const config = selected.FindFirstChild("RoomConfig"); + if (selected.IsA("Model") && config && checkRoomConfig(config)) { + const roomArea = new HandlesArea(pluginModel, config.Origin.Value, config.End.Value); + roomArea.originValueChanged.Connect((value) => (config.Origin.Value = value)); + roomArea.tipValueChanged.Connect((value) => (config.End.Value = value)); + } + } +}); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..39f6696 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + // required + "allowSyntheticDefaultImports": true, + "downlevelIteration": true, + "jsx": "react", + "jsxFactory": "React.createElement", + "jsxFragmentFactory": "React.Fragment", + "module": "commonjs", + "moduleResolution": "Node", + "noLib": true, + "resolveJsonModule": true, + "experimentalDecorators": true, + "forceConsistentCasingInFileNames": true, + "moduleDetection": "force", + "strict": true, + "target": "ESNext", + "typeRoots": ["node_modules/@rbxts"], + + // configurable + "types": ["types/plugin"], + "rootDir": "src", + "outDir": "out", + "baseUrl": "src", + "incremental": true, + "tsBuildInfoFile": "out/tsconfig.tsbuildinfo" + } +}