Enhance property encoding and class descriptor retrieval in rbx_dom_lua

- Introduced a new function, `findClassDescriptor`, to retrieve class properties and metadata, including inherited properties, from the database.
- Updated `encodeInstance` to include encoding for Tags alongside Attributes, ensuring comprehensive property serialization.
- Improved property filtering logic to skip non-serializable properties and those matching default values, aligning with syncback behavior.
- Enhanced comments for clarity on property handling and encoding processes.
This commit is contained in:
Joe 2026-01-30 13:18:20 -06:00
parent c0d089f0aa
commit dccd3a691a
6 changed files with 188 additions and 62 deletions

View file

@ -2,6 +2,51 @@ local database = require(script.database)
local Error = require(script.Error)
local PropertyDescriptor = require(script.PropertyDescriptor)
-- Returns a class descriptor with all property names and metadata (including inherited ones)
-- Returns nil if the class doesn't exist in the database
-- The properties table maps property names to metadata (scriptability, serialization status)
-- To get a full PropertyDescriptor for encoding, use findCanonicalPropertyDescriptor
local function findClassDescriptor(className)
local classData = database.Classes[className]
if classData == nil then
return nil
end
-- Build a table of all properties, walking up the inheritance chain
local allProperties = {}
local currentClassName = className
repeat
local currentClass = database.Classes[currentClassName]
if currentClass == nil then
break
end
-- Add properties from this class (don't override if already set by subclass)
for propertyName, propertyData in pairs(currentClass.Properties) do
if allProperties[propertyName] == nil then
-- Only include canonical properties (not aliases)
if propertyData.Kind and propertyData.Kind.Canonical then
allProperties[propertyName] = {
name = propertyName,
scriptability = propertyData.Scriptability,
dataType = propertyData.DataType,
serialization = propertyData.Kind.Canonical.Serialization,
}
end
end
end
currentClassName = currentClass.Superclass
until currentClassName == nil
return {
name = classData.Name,
superclass = classData.Superclass,
properties = allProperties,
}
end
local function findCanonicalPropertyDescriptor(className, propertyName)
local currentClassName = className
@ -65,6 +110,7 @@ return {
readProperty = readProperty,
writeProperty = writeProperty,
findCanonicalPropertyDescriptor = findCanonicalPropertyDescriptor,
findClassDescriptor = findClassDescriptor,
Error = Error,
EncodedValue = require(script.EncodedValue),
}