This commit is contained in:
lx
2026-07-06 14:01:11 -04:00
commit c4f97d729d
16468 changed files with 935321 additions and 0 deletions
@@ -0,0 +1,22 @@
return function(num, sep, sepCount)
assert(type(num) == "number", "formatInteger expects a number; was given type: " .. type(num))
sep = sep or ","
sepCount = sepCount or 3
local parsedInt = string.format("%.0f", math.abs(num))
local firstSeperatorIndex = #parsedInt % sepCount
if firstSeperatorIndex == 0 then
firstSeperatorIndex = sepCount
end
local seperatorPattern = "(" .. string.rep("%d", sepCount) .. ")"
local seperatorReplacement = sep .. "%1"
local result = parsedInt:sub(1, firstSeperatorIndex) ..
parsedInt:sub(firstSeperatorIndex+1):gsub(seperatorPattern, seperatorReplacement)
if num < 0 then
result = "-" .. result
end
return result
end
@@ -0,0 +1,99 @@
return function()
local formatInteger = require(script.Parent.formatInteger)
describe("FormatIntegerString", function()
it("should throw an error if called an a non-number type", function()
local num = "123"
expect(function()
formatInteger(num)
end).to.throw()
end)
it("Should format positive integer whose length less than or equal to sepCount with comma properly", function()
local num = 123
local expectedResult = "123"
expect(formatInteger(num)).to.equal(expectedResult)
end)
it("Should format negative integer whose length less than or equal to sepCount with comma properly", function()
local num = -123
local expectedResult = "-123"
expect(formatInteger(num)).to.equal(expectedResult)
end)
it("Should format positive integer whose length greater than sepCount with comma properly", function()
local num = 1234
local expectedResult = "1,234"
expect(formatInteger(num)).to.equal(expectedResult)
end)
it("Should format negative integer whose length greater than sepCount with comma properly", function()
local num = -1234
local expectedResult = "-1,234"
expect(formatInteger(num)).to.equal(expectedResult)
end)
it("Should format positive integer in the form for scientific notation with comma properly", function()
local num = 4.5e21
local expectedResult = "4,500,000,000,000,000,000,000"
expect(formatInteger(num)).to.equal(expectedResult)
end)
it("Should format negative integer in the form for scientific notation with comma properly", function()
local num = -4.5e21
local expectedResult = "-4,500,000,000,000,000,000,000"
expect(formatInteger(num)).to.equal(expectedResult)
end)
it("Should format positive and negative zero with comma properly ", function()
local num1 = 0
local num2 = -0
local expectedResult = "0"
expect(formatInteger(num1)).to.equal(expectedResult)
expect(formatInteger(num2)).to.equal(expectedResult)
end)
it("Should format positive integer whose length less than or equal to sepCount with dot properly", function()
local num = 12
local expectedResult = "12"
expect(formatInteger(num, ".", 2)).to.equal(expectedResult)
end)
it("Should format negative integer whose length less than or equal to sepCount with dot properly", function()
local num = -12
local expectedResult = "-12"
expect(formatInteger(num, ".", 2)).to.equal(expectedResult)
end)
it("Should format positive integer whose length greater than sepCount with dot properly", function()
local num = 123
local expectedResult = "1.23"
expect(formatInteger(num, ".", 2)).to.equal(expectedResult)
end)
it("Should format negative integer whose length greater than sepCount with comma properly", function()
local num = -123
local expectedResult = "-1.23"
expect(formatInteger(num, ".", 2)).to.equal(expectedResult)
end)
it("Should format positive integer whose length less than or equal to sepCount with dot properly", function()
local num = 123
local expectedResult = "123"
expect(formatInteger(num, ".", 4)).to.equal(expectedResult)
end)
it("Should format negative integer whose length less than or equal to sepCount with dot properly", function()
local num = -123
local expectedResult = "-123"
expect(formatInteger(num, ".", 4)).to.equal(expectedResult)
end)
it("Should format positive integer whose length greater than sepCount with dot properly", function()
local num = 12345
local expectedResult = "1.2345"
expect(formatInteger(num, ".", 4)).to.equal(expectedResult)
end)
it("Should format negative integer whose length greater than sepCount with comma properly", function()
local num = -12345
local expectedResult = "-1.2345"
expect(formatInteger(num, ".", 4)).to.equal(expectedResult)
end)
it("Should format positive integer whose length greater than sepCount with dot properly", function()
local num = 12345
local expectedResult = "1.2345"
expect(formatInteger(num, ".", 4)).to.equal(expectedResult)
end)
end)
end
@@ -0,0 +1,3 @@
return function(conversation)
return (conversation.title or conversation.titleForViewer):gsub("\n", "")
end
@@ -0,0 +1,18 @@
local ContentProvider = game:GetService("ContentProvider")
local CorePackages = game:GetService("CorePackages")
local trimCharacterFromEndString = require(CorePackages.AppTempCommon.Temp.trimCharacterFromEndString)
local BASE_URL = trimCharacterFromEndString(ContentProvider.BaseUrl, "/")
local len = #BASE_URL
if BASE_URL:find("https://www.") then
BASE_URL = BASE_URL:sub(13, len)
elseif BASE_URL:find("http://www.") then
BASE_URL = BASE_URL:sub(12, len)
end
local WEB_URL = "https://www." .. BASE_URL.."/games/"
return function(placeId)
assert(type(placeId) == "string", "getGameUrlByPlaceId expects a string; was given type: " .. type(placeId))
return WEB_URL .. placeId
end
@@ -0,0 +1,31 @@
return function()
local getGameUrlByPlaceId = require(script.Parent.getGameUrlByPlaceId)
local CorePackages = game:GetService("CorePackages")
local trimCharacterFromEndString = require(CorePackages.AppTempCommon.Temp.trimCharacterFromEndString)
describe("GetGameUrlByPlaceId", function()
it("should throw an error if called an a non-string type", function()
local placeId = 123456
expect(function()
getGameUrlByPlaceId(placeId)
end).to.throw()
end)
it("Should return the game Url properly", function()
local ContentProvider = game:GetService("ContentProvider")
local BASE_URL = trimCharacterFromEndString(ContentProvider.BaseUrl, "/")
local len = #BASE_URL
if BASE_URL:find("https://www.") then
BASE_URL = BASE_URL:sub(13, len)
elseif BASE_URL:find("http://www.") then
BASE_URL = BASE_URL:sub(12, len)
end
local WEB_URL = "https://www." .. BASE_URL.."/games/"
local placeId = "123456"
local expectedResult = WEB_URL .. placeId
expect(getGameUrlByPlaceId(placeId)).to.equal(expectedResult)
end)
end)
end
@@ -0,0 +1,9 @@
local luaAppLegacyInputDisabledGlobally = settings():GetFFlag('LuaAppLegacyInputDisabledGlobally2')
return function(component)
if luaAppLegacyInputDisabledGlobally then
return component.Activated
else
return component.MouseButton1Click
end
end
@@ -0,0 +1,7 @@
-- For use with InputBegan and InputEnded events
-- specifically to determine pressed/unpressed states
return function(inputObject)
local userInputType = inputObject.UserInputType
return (userInputType == Enum.UserInputType.Touch or userInputType == Enum.UserInputType.MouseButton1)
end
@@ -0,0 +1,40 @@
--[[
A user would has two options to launch a game
1) Parameter: gameRootPlaceId. Launch a game himself/herself.
2) Parameter: IN_GAME user. Launch a game which his/her friend is playing.
]]
local GuiService = game:GetService("GuiService")
local HttpService = game:GetService("HttpService")
local Modules = game:GetService("CoreGui").RobloxGui.Modules
local LuaApp = Modules.LuaApp
local LuaChat = Modules.LuaChat
local GameParams = require(LuaChat.Models.GameParams)
local NotificationType = require(LuaApp.Enum.NotificationType)
local JoinGame = {}
local function launchGame(gameParams)
local payload = HttpService:JSONEncode(gameParams)
GuiService:BroadcastNotification(payload, NotificationType.LAUNCH_GAME)
end
function JoinGame:ByUser(user)
local gameParams
if tostring(user.placeId) == tostring(user.rootPlaceId) then
gameParams = GameParams.fromPlaceInstance(user.placeId, user.gameInstanceId)
else
gameParams = GameParams.fromUserId(user.id)
end
launchGame(gameParams)
end
function JoinGame:ByGame(placeId)
local gameParams = GameParams.fromPlaceId(placeId)
launchGame(gameParams)
end
return JoinGame
@@ -0,0 +1,37 @@
return function()
local JoinGame = require(script.Parent.joinGame)
describe("Join Game", function()
it("should start a game by game instance id properly", function()
local user = {
placeId = "13822889",
rootPlaceId = 13822889,
gameInstanceId = "3f01a9e2-dc3c-4e5a-9e1e-2cc63c5d5b85",
}
expect(function()
JoinGame:ByUser(user)
end).to.be.ok()
end)
it("should start a game by user id properly", function()
local user = {
placeId = "13822889",
rootPlaceId = 13822890,
gameInstanceId = nil,
}
expect(function()
JoinGame:ByUser(user)
end).to.be.ok()
end)
it("should join a game with game root place id properly", function()
local gameRootPlaceId = "13822889"
expect(function()
JoinGame:ByGame(gameRootPlaceId)
end).to.be.ok()
end)
end)
end
@@ -0,0 +1,19 @@
local Modules = game:GetService("CoreGui").RobloxGui.Modules
local PercentReportingByCountryCode = tonumber(settings():GetFVariable("PercentReportingByCountryCode")) or 0
local WebApi = require(Modules.LuaChat.WebApi)
local function shouldReportForLocation()
return math.random(0, 99) < PercentReportingByCountryCode
end
return function(featureName, measureName, seconds)
if not shouldReportForLocation() then
return
end
local status = WebApi.ReportToDiagByCountryCode(featureName, measureName, seconds)
if status ~= WebApi.Status.OK then
warn("Failed to report ".. measureName .." to Diag")
end
end
@@ -0,0 +1,3 @@
return function(gameUrl)
return string.match(gameUrl, ".*%d+")
end