Skip to content

Commit 483f7f1

Browse files
committed
Particles are added to bucket via Bucket.addParticleNearestAtom() in cases where resetting bucket state isn't important. #112
1 parent 76d7d86 commit 483f7f1

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

js/common/model/Bucket.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,21 @@ class Bucket extends SphereBucket {
5454

5555
// Create the atoms for each element and add them to the bucket.
5656
for ( let i = 0; i < quantity; i++ ) {
57-
this.addParticleFirstOpen( new Atom2( element, stepEmitter ), false );
57+
this.addParticleNearestOpen( new Atom2( element, stepEmitter ), false );
5858
}
5959
}
6060

6161
// Instantly place the atom in the correct position, whether or not it is in the bucket
62-
placeAtom( atom ) {
62+
placeAtom( atom, addFirstOpen ) {
6363
if ( this.containsParticle( atom ) ) {
6464
this.removeParticle( atom, true );
6565
}
66-
this.addParticleFirstOpen( atom, false );
66+
if ( addFirstOpen ) {
67+
this.addParticleFirstOpen( atom, false );
68+
}
69+
else {
70+
this.addParticleNearestOpen( atom, false );
71+
}
6772
}
6873

6974
/**
@@ -75,7 +80,7 @@ class Bucket extends SphereBucket {
7580
this.fullState.forEach( atom => {
7681
if ( !this.particleList.contains( atom ) ) {
7782
this.particleList.push( atom );
78-
this.placeAtom( atom );
83+
this.placeAtom( atom, true );
7984
}
8085
} );
8186
}

js/common/model/Kit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class Kit {
9393
atom.reset();
9494

9595
// THEN place it so we overwrite its "bad" position and destination info
96-
this.getBucketForElement( atom.element ).placeAtom( atom );
96+
this.getBucketForElement( atom.element ).placeAtom( atom, true );
9797
} );
9898

9999
// if reset kit ignores collection boxes, add in other atoms that are equivalent to how the bucket started

js/common/view/KitNode.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class KitNode extends Node {
128128

129129
// Add the particle to the bucket atom layer and the bucket's particles.
130130
this.atomLayer.addChild( atomNode );
131-
bucket.placeAtom( atom );
131+
bucket.placeAtom( atom, false );
132132

133133
// Add a drag listener that will move the model element when the user
134134
// drags this atom.

0 commit comments

Comments
 (0)