add gs
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
local function createAccessorySchema(attachmentName)
|
||||
assert(attachmentName, "attachmentName cannot be nil")
|
||||
return {
|
||||
ClassName = "Accessory",
|
||||
_children = {
|
||||
{
|
||||
Name = "ThumbnailConfiguration",
|
||||
ClassName = "Configuration",
|
||||
_optional = true,
|
||||
_children = {
|
||||
{
|
||||
Name = "ThumbnailCameraTarget",
|
||||
ClassName = "ObjectValue",
|
||||
},
|
||||
{
|
||||
Name = "ThumbnailCameraValue",
|
||||
ClassName = "CFrameValue",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name = "Handle",
|
||||
ClassName = "Part",
|
||||
_children = {
|
||||
{
|
||||
Name = attachmentName,
|
||||
ClassName = "Attachment",
|
||||
},
|
||||
{
|
||||
ClassName = "SpecialMesh",
|
||||
},
|
||||
{
|
||||
ClassName = "StringValue",
|
||||
Name = "AvatarPartScaleType",
|
||||
_optional = true,
|
||||
},
|
||||
{
|
||||
ClassName = "TouchTransmitter",
|
||||
_optional = true,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
return createAccessorySchema
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
local HttpService = game:GetService("HttpService")
|
||||
local HttpRbxApiService = game:GetService("HttpRbxApiService")
|
||||
local ContentProvider = game:GetService("ContentProvider")
|
||||
|
||||
local function getBaseDomain()
|
||||
local baseUrl = ContentProvider.BaseUrl
|
||||
if string.sub(baseUrl, #baseUrl) ~= "/" then
|
||||
baseUrl = baseUrl .. "/"
|
||||
end
|
||||
local _, schemeEnd = string.find(baseUrl, "://")
|
||||
local _, prefixEnd = string.find(baseUrl, "%.", schemeEnd + 1)
|
||||
return string.sub(baseUrl, prefixEnd + 1)
|
||||
end
|
||||
|
||||
local MAX_RETRIES = 5
|
||||
|
||||
local function requestAndRetry(apiUrl, data, attempt)
|
||||
if attempt == nil then
|
||||
attempt = 0
|
||||
end
|
||||
|
||||
local success, response = pcall(function()
|
||||
return HttpRbxApiService:PostAsyncFullUrl(apiUrl, data)
|
||||
end)
|
||||
|
||||
if success then
|
||||
return true, response
|
||||
elseif attempt >= MAX_RETRIES then
|
||||
return false, response
|
||||
else
|
||||
local timeToWait = 2^(attempt - 1)
|
||||
wait(timeToWait)
|
||||
return requestAndRetry(apiUrl, data, attempt + 1)
|
||||
end
|
||||
end
|
||||
|
||||
local BASE_DOMAIN = getBaseDomain()
|
||||
local ITEM_CONFIGURATION_URL = string.format("https://itemconfiguration.%s", BASE_DOMAIN)
|
||||
local GET_ASSET_CREATION_DETAILS_URL = ITEM_CONFIGURATION_URL .. "v1/creations/get-asset-details"
|
||||
|
||||
local function getAssetCreationDetails(isAsync, assetIds)
|
||||
local success, response = requestAndRetry(
|
||||
GET_ASSET_CREATION_DETAILS_URL,
|
||||
HttpService:JSONEncode({ assetIds = assetIds })
|
||||
)
|
||||
|
||||
-- TODO: isAsync
|
||||
|
||||
if success then
|
||||
return true, HttpService:JSONDecode(response)
|
||||
else
|
||||
return false, response
|
||||
end
|
||||
end
|
||||
|
||||
return getAssetCreationDetails
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
local function checkName(nameList, instanceName)
|
||||
if type(nameList) == "table" then
|
||||
for _, name in pairs(nameList) do
|
||||
if name == instanceName then
|
||||
return true
|
||||
end
|
||||
end
|
||||
elseif type(nameList) == "string" then
|
||||
return nameList == instanceName
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function getReadableName(nameList)
|
||||
if type(nameList) == "table" then
|
||||
return table.concat(nameList, " or ")
|
||||
elseif type(nameList) == "string" then
|
||||
return nameList
|
||||
end
|
||||
return "*"
|
||||
end
|
||||
|
||||
local function validateWithSchemaHelper(schema, instance, authorizedSet)
|
||||
-- validate
|
||||
if instance.ClassName ~= schema.ClassName or (schema.Name ~= nil and not checkName(schema.Name, instance.Name)) then
|
||||
return { success = false }
|
||||
end
|
||||
|
||||
-- validate children
|
||||
if schema._children then
|
||||
for _, childSchema in pairs(schema._children) do
|
||||
local found = false
|
||||
local mostRecentFailure
|
||||
for _, child in pairs(instance:GetChildren()) do
|
||||
local result = validateWithSchemaHelper(childSchema, child, authorizedSet)
|
||||
if result.success then
|
||||
found = true
|
||||
break
|
||||
elseif result.message then
|
||||
mostRecentFailure = result
|
||||
end
|
||||
end
|
||||
if not found and not childSchema._optional then
|
||||
if mostRecentFailure then
|
||||
return mostRecentFailure
|
||||
else
|
||||
return {
|
||||
success = false,
|
||||
message = "Could not find a "
|
||||
.. childSchema.ClassName
|
||||
.. " called "
|
||||
.. getReadableName(childSchema.Name)
|
||||
.. " inside "
|
||||
.. instance.Name
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
authorizedSet[instance] = true
|
||||
|
||||
return { success = true }
|
||||
end
|
||||
|
||||
local function validateWithSchema(schema, instance)
|
||||
|
||||
if instance.ClassName ~= schema.ClassName or (schema.Name ~= nil and schema.Name ~= instance.Name) then
|
||||
return {
|
||||
success = false,
|
||||
message = "Expected top-level instance to be a " .. schema.ClassName,
|
||||
}
|
||||
end
|
||||
|
||||
local authorizedSet = {}
|
||||
local result = validateWithSchemaHelper(schema, instance, authorizedSet)
|
||||
|
||||
if not result.success then
|
||||
return result
|
||||
end
|
||||
|
||||
-- check for extra descendants
|
||||
local unauthorizedDescendantPaths = {}
|
||||
for _, descendant in pairs(instance:GetDescendants()) do
|
||||
if authorizedSet[descendant] == nil then
|
||||
unauthorizedDescendantPaths[#unauthorizedDescendantPaths + 1] = descendant:GetFullName()
|
||||
end
|
||||
end
|
||||
|
||||
if #unauthorizedDescendantPaths > 0 then
|
||||
return {
|
||||
success = false,
|
||||
message = "Unexpected Descendants:\n" .. table.concat(unauthorizedDescendantPaths, "\n")
|
||||
}
|
||||
end
|
||||
|
||||
return { success = true }
|
||||
end
|
||||
|
||||
return validateWithSchema
|
||||
@@ -0,0 +1,33 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
|
||||
local Cryo = require(CorePackages.Cryo)
|
||||
|
||||
local function round(num, numDecimalPlaces)
|
||||
local mult = 10^(numDecimalPlaces or 0)
|
||||
return math.floor(num * mult + 0.5) / mult
|
||||
end
|
||||
|
||||
local function valueToString(propValue)
|
||||
local valueType = typeof(propValue)
|
||||
if propValue == Cryo.None then
|
||||
return "not defined"
|
||||
elseif valueType == "Vector3" then
|
||||
return string.format(
|
||||
"%d, %d, %d",
|
||||
round(propValue.X, 2),
|
||||
round(propValue.Y, 2),
|
||||
round(propValue.Z, 2)
|
||||
)
|
||||
elseif valueType == "Color3" then
|
||||
return string.format(
|
||||
"%d, %d, %d",
|
||||
math.floor(propValue.r * 255),
|
||||
math.floor(propValue.g * 255),
|
||||
math.floor(propValue.b * 255)
|
||||
)
|
||||
else
|
||||
return tostring(propValue)
|
||||
end
|
||||
end
|
||||
|
||||
return valueToString
|
||||
Reference in New Issue
Block a user