fixed disconnect!

can remove all modifiers in pivot
This commit is contained in:
SethTrowbridge 2021-05-15 10:47:22 -04:00
parent c30c20e8b2
commit 23c7c60b5b

View File

@ -40,24 +40,27 @@ var N =
{ {
let remove = (inArray, inMatch) => inArray.findIndex( (inMember, inIndex, inArray) => (inMember === inMatch) ? inArray.splice(inIndex, 1) : false ); let remove = (inArray, inMatch) => inArray.findIndex( (inMember, inIndex, inArray) => (inMember === inMatch) ? inArray.splice(inIndex, 1) : false );
// if no specific child was passed
if(inNodeMinor === null) if(inNodeMinor === null)
{ {
// get all the children
let check = N.Step(inNodeMajor, inKey); let check = N.Step(inNodeMajor, inKey);
if(!check){ return; } if(!check){ return; }
check.forEach( inLoopNode =>
{
if(inLoopNode.Link[inKey].Get.length == 1)
{
// we're about to delete the last get reference on a minor node, just purge the key entirely
delete inLoopNode.Link[inKey];
}
else
{
remove( inLoopNode.Link[inKey].Get, inNodeMajor);
}
// go down to each child ...
check.forEach( inNodeMinor =>
{
let connections = inNodeMinor.Link[inKey];
remove( connections.Get, inNodeMajor); // ... and remove any reference to the parent
// if after the remove operation, this child has no connections on inKey, scrub the key
if(!connections.Set.length && !connections.Get.length)
{
delete inNodeMinor.Link[inKey];
}
}); });
// we just wiped out all set, if get is empty we can purge the key from major
// we just wiped out all outgoing connections to the parent, if incoming connections are empty too we can purge the key there as well
if(inNodeMajor.Link[inKey].Get.length == 0) if(inNodeMajor.Link[inKey].Get.length == 0)
{ {
delete inNodeMajor.Link[inKey]; delete inNodeMajor.Link[inKey];
@ -65,20 +68,27 @@ var N =
return; return;
} }
// if no specific parent was passed
if(inNodeMajor === null) if(inNodeMajor === null)
{ {
inNodeMinor.Link[inKey].Get.forEach( inLoopNode => // get all the parents
let check = N.Step(inNodeMinor, inKey, false);
if(!check){ return; }
// go up to each parent ...
check.forEach( inNodeMajor =>
{ {
if(inLoopNode.Link[inKey].Set.length == 1) let connections = inNodeMajor.Link[inKey];
remove( connections.Set, inNodeMinor); // ... and remove any reference to the child
// if after the remove operation, this parent has no connections on inKey, scrub the key
if( !connections.Set.length && !connections.Get.length )
{ {
delete inLoopNode.Link[inKey]; delete inNodeMajor.Link[inKey];
}
else
{
remove( inLoopNode.Link[inKey].Set, inNodeMinor);
} }
}); });
// we just wiped out all get, if set is empty we can purge the key from minor
// we just wiped out all incoming connections to the child, if outgoing connections are empty too we can purge the key there as well
if(inNodeMinor.Link[inKey].Set.length == 0) if(inNodeMinor.Link[inKey].Set.length == 0)
{ {
delete inNodeMinor.Link[inKey]; delete inNodeMinor.Link[inKey];
@ -86,7 +96,7 @@ var N =
return; return;
} }
// if a specific parent and child were passed
if(inNodeMajor.Link[inKey].Set.length == 1) if(inNodeMajor.Link[inKey].Set.length == 1)
{ {
delete inNodeMajor.Link[inKey]; delete inNodeMajor.Link[inKey];
@ -110,7 +120,7 @@ var N =
let connectionGroup = inNode.Link[inKey]; let connectionGroup = inNode.Link[inKey];
if(!connectionGroup) if(!connectionGroup)
{ {
if(inForceCreate) if(inForceCreate === true)
{ {
inNode.Link[inKey] = connectionGroup = {Get:[], Set:[]}; inNode.Link[inKey] = connectionGroup = {Get:[], Set:[]};
} }
@ -262,24 +272,24 @@ var Pivot =
{ {
N.ID.Walk++; N.ID.Walk++;
let pivotRoot = N.Create({Leaves:Pivot.Leaves}); let pivotRoot = N.Create({Label:"Pivot Root", Leaves:Pivot.Leaves});
N.Connect(Pivot.Root, pivotRoot, "Pivot"); N.Connect(Pivot.Root, pivotRoot, "Pivot");
return Pivot.Pivot(pivotRoot, inPivotIndicies, inSumIndicies); return Pivot.Pivot(pivotRoot, inPivotIndicies, inSumIndicies);
}, },
Delete(inRoot) Delete(inRoot)
{ {
N.ID.Walk++; let check = N.Step(inRoot, "Modifier");
if(check)
let scan = n =>
{ {
while(check.length>0)
}; {
Pivot.Unmodify(check[0]);
N.Walk(scan, inRoot, "Hierarchy") }
}
}, },
Modify(inNode) Modify(inNode)
{ {
let modified = N.Create({}); let modified = N.Create({Label:"Modifier"});
N.ID.Walk++; N.ID.Walk++;
if(N.Step(inNode, "Hierarchy").length) if(N.Step(inNode, "Hierarchy").length)
{ {
@ -290,7 +300,6 @@ var Pivot =
} }
else else
{ {
N.Connect(Pivot.Root, modified, "Modifier"); N.Connect(Pivot.Root, modified, "Modifier");
} }
@ -313,15 +322,13 @@ var Pivot =
return modified; return modified;
}, },
Unmodify(inNode) Unmodify(inModifier)
{ {
let modifier = N.Step(inNode, "ModifyAt", false)[0]; N.Disconnect(inModifier, null, "ModifyUp");
N.Disconnect(inModifier, null, "ModifyDown");
N.Disconnect(modifier, null, "ModifyUp"); N.Disconnect(inModifier, null, "ModifyOut");
N.Disconnect(modifier, null, "ModifyDown"); N.Disconnect(inModifier, null, "ModifyAt");
N.Disconnect(modifier, null, "ModifyOut"); N.Disconnect(null, inModifier, "Modifier");
N.Disconnect(modifier, null, "ModifyAt");
N.Disconnect(null, modifier, "Modifier");
} }
}; };
</script> </script>
@ -412,7 +419,7 @@ let ElNode = ({node, depth}) =>
className:"Icon Modify remove", className:"Icon Modify remove",
onClick:e=> onClick:e=>
{ {
Pivot.Unmodify(node); Pivot.Unmodify(N.Step(node, "ModifyAt", false)[0]);
Render(); Render();
} }
}, "Unmodify"); }, "Unmodify");
@ -433,6 +440,7 @@ let ElNode = ({node, depth}) =>
let ElPivot = ({pivot}) => let ElPivot = ({pivot}) =>
{ {
return h("div", {style:{display:"inline-block", width:"500px"}}, [ return h("div", {style:{display:"inline-block", width:"500px"}}, [
h("button", {onClick:e=>{Pivot.Delete(pivot);Render();}}, "delete?"),
h(ElModifiers, {node:pivot}), h(ElModifiers, {node:pivot}),
h(ElNode, {node:pivot, depth:0}) h(ElNode, {node:pivot, depth:0})
]); ]);
@ -445,7 +453,7 @@ let ElModifiers = ({node}) =>
h("strong", null, "modifiers"), h("strong", null, "modifiers"),
...modifiers.map( m => h("span", {onClick:e=> ...modifiers.map( m => h("span", {onClick:e=>
{ {
Pivot.Unmodify(N.Step(m, "ModifyAt")[0]); Pivot.Unmodify(m);
Render(); Render();
} }
}, "modifier")) }, "modifier"))