Catch up, several fixes and QoL.
This commit is contained in:
@ -1,19 +1,35 @@
|
||||
--!strict
|
||||
local Format: Format = {}
|
||||
local LegacyFonts = require(script.Parent.LegacyFonts)
|
||||
|
||||
local Vector2_consts = table.freeze({
|
||||
[Vector2.one] = "Vector2.one",
|
||||
[Vector2.zero] = "Vector2.zero",
|
||||
[Vector2.xAxis] = "Vector2.xAxis",
|
||||
[Vector2.yAxis] = "Vector2.yAxis",
|
||||
})
|
||||
|
||||
local Vector3_consts = table.freeze({
|
||||
[Vector3.one] = "Vector3.one",
|
||||
[Vector3.zero] = "Vector3.zero",
|
||||
[Vector3.xAxis] = "Vector3.xAxis",
|
||||
[Vector3.yAxis] = "Vector3.yAxis",
|
||||
[Vector3.zAxis] = "Vector3.zAxis",
|
||||
})
|
||||
|
||||
export type FormatFunc = (any) -> string
|
||||
export type Format = { [string]: FormatFunc }
|
||||
export type IEnum = { GetEnumItems: (IEnum) -> {EnumItem} }
|
||||
export type IEnum = { GetEnumItems: (IEnum) -> { EnumItem } }
|
||||
|
||||
local function flags(flagType: any, enum: Enum): string
|
||||
local value = 0
|
||||
|
||||
|
||||
for i, item: EnumItem in enum:GetEnumItems() do
|
||||
if (flags :: any)[item.Name] then
|
||||
if flagType[item.Name] then
|
||||
value += (2 ^ item.Value)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return tostring(value)
|
||||
end
|
||||
|
||||
@ -25,7 +41,7 @@ function Format.Bytes(value: string): string
|
||||
if #value > 0 then
|
||||
return string.format("Convert.FromBase64String(%q)", value)
|
||||
end
|
||||
|
||||
|
||||
return "Array.Empty<byte>()"
|
||||
end
|
||||
|
||||
@ -38,9 +54,9 @@ function Format.String(value: string): string
|
||||
end
|
||||
|
||||
function Format.Int(value: number): string
|
||||
if value == 2^31-1 then
|
||||
if value == 2 ^ 31 - 1 then
|
||||
return "int.MaxValue"
|
||||
elseif value == -2^31 then
|
||||
elseif value == -2 ^ 31 then
|
||||
return "int.MinValue"
|
||||
else
|
||||
return string.format("%i", value)
|
||||
@ -49,20 +65,20 @@ end
|
||||
|
||||
function Format.Number(value: number): string
|
||||
local int = math.floor(value)
|
||||
|
||||
|
||||
if math.abs(value - int) < 0.001 then
|
||||
return Format.Int(int)
|
||||
end
|
||||
|
||||
|
||||
local result = string.format("%.5f", value)
|
||||
result = result:gsub("%.?0+$", "")
|
||||
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
function Format.Double(value: number): string
|
||||
local result = Format.Number(value)
|
||||
|
||||
|
||||
if result == "inf" then
|
||||
return "double.MaxValue"
|
||||
elseif result == "-inf" then
|
||||
@ -74,16 +90,16 @@ end
|
||||
|
||||
function Format.Float(value: number): string
|
||||
local result = Format.Number(value)
|
||||
|
||||
|
||||
if result == "inf" then
|
||||
return "float.MaxValue"
|
||||
elseif result == "-inf" then
|
||||
return "float.MinValue"
|
||||
else
|
||||
if result:find("%.") then
|
||||
result = result .. 'f'
|
||||
result = result .. "f"
|
||||
end
|
||||
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
@ -98,7 +114,7 @@ end
|
||||
|
||||
function Format.EnumItem(item: EnumItem): string
|
||||
local enum = tostring(item.EnumType)
|
||||
return enum .. '.' .. item.Name
|
||||
return enum .. "." .. item.Name
|
||||
end
|
||||
|
||||
function Format.BrickColor(brickColor: BrickColor): string
|
||||
@ -110,22 +126,22 @@ function Format.Color3(color: Color3): string
|
||||
if color == Color3.new() then
|
||||
return "new Color3()"
|
||||
end
|
||||
|
||||
|
||||
local r = Format.Float(color.R)
|
||||
local g = Format.Float(color.G)
|
||||
local b = Format.Float(color.B)
|
||||
|
||||
local fmt = "%s(%s, %s, %s)";
|
||||
local constructor = "new Color3";
|
||||
|
||||
if string.find(r .. g .. b, 'f') then
|
||||
|
||||
local fmt = "%s(%s, %s, %s)"
|
||||
local constructor = "new Color3"
|
||||
|
||||
if string.find(r .. g .. b, "f") then
|
||||
r = Format.Int(color.R * 255)
|
||||
g = Format.Int(color.G * 255)
|
||||
b = Format.Int(color.B * 255)
|
||||
|
||||
|
||||
constructor = "Color3.FromRGB"
|
||||
end
|
||||
|
||||
|
||||
return fmt:format(constructor, r, g, b)
|
||||
end
|
||||
|
||||
@ -133,10 +149,10 @@ function Format.UDim(udim: UDim): string
|
||||
if udim == UDim.new() then
|
||||
return "new UDim()"
|
||||
end
|
||||
|
||||
|
||||
local scale = Format.Float(udim.Scale)
|
||||
local offset = Format.Int(udim.Offset)
|
||||
|
||||
|
||||
local fmt = "new UDim(%s, %s)"
|
||||
return fmt:format(scale, offset)
|
||||
end
|
||||
@ -145,62 +161,66 @@ function Format.UDim2(udim2: UDim2): string
|
||||
if udim2 == UDim2.new() then
|
||||
return "new UDim2()"
|
||||
end
|
||||
|
||||
|
||||
local xScale = Format.Float(udim2.X.Scale)
|
||||
local yScale = Format.Float(udim2.Y.Scale)
|
||||
|
||||
|
||||
local xOffset = Format.Int(udim2.X.Offset)
|
||||
local yOffset = Format.Int(udim2.Y.Offset)
|
||||
|
||||
|
||||
local fmt = "new UDim2(%s, %s, %s, %s)"
|
||||
return fmt:format(xScale, xOffset, yScale, yOffset)
|
||||
end
|
||||
|
||||
function Format.Vector2(v2: Vector2): string
|
||||
if v2 == Vector2.zero then
|
||||
return "new Vector2()"
|
||||
for const, str in Vector2_consts do
|
||||
if v2 == const then
|
||||
return str
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local x = Format.Float(v2.X)
|
||||
local y = Format.Float(v2.Y)
|
||||
|
||||
|
||||
local fmt = "new Vector2(%s, %s)"
|
||||
return fmt:format(x, y)
|
||||
end
|
||||
|
||||
function Format.Vector3(v3: Vector3): string
|
||||
if v3 == Vector3.zero then
|
||||
return "new Vector3()"
|
||||
for const, str in Vector3_consts do
|
||||
if v3 == const then
|
||||
return str
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local x = Format.Float(v3.X)
|
||||
local y = Format.Float(v3.Y)
|
||||
local z = Format.Float(v3.Z)
|
||||
|
||||
|
||||
local fmt = "new Vector3(%s, %s, %s)"
|
||||
return fmt:format(x, y, z)
|
||||
end
|
||||
|
||||
function Format.CFrame(cf: CFrame): string
|
||||
if cf == CFrame.identity then
|
||||
return "new CFrame()"
|
||||
return "CFrame.identity"
|
||||
end
|
||||
|
||||
|
||||
if cf.Rotation == CFrame.identity then
|
||||
local x = Format.Float(cf.X)
|
||||
local y = Format.Float(cf.Y)
|
||||
local z = Format.Float(cf.Z)
|
||||
|
||||
|
||||
return string.format("new CFrame(%s, %s, %s)", x, y, z)
|
||||
else
|
||||
local comp = { cf:GetComponents() }
|
||||
local matrix = ""
|
||||
|
||||
|
||||
for i = 1, 12 do
|
||||
local sep = (if i > 1 then ", " else "")
|
||||
matrix ..= sep .. Format.Float(comp[i])
|
||||
end
|
||||
|
||||
|
||||
return string.format("new CFrame(%s)", matrix)
|
||||
end
|
||||
end
|
||||
@ -208,14 +228,14 @@ end
|
||||
function Format.NumberRange(nr: NumberRange): string
|
||||
local min = Format.Float(nr.Min)
|
||||
local max = Format.Float(nr.Max)
|
||||
|
||||
|
||||
local fmt = "new NumberRange(%s)"
|
||||
local value = min
|
||||
|
||||
|
||||
if min ~= max then
|
||||
value ..= ", " .. max
|
||||
end
|
||||
|
||||
|
||||
return fmt:format(value)
|
||||
end
|
||||
|
||||
@ -225,10 +245,10 @@ function Format.Ray(ray: Ray): string
|
||||
return "new Ray()"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local origin = Format.Vector3(ray.Origin)
|
||||
local direction = Format.Vector3(ray.Direction)
|
||||
|
||||
|
||||
local fmt = "new Ray(%s, %s)"
|
||||
return fmt:format(origin, direction)
|
||||
end
|
||||
@ -236,14 +256,14 @@ end
|
||||
function Format.Rect(rect: Rect): string
|
||||
local min: any = rect.Min
|
||||
local max: any = rect.Max
|
||||
|
||||
|
||||
if min == max and min == Vector2.zero then
|
||||
return "new Rect()"
|
||||
end
|
||||
|
||||
|
||||
min = Format.Vector2(min)
|
||||
max = Format.Vector2(max)
|
||||
|
||||
|
||||
local fmt = "new Rect(%s, %s)"
|
||||
return fmt:format(min, max)
|
||||
end
|
||||
@ -251,7 +271,7 @@ end
|
||||
function Format.ColorSequence(cs: ColorSequence): string
|
||||
local csKey = cs.Keypoints[1]
|
||||
local value = tostring(csKey.Value)
|
||||
|
||||
|
||||
local fmt = "new ColorSequence(%s)"
|
||||
return fmt:format(value)
|
||||
end
|
||||
@ -259,8 +279,8 @@ end
|
||||
function Format.NumberSequence(ns: NumberSequence): string
|
||||
local nsKey = ns.Keypoints[1]
|
||||
local fmt = "new NumberSequence(%s)"
|
||||
|
||||
local value = Format.Float(nsKey.Value)
|
||||
|
||||
local value = Format.Float(nsKey.Value)
|
||||
return fmt:format(value)
|
||||
end
|
||||
|
||||
@ -268,11 +288,11 @@ function Format.Vector3int16(v3: Vector3int16): string
|
||||
if v3 == Vector3int16.new() then
|
||||
return "new Vector3int16()"
|
||||
end
|
||||
|
||||
|
||||
local x = Format.Int(v3.X)
|
||||
local y = Format.Int(v3.Y)
|
||||
local z = Format.Int(v3.Z)
|
||||
|
||||
|
||||
local fmt = "new Vector3int16(%s, %s, %s)"
|
||||
return fmt:format(x, y, z)
|
||||
end
|
||||
@ -283,12 +303,19 @@ function Format.SharedString(str: string): string
|
||||
end
|
||||
|
||||
function Format.FontFace(font: Font): string
|
||||
local legacyFont = LegacyFonts[tostring(font)]
|
||||
|
||||
if legacyFont then
|
||||
local fmt = "FontFace.FromEnum(Enums.Font.%s)"
|
||||
return fmt:format(legacyFont.Name)
|
||||
end
|
||||
|
||||
local family = string.format("%q", font.Family)
|
||||
local args = { family }
|
||||
|
||||
|
||||
local style = font.Style
|
||||
local weight = font.Weight
|
||||
|
||||
|
||||
if style ~= Enum.FontStyle.Normal then
|
||||
table.insert(args, "FontStyle." .. style.Name)
|
||||
end
|
||||
@ -296,11 +323,11 @@ function Format.FontFace(font: Font): string
|
||||
if #args > 1 or weight ~= Enum.FontWeight.Regular then
|
||||
table.insert(args, "FontWeight." .. weight.Name)
|
||||
end
|
||||
|
||||
|
||||
local fmt = "new FontFace(%s)"
|
||||
local argStr = table.concat(args, ", ")
|
||||
|
||||
|
||||
return fmt:format(argStr)
|
||||
end
|
||||
|
||||
return Format
|
||||
return Format
|
||||
|
14
Plugins/GenerateApiDump/LegacyFonts.lua
Normal file
14
Plugins/GenerateApiDump/LegacyFonts.lua
Normal file
@ -0,0 +1,14 @@
|
||||
--!strict
|
||||
|
||||
local LegacyFonts = {} :: {
|
||||
[string]: Enum.Font,
|
||||
}
|
||||
|
||||
for i, font: Enum.Font in Enum.Font:GetEnumItems() do
|
||||
if font ~= Enum.Font.Unknown then
|
||||
local fontFace = Font.fromEnum(font)
|
||||
LegacyFonts[tostring(fontFace)] = font
|
||||
end
|
||||
end
|
||||
|
||||
return table.freeze(LegacyFonts)
|
File diff suppressed because it is too large
Load Diff
@ -182,8 +182,7 @@ local function createProperty(propName, propType)
|
||||
name = data[2]
|
||||
end
|
||||
|
||||
return
|
||||
{
|
||||
return {
|
||||
Name = propName,
|
||||
|
||||
Serialization = {
|
||||
@ -302,6 +301,7 @@ local function generateClasses()
|
||||
|
||||
local enumMap = {
|
||||
Axis = true,
|
||||
Font = true,
|
||||
FontSize = true,
|
||||
FontStyle = true,
|
||||
FontWeight = true,
|
||||
@ -389,6 +389,8 @@ local function generateClasses()
|
||||
if not classTags.Service then
|
||||
return tostring(object)
|
||||
end
|
||||
|
||||
return nil
|
||||
end)
|
||||
|
||||
if not noSecurityCheck then
|
||||
@ -519,6 +521,10 @@ local function generateClasses()
|
||||
table.sort(diffNames)
|
||||
|
||||
for i, name in ipairs(diffNames) do
|
||||
if redirectProps[name] then
|
||||
continue
|
||||
end
|
||||
|
||||
local value = diffProps[name]
|
||||
local valueType = typeof(value)
|
||||
local formatFunc = getFormatFunction(valueType)
|
||||
@ -671,7 +677,7 @@ local function generateClasses()
|
||||
end)
|
||||
end
|
||||
elseif category == "Enum" then
|
||||
local enum = Enum[valueType]
|
||||
local enum = (Enum :: any)[valueType]
|
||||
local lowestId = math.huge
|
||||
local lowest
|
||||
|
||||
|
Reference in New Issue
Block a user