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,7 +7,7 @@ function module.init(shared)
local mount = {};
mount.__index = mount;
function mount:unmount()
for _,this in ipairs(self.items) do
local this = self.this
local typeThis = type(this);
if typeThis == "userdata" then
this:Destroy();
@ -23,20 +23,16 @@ function module.init(shared)
-- todo for remove child on parent
end
end
end
function new.getHolder(item)
return (type(item) == "table") and (item._holder or item.holder or item.__holder) or item;
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;
function new.mount(to,this,holder)
local thisObject = this;
if type(this) == "table" then
thisO = this.__object;
thisObject = this.__object;
local parent = rawget(this,"__parent");
if type(parent) == "table" then
local parentChild = rawget(parent,"__child");
@ -50,8 +46,8 @@ function module.init(shared)
end
rawset(this,"__parent",to);
end
if thisO then
thisO.Parent = getHolder(to);
if thisObject then
thisObject.Parent = holder or getHolder(to);
end
if type(to) == "table" then
local child = rawget(to,"__child");
@ -61,8 +57,7 @@ function module.init(shared)
end
insert(child,this);
end
end
return setmetatable({to = to,this = items},mount);
return setmetatable({to = to,this = this},mount);
end
setmetatable(new,{