mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-24 22:56:02 +00:00
Start tracking property changes in plugin
This commit is contained in:
@@ -9,10 +9,12 @@ local Log = require(script.Parent.Parent.Log)
|
|||||||
local InstanceMap = {}
|
local InstanceMap = {}
|
||||||
InstanceMap.__index = InstanceMap
|
InstanceMap.__index = InstanceMap
|
||||||
|
|
||||||
function InstanceMap.new()
|
function InstanceMap.new(onInstanceChanged)
|
||||||
local self = {
|
local self = {
|
||||||
fromIds = {},
|
fromIds = {},
|
||||||
fromInstances = {},
|
fromInstances = {},
|
||||||
|
instancesToSignal = {},
|
||||||
|
onInstanceChanged = onInstanceChanged,
|
||||||
}
|
}
|
||||||
|
|
||||||
return setmetatable(self, InstanceMap)
|
return setmetatable(self, InstanceMap)
|
||||||
@@ -31,12 +33,14 @@ end
|
|||||||
function InstanceMap:insert(id, instance)
|
function InstanceMap:insert(id, instance)
|
||||||
self.fromIds[id] = instance
|
self.fromIds[id] = instance
|
||||||
self.fromInstances[instance] = id
|
self.fromInstances[instance] = id
|
||||||
|
self:__connectSignals(instance)
|
||||||
end
|
end
|
||||||
|
|
||||||
function InstanceMap:removeId(id)
|
function InstanceMap:removeId(id)
|
||||||
local instance = self.fromIds[id]
|
local instance = self.fromIds[id]
|
||||||
|
|
||||||
if instance ~= nil then
|
if instance ~= nil then
|
||||||
|
self:__disconnectSignals(instance)
|
||||||
self.fromIds[id] = nil
|
self.fromIds[id] = nil
|
||||||
self.fromInstances[instance] = nil
|
self.fromInstances[instance] = nil
|
||||||
else
|
else
|
||||||
@@ -46,6 +50,7 @@ end
|
|||||||
|
|
||||||
function InstanceMap:removeInstance(instance)
|
function InstanceMap:removeInstance(instance)
|
||||||
local id = self.fromInstances[instance]
|
local id = self.fromInstances[instance]
|
||||||
|
self:__disconnectSignals(instance)
|
||||||
|
|
||||||
if id ~= nil then
|
if id ~= nil then
|
||||||
self.fromInstances[instance] = nil
|
self.fromInstances[instance] = nil
|
||||||
@@ -88,4 +93,23 @@ function InstanceMap:destroyId(id)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function InstanceMap:__connectSignals(instance)
|
||||||
|
-- TODO: Connect to different event for ValueBase objects?
|
||||||
|
|
||||||
|
self.instancesToSignal[instance] = instance.Changed:Connect(function(propertyName)
|
||||||
|
Log.trace("%s.%s changed", instance:GetFullName(), propertyName)
|
||||||
|
|
||||||
|
if self.onInstanceChanged ~= nil then
|
||||||
|
self.onInstanceChanged(instance, propertyName)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function InstanceMap:__disconnectSignals(instance)
|
||||||
|
if self.instancesToSignal[instance] ~= nil then
|
||||||
|
self.instancesToSignal[instance]:Disconnect()
|
||||||
|
self.instancesToSignal[instance] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return InstanceMap
|
return InstanceMap
|
||||||
Reference in New Issue
Block a user