bug fix for self parenting

This commit is contained in:
세젤귀 고양이들 2022-01-01 20:49:53 +09:00
parent 9189cbcd92
commit a6bc37dbc7
2 changed files with 46 additions and 50 deletions

View file

@ -14,15 +14,16 @@ local module = {};
function module.init(shared)
local new = {};
local InstanceNew = Instance.new;
local event = shared.event; ---@module src.event
local event = shared.event; ---@module "src.event"
local bind = event.bind;
local store = shared.store; ---@module src.store
local store = shared.store; ---@module "src.store"
local addObject = store.addObject;
local storeNew = store.new;
local mount = shared.mount; ---@module src.mount
local mount = shared.mount; ---@module "src.mount"
local getHolder = mount.getHolder;
local advancedTween = shared.advancedTween; ---@module src.libs.AdvancedTween
local round = shared.round; ---@module src.libs.round
local mountf = mount.mount;
local advancedTween = shared.advancedTween; ---@module "src.libs.AdvancedTween"
local round = shared.round; ---@module "src.libs.round"
local function setProperty(item,index,value,ClassName)
ClassName = ClassName or item.ClassName;
@ -69,7 +70,7 @@ function module.init(shared)
item = func(parsed);
local holder = getHolder(item);
for _,v in ipairs(childs) do
mount(item,v,holder);
mountf(item,v,holder);
end
return item;
end
@ -142,7 +143,7 @@ function module.init(shared)
setProperty(item,index,value,ClassName);
elseif indexType == "number" then -- object
-- child object
mount(item,((iprop == 1) and value or value:Clone()),holder);
mountf(item,((iprop == 1) and value or value:Clone()),holder);
end
end
end
@ -219,7 +220,7 @@ function module.init(shared)
rawset(self,"__holder",object);
if parent then
rawset(self,"__parent",parent);
mount(self,parent)
mountf(self,parent)
end
-- prevent gc
((type(object) == "table" and object.__object) or object):GetPropertyChangedSignal "ClassName":Connect(function()

View file

@ -7,21 +7,20 @@ function module.init(shared)
local mount = {};
mount.__index = mount;
function mount:unmount()
for _,this in ipairs(self.items) do
local typeThis = type(this);
if typeThis == "userdata" then
this:Destroy();
elseif typeThis == "table" then
pcall(function()
this.Parent = nil;
end);
local destroyThis = this.Destroy;
if destroyThis then
pcall(destroyThis,this);
end
--if sef.to when
-- todo for remove child on parent
local this = self.this
local typeThis = type(this);
if typeThis == "userdata" then
this:Destroy();
elseif typeThis == "table" then
pcall(function()
this.Parent = nil;
end);
local destroyThis = this.Destroy;
if destroyThis then
pcall(destroyThis,this);
end
--if sef.to when
-- todo for remove child on parent
end
end
@ -30,39 +29,35 @@ function module.init(shared)
end
local getHolder = new.getHolder
-- we should add plugin support
local pack = table.pack;
function new.mount(to,...)
local items = pack(...);
for _,this in ipairs(items) do
local thisO = this;
if type(this) == "table" then
thisO = this.__object;
local parent = rawget(this,"__parent");
if type(parent) == "table" then
local parentChild = rawget(parent,"__child");
if parentChild then
for i,v in pairs(parentChild) do
if v == this then
parentChild[i] = nil;
end
function new.mount(to,this,holder)
local thisObject = this;
if type(this) == "table" then
thisObject = this.__object;
local parent = rawget(this,"__parent");
if type(parent) == "table" then
local parentChild = rawget(parent,"__child");
if parentChild then
for i,v in pairs(parentChild) do
if v == this then
parentChild[i] = nil;
end
end
end
rawset(this,"__parent",to);
end
if thisO then
thisO.Parent = getHolder(to);
end
if type(to) == "table" then
local child = rawget(to,"__child");
if not child then
child = {};
rawset(to,"__child",child);
end
insert(child,this);
end
rawset(this,"__parent",to);
end
return setmetatable({to = to,this = items},mount);
if thisObject then
thisObject.Parent = holder or getHolder(to);
end
if type(to) == "table" then
local child = rawget(to,"__child");
if not child then
child = {};
rawset(to,"__child",child);
end
insert(child,this);
end
return setmetatable({to = to,this = this},mount);
end
setmetatable(new,{