Refactor PatchTree and applyPatch for improved readability and logic consistency

- Restructured property change checks in PatchTree.build to enhance clarity and maintainability.
- Updated applyPatch to improve the handling of instance retrieval logic for removed instances.
- Simplified the findDuplicateNames function in diff.lua for better readability and consistency in handling duplicate names.
This commit is contained in:
Joe 2026-01-20 23:05:16 -06:00
parent d21331cb65
commit cd05690d8a
3 changed files with 38 additions and 36 deletions

View file

@ -29,7 +29,9 @@ local function applyPatch(instanceMap, patch)
for _, removedIdOrInstance in ipairs(patch.removed) do
-- Skip auto-created instances that shouldn't be synced
local instance = if Types.RbxId(removedIdOrInstance) then instanceMap.fromIds[removedIdOrInstance] else removedIdOrInstance
local instance = if Types.RbxId(removedIdOrInstance)
then instanceMap.fromIds[removedIdOrInstance]
else removedIdOrInstance
if instance and Config.ignoredClassNames[instance.ClassName] then
continue
end

View file

@ -17,7 +17,10 @@ local function isEmpty(table)
end
-- Finds duplicate names among children and returns a set of names that are duplicated
local function findDuplicateNames(children: { Instance } | { string }, virtualInstances: { [string]: any }?): { [string]: boolean }
local function findDuplicateNames(
children: { Instance } | { string },
virtualInstances: { [string]: any }?
): { [string]: boolean }
local nameCounts: { [string]: number } = {}
local duplicates: { [string]: boolean } = {}
@ -411,10 +414,7 @@ local function diff(instanceMap, virtualInstances, rootId)
-- Log count of skipped duplicates
if skippedDuplicateCount > 0 then
Log.warn(
"Skipped {} location(s) with duplicate-named siblings (cannot reliably sync)",
skippedDuplicateCount
)
Log.warn("Skipped {} location(s) with duplicate-named siblings (cannot reliably sync)", skippedDuplicateCount)
end
if not diffSuccess then