mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-21 05:06:29 +00:00
Plugin: Port reconciler to use rbx_dom_lua
This commit is contained in:
@@ -1,33 +1,17 @@
|
||||
local RbxDom = require(script:FindFirstAncestor("Rojo").RbxDom)
|
||||
|
||||
local Logging = require(script.Parent.Logging)
|
||||
|
||||
--[[
|
||||
Attempts to set a property on the given instance.
|
||||
|
||||
This method deals in terms of what Rojo calls 'canonical properties', which
|
||||
don't necessarily exist either in serialization or in Lua-reflected APIs,
|
||||
but may be present in the API dump.
|
||||
|
||||
Ideally, canonical properties map 1:1 with properties we can assign, but in
|
||||
some cases like LocalizationTable contents and CollectionService tags, we
|
||||
have to read/write properties a little differently.
|
||||
]]
|
||||
local function setCanonicalProperty(instance, key, value)
|
||||
-- The 'Contents' property of LocalizationTable isn't directly exposed, but
|
||||
-- has corresponding (deprecated) getters and setters.
|
||||
if instance.ClassName == "LocalizationTable" and key == "Contents" then
|
||||
instance:SetContents(value)
|
||||
return
|
||||
end
|
||||
|
||||
-- Temporary workaround for fixing issue #141 in this specific case.
|
||||
if instance.ClassName == "Lighting" and key == "Technology" then
|
||||
return
|
||||
if not RbxDom.CanonicalProperty.isScriptable(instance.ClassName, key) then
|
||||
return false
|
||||
end
|
||||
|
||||
-- If we don't have permissions to access this value at all, we can skip it.
|
||||
local readSuccess, existingValue = pcall(function()
|
||||
return instance[key]
|
||||
end)
|
||||
local readSuccess, existingValue = RbxDom.CanonicalProperty.read(instance, key)
|
||||
|
||||
if not readSuccess then
|
||||
-- An error will be thrown if there was a permission issue or if the
|
||||
@@ -35,17 +19,13 @@ local function setCanonicalProperty(instance, key, value)
|
||||
-- because it's probably their fault.
|
||||
if existingValue:find("lacking permission") then
|
||||
Logging.trace("Permission error reading property %s on class %s", tostring(key), instance.ClassName)
|
||||
return
|
||||
return false
|
||||
else
|
||||
error(("Invalid property %s on class %s: %s"):format(tostring(key), instance.ClassName, existingValue), 2)
|
||||
end
|
||||
end
|
||||
|
||||
local writeSuccess, err = pcall(function()
|
||||
if existingValue ~= value then
|
||||
instance[key] = value
|
||||
end
|
||||
end)
|
||||
local writeSuccess, err = RbxDom.CanonicalProperty.write(instance, key, value)
|
||||
|
||||
if not writeSuccess then
|
||||
error(("Cannot set property %s on class %s: %s"):format(tostring(key), instance.ClassName, err), 2)
|
||||
|
||||
Reference in New Issue
Block a user