Add support for CFrame and Font in instance attributes

This commit is contained in:
Filip Tibell 2023-07-07 09:02:02 +02:00
parent 9e67a8542f
commit 1dc0ea67e3
No known key found for this signature in database
5 changed files with 25 additions and 15 deletions

View file

@ -10,9 +10,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased ## Unreleased
### Added
- Added support for `CFrame` and `Font` types in attributes when using the `roblox` builtin.
### Fixed ### Fixed
- Fixed `roblox.serializeModel` still keeping some unique ids - Fixed `roblox.serializeModel` still keeping some unique ids.
## `0.7.3` - July 5th, 2023 ## `0.7.3` - July 5th, 2023

12
Cargo.lock generated
View file

@ -1535,7 +1535,7 @@ dependencies = [
[[package]] [[package]]
name = "rbx_binary" name = "rbx_binary"
version = "0.7.0" version = "0.7.0"
source = "git+https://github.com/rojo-rbx/rbx-dom?rev=2e78feb05e033cbca8db1d9e490f8334c096d13e#2e78feb05e033cbca8db1d9e490f8334c096d13e" source = "git+https://github.com/rojo-rbx/rbx-dom?rev=b6d255e0b5d96155f694ca224676b251059cf2de#b6d255e0b5d96155f694ca224676b251059cf2de"
dependencies = [ dependencies = [
"log", "log",
"lz4", "lz4",
@ -1566,7 +1566,7 @@ dependencies = [
[[package]] [[package]]
name = "rbx_dom_weak" name = "rbx_dom_weak"
version = "2.4.0" version = "2.4.0"
source = "git+https://github.com/rojo-rbx/rbx-dom?rev=2e78feb05e033cbca8db1d9e490f8334c096d13e#2e78feb05e033cbca8db1d9e490f8334c096d13e" source = "git+https://github.com/rojo-rbx/rbx-dom?rev=b6d255e0b5d96155f694ca224676b251059cf2de#b6d255e0b5d96155f694ca224676b251059cf2de"
dependencies = [ dependencies = [
"rbx_types", "rbx_types",
"serde", "serde",
@ -1575,7 +1575,7 @@ dependencies = [
[[package]] [[package]]
name = "rbx_reflection" name = "rbx_reflection"
version = "4.2.0" version = "4.2.0"
source = "git+https://github.com/rojo-rbx/rbx-dom?rev=2e78feb05e033cbca8db1d9e490f8334c096d13e#2e78feb05e033cbca8db1d9e490f8334c096d13e" source = "git+https://github.com/rojo-rbx/rbx-dom?rev=b6d255e0b5d96155f694ca224676b251059cf2de#b6d255e0b5d96155f694ca224676b251059cf2de"
dependencies = [ dependencies = [
"rbx_types", "rbx_types",
"serde", "serde",
@ -1585,7 +1585,7 @@ dependencies = [
[[package]] [[package]]
name = "rbx_reflection_database" name = "rbx_reflection_database"
version = "0.2.6+roblox-572" version = "0.2.6+roblox-572"
source = "git+https://github.com/rojo-rbx/rbx-dom?rev=2e78feb05e033cbca8db1d9e490f8334c096d13e#2e78feb05e033cbca8db1d9e490f8334c096d13e" source = "git+https://github.com/rojo-rbx/rbx-dom?rev=b6d255e0b5d96155f694ca224676b251059cf2de#b6d255e0b5d96155f694ca224676b251059cf2de"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"rbx_reflection", "rbx_reflection",
@ -1596,7 +1596,7 @@ dependencies = [
[[package]] [[package]]
name = "rbx_types" name = "rbx_types"
version = "1.5.0" version = "1.5.0"
source = "git+https://github.com/rojo-rbx/rbx-dom?rev=2e78feb05e033cbca8db1d9e490f8334c096d13e#2e78feb05e033cbca8db1d9e490f8334c096d13e" source = "git+https://github.com/rojo-rbx/rbx-dom?rev=b6d255e0b5d96155f694ca224676b251059cf2de#b6d255e0b5d96155f694ca224676b251059cf2de"
dependencies = [ dependencies = [
"base64 0.13.1", "base64 0.13.1",
"bitflags 1.3.2", "bitflags 1.3.2",
@ -1610,7 +1610,7 @@ dependencies = [
[[package]] [[package]]
name = "rbx_xml" name = "rbx_xml"
version = "0.13.0" version = "0.13.0"
source = "git+https://github.com/rojo-rbx/rbx-dom?rev=2e78feb05e033cbca8db1d9e490f8334c096d13e#2e78feb05e033cbca8db1d9e490f8334c096d13e" source = "git+https://github.com/rojo-rbx/rbx-dom?rev=b6d255e0b5d96155f694ca224676b251059cf2de#b6d255e0b5d96155f694ca224676b251059cf2de"
dependencies = [ dependencies = [
"base64 0.13.1", "base64 0.13.1",
"log", "log",

View file

@ -22,11 +22,11 @@ thiserror.workspace = true
glam = "0.24" glam = "0.24"
rand = "0.8" rand = "0.8"
rbx_binary = { git = "https://github.com/rojo-rbx/rbx-dom", rev = "2e78feb05e033cbca8db1d9e490f8334c096d13e" } rbx_binary = { git = "https://github.com/rojo-rbx/rbx-dom", rev = "b6d255e0b5d96155f694ca224676b251059cf2de" }
rbx_dom_weak = { git = "https://github.com/rojo-rbx/rbx-dom", rev = "2e78feb05e033cbca8db1d9e490f8334c096d13e" } rbx_dom_weak = { git = "https://github.com/rojo-rbx/rbx-dom", rev = "b6d255e0b5d96155f694ca224676b251059cf2de" }
rbx_reflection = { git = "https://github.com/rojo-rbx/rbx-dom", rev = "2e78feb05e033cbca8db1d9e490f8334c096d13e" } rbx_reflection = { git = "https://github.com/rojo-rbx/rbx-dom", rev = "b6d255e0b5d96155f694ca224676b251059cf2de" }
rbx_reflection_database = { git = "https://github.com/rojo-rbx/rbx-dom", rev = "2e78feb05e033cbca8db1d9e490f8334c096d13e" } rbx_reflection_database = { git = "https://github.com/rojo-rbx/rbx-dom", rev = "b6d255e0b5d96155f694ca224676b251059cf2de" }
rbx_xml = { git = "https://github.com/rojo-rbx/rbx-dom", rev = "2e78feb05e033cbca8db1d9e490f8334c096d13e" } rbx_xml = { git = "https://github.com/rojo-rbx/rbx-dom", rev = "b6d255e0b5d96155f694ca224676b251059cf2de" }
[dev-dependencies] [dev-dependencies]
anyhow = "1.0" anyhow = "1.0"

View file

@ -24,16 +24,16 @@ pub fn ensure_valid_attribute_name(name: impl AsRef<str>) -> LuaResult<()> {
} }
pub fn ensure_valid_attribute_value(value: &DomValue) -> LuaResult<()> { pub fn ensure_valid_attribute_value(value: &DomValue) -> LuaResult<()> {
// TODO: Uncomment supported types when they are also supported in rbx-dom serialization
let is_valid = matches!( let is_valid = matches!(
value.ty(), value.ty(),
DomType::Bool DomType::Bool
| DomType::BrickColor | DomType::BrickColor
// | DomType::CFrame | DomType::CFrame
| DomType::Color3 | DomType::Color3
| DomType::ColorSequence | DomType::ColorSequence
| DomType::Float32 | DomType::Float32
| DomType::Float64 | DomType::Float64
| DomType::Font
| DomType::Int32 | DomType::Int32
| DomType::Int64 | DomType::Int64
| DomType::NumberRange | DomType::NumberRange
@ -43,7 +43,7 @@ pub fn ensure_valid_attribute_value(value: &DomValue) -> LuaResult<()> {
| DomType::UDim | DomType::UDim
| DomType::UDim2 | DomType::UDim2
| DomType::Vector2 | DomType::Vector2
| DomType::Vector3 // | DomType::Font | DomType::Vector3
); );
if is_valid { if is_valid {
Ok(()) Ok(())

View file

@ -2,9 +2,11 @@ local fs = require("@lune/fs")
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox") :: any
local BrickColor = roblox.BrickColor local BrickColor = roblox.BrickColor
local CFrame = roblox.CFrame
local Color3 = roblox.Color3 local Color3 = roblox.Color3
local ColorSequence = roblox.ColorSequence local ColorSequence = roblox.ColorSequence
local ColorSequenceKeypoint = roblox.ColorSequenceKeypoint local ColorSequenceKeypoint = roblox.ColorSequenceKeypoint
local Font = roblox.Font
local NumberRange = roblox.NumberRange local NumberRange = roblox.NumberRange
local NumberSequence = roblox.NumberSequence local NumberSequence = roblox.NumberSequence
local NumberSequenceKeypoint = roblox.NumberSequenceKeypoint local NumberSequenceKeypoint = roblox.NumberSequenceKeypoint
@ -19,6 +21,8 @@ local modelFile = fs.readFile("tests/roblox/rbx-test-files/models/attributes/bin
local model = roblox.deserializeModel(modelFile)[1] local model = roblox.deserializeModel(modelFile)[1]
model:SetAttribute("Foo", "Bar") model:SetAttribute("Foo", "Bar")
model:SetAttribute("CFrame", CFrame.identity)
model:SetAttribute("Font", Font.new("Arial"))
local ATTRS_ACTUAL = model:GetAttributes() local ATTRS_ACTUAL = model:GetAttributes()
local ATTRS_EXPECTED: { [string]: any } = { local ATTRS_EXPECTED: { [string]: any } = {
@ -48,6 +52,8 @@ local ATTRS_EXPECTED: { [string]: any } = {
NaN = 0 / 0, NaN = 0 / 0,
-- Extras we set -- Extras we set
Foo = "Bar", Foo = "Bar",
CFrame = CFrame.identity,
Font = Font.new("Arial"),
} }
for name, value in ATTRS_EXPECTED do for name, value in ATTRS_EXPECTED do