Helper scripts for making font & physical properties from enums

This commit is contained in:
Filip Tibell 2023-03-17 10:44:21 +01:00
parent 6d76df7524
commit e57abbe5d9
No known key found for this signature in database
4 changed files with 55 additions and 2 deletions

2
.gitignore vendored
View file

@ -22,3 +22,5 @@ luneTypes.d.luau
# Files generated by runtime or build scripts # Files generated by runtime or build scripts
packages/lib-roblox/scripts/brick_color.rs packages/lib-roblox/scripts/brick_color.rs
packages/lib-roblox/scripts/font_enum_map.rs
packages/lib-roblox/scripts/physical_properties_enum_map.rs

View file

@ -5,8 +5,11 @@
"luau-lsp.types.definitionFiles": ["luneTypes.d.luau"], "luau-lsp.types.definitionFiles": ["luneTypes.d.luau"],
"luau-lsp.types.documentationFiles": ["luneDocs.json"], "luau-lsp.types.documentationFiles": ["luneDocs.json"],
"luau-lsp.require.mode": "relativeToFile", "luau-lsp.require.mode": "relativeToFile",
// Luau - ignore type defs file in docs dir // Luau - ignore type defs file in docs dir and dev scripts we use
"luau-lsp.ignoreGlobs": ["docs/*.d.luau"], "luau-lsp.ignoreGlobs": [
"docs/*.d.luau",
"packages/lib-roblox/scripts/*.luau"
],
// Rust // Rust
"rust-analyzer.check.command": "clippy", "rust-analyzer.check.command": "clippy",
// Formatting // Formatting

View file

@ -0,0 +1,22 @@
-- NOTE: This must be ran in Roblox Studio to get up-to-date font values
local contents = ""
contents ..= "\nconst FONT_ENUM_MAP: &[(&str, Option<(&str, RbxFontWeight, RbxFontStyle)>)] = &[\n"
for _, enum in Enum.Font:GetEnumItems() do
if enum == Enum.Font.Unknown then
contents ..= ' ("Unknown", None),\n'
else
local font = Font.fromEnum(enum)
contents ..= string.format(
' ("%s", Some(("%s", RbxFontWeight::%s, RbxFontStyle::%s))),\n',
enum.Name,
font.Family,
font.Weight.Name,
font.Style.Name
)
end
end
contents ..= "];\n"
print(contents)

View file

@ -0,0 +1,26 @@
-- NOTE: This must be ran in Roblox Studio to get up-to-date enum values
local contents = ""
local longestNameLen = 0
for _, enum in Enum.Material:GetEnumItems() do
longestNameLen = math.max(longestNameLen, #enum.Name)
end
contents ..= "\n#[rustfmt::skip]\nconst MATERIAL_ENUM_MAP: &[(&str, f32, f32, f32, f32, f32)] = &[\n"
for _, enum in Enum.Material:GetEnumItems() do
local props = PhysicalProperties.new(enum)
contents ..= string.format(
' ("%s",%s %.2f, %.2f, %.2f, %.2f, %.2f),\n',
enum.Name,
string.rep(" ", longestNameLen - #enum.Name),
props.Density,
props.Friction,
props.Elasticity,
props.FrictionWeight,
props.ElasticityWeight
)
end
contents ..= "];\n"
print(contents)