Enhance property handling in PatchTree.build function to support EnumItem conversion for incoming raw numbers. Improved readability by restructuring property change checks and maintaining line change calculations for Source properties.

This commit is contained in:
Joe 2026-01-20 21:49:42 -06:00
parent 196cf7aed7
commit 06457bc0db

View file

@ -256,24 +256,41 @@ function PatchTree.build(patch, instanceMap, changeListHeaders)
addProp("Name", instance.Name, change.changedName)
end
for prop, incoming in change.changedProperties do
local incomingSuccess, incomingValue = decodeValue(incoming, instanceMap)
local currentSuccess, currentValue = getProperty(instance, prop)
for prop, incoming in change.changedProperties do
local incomingSuccess, incomingValue = decodeValue(incoming, instanceMap)
local currentSuccess, currentValue = getProperty(instance, prop)
-- Check if this is a Source property - count line differences
if prop == "Source" and currentSuccess and incomingSuccess then
hasSourceChange = true
totalLineChanges, whitespaceLineChanges =
WhitespaceUtil.CountLineDifferences(currentValue, incomingValue)
-- If incoming is a raw number and current is an EnumItem, convert incoming
-- to the proper EnumItem for better display (server sends Enum as raw numbers)
if
incomingSuccess
and currentSuccess
and typeof(incomingValue) == "number"
and typeof(currentValue) == "EnumItem"
then
local enumType = currentValue.EnumType
local ok, converted = pcall(function()
return enumType:FromValue(incomingValue)
end)
if ok and converted then
incomingValue = converted
end
addProp(
prop,
if currentSuccess then currentValue else "[Error]",
if incomingSuccess then incomingValue else select(2, next(incoming))
)
end
-- Check if this is a Source property - count line differences
if prop == "Source" and currentSuccess and incomingSuccess then
hasSourceChange = true
totalLineChanges, whitespaceLineChanges =
WhitespaceUtil.CountLineDifferences(currentValue, incomingValue)
end
addProp(
prop,
if currentSuccess then currentValue else "[Error]",
if incomingSuccess then incomingValue else select(2, next(incoming))
)
end
-- Count non-Source property changes
local propCount = changeIndex - (if hasSourceChange then 1 else 0)