Skip to content

Commit

Permalink
Fix block ordering issue, see #216
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisklus committed Feb 17, 2020
1 parent d86f2d8 commit c6e8124
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions js/intro/view/EFACIntroScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,40 +604,35 @@ define( require => {

// updates the Z-order of the blocks when their position changes
const blockChangeListener = position => {
let currentBlock = null;
let currentBlockNode = null;
const blocks = [ ...model.blocks.array ];

model.blocks.forEach( block => {
if ( block.positionProperty.value === position ) {
currentBlock = block;
blocks.sort( ( a, b ) => {
// a block that's completely to the right of another block should always be in front
if ( a.bounds.minX >= b.bounds.maxX ) {
return 1;
}
} );
blockNodes.forEach( blockNode => {
if ( blockNode.block === currentBlock ) {
currentBlockNode = blockNode;
else if ( a.bounds.maxX <= b.bounds.minX ) {
return -1;
}
} );

model.blocks.forEach( otherBlock => {
if ( otherBlock === currentBlock ) {
return;
// a block that's above another should always be in front if they overlap in the x direction
if ( a.bounds.minY > b.bounds.minY ) {
return 1;
}
else if ( b.bounds.minY > a.bounds.minY ) {
return -1;
}
else {
return 0;
}
} );

let otherBlockNode = null;
blocks.forEach( block => {
blockNodes.forEach( blockNode => {
if ( blockNode.block === otherBlock ) {
otherBlockNode = blockNode;
if ( blockNode.block === block ) {
blockNode.moveToFront();
}
} );

if ( currentBlock.getBounds().minX >= otherBlock.getBounds().maxX ||
currentBlock.getBounds().minY >= otherBlock.getBounds().maxY ) {
currentBlockNode.moveToFront();
}
else if ( otherBlock.getBounds().minX >= currentBlock.getBounds().maxX ||
otherBlock.getBounds().minY >= currentBlock.getBounds().maxY ) {
otherBlockNode.moveToFront();
}
} )
} );
};

Expand Down

0 comments on commit c6e8124

Please sign in to comment.