Skip to content

Commit c0b4314

Browse files
committed
Pass in a required function for offsets, see phetsims/number-play#19
1 parent 2ce84d6 commit c0b4314

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

js/common/model/CountingCommonModel.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import createObservableArray from '../../../../axon/js/createObservableArray.js'
1010
import Vector2 from '../../../../dot/js/Vector2.js';
1111
import ScreenView from '../../../../joist/js/ScreenView.js';
1212
import countingCommon from '../../countingCommon.js';
13-
import CountingCommonConstants from '../CountingCommonConstants.js';
1413
import PaperNumber from './PaperNumber.js';
1514

1615
class CountingCommonModel {
@@ -127,17 +126,18 @@ class CountingCommonModel {
127126
* @param {Bounds2} availableModelBounds - Constrain the position to be inside these bounds
128127
* @param {PaperNumber} paperNumber1
129128
* @param {PaperNumber} paperNumber2
130-
* @param {number} [repelDistance] // TODO: this should be generalized better, see https://github.com/phetsims/number-play/issues/19
129+
* @param {function(leftPaperNumber:PaperNumber,rightPaperNumber:PaperNumber):{left:number,right:number}} getRepelOffsets
131130
*/
132-
repelAway( availableModelBounds, paperNumber1, paperNumber2, repelDistance ) {
131+
repelAway( availableModelBounds, paperNumber1, paperNumber2, getRepelOffsets ) {
133132
// Determine which are 'left' and 'right'
134133
const isPaper1Left = paperNumber1.positionProperty.value.x < paperNumber2.positionProperty.value.x;
135134
const leftPaperNumber = isPaper1Left ? paperNumber1 : paperNumber2;
136135
const rightPaperNumber = isPaper1Left ? paperNumber2 : paperNumber1;
137136

138137
// Determine offsets
139-
const repelLeftOffset = -repelDistance || -CountingCommonConstants.MOVE_AWAY_DISTANCE[ leftPaperNumber.digitLength ];
140-
const repelRightOffset = repelDistance || CountingCommonConstants.MOVE_AWAY_DISTANCE[ rightPaperNumber.digitLength ];
138+
const repelOffsets = getRepelOffsets( leftPaperNumber, rightPaperNumber );
139+
const repelLeftOffset = repelOffsets.left;
140+
const repelRightOffset = repelOffsets.right;
141141
const leftPosition = leftPaperNumber.positionProperty.value.plusXY( repelLeftOffset, 0 );
142142
const rightPosition = rightPaperNumber.positionProperty.value.plusXY( repelRightOffset, 0 );
143143

js/common/view/CountingCommonView.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Node from '../../../../scenery/js/nodes/Node.js';
1313
import Plane from '../../../../scenery/js/nodes/Plane.js';
1414
import ClosestDragListener from '../../../../sun/js/ClosestDragListener.js';
1515
import countingCommon from '../../countingCommon.js';
16+
import CountingCommonConstants from '../CountingCommonConstants.js';
1617
import ArithmeticRules from '../model/ArithmeticRules.js';
1718
import PaperNumberNode from './PaperNumberNode.js';
1819

@@ -172,7 +173,13 @@ class CountingCommonView extends ScreenView {
172173
}
173174
else {
174175
// repel numbers - show rejection
175-
this.model.repelAway( this.availableViewBoundsProperty.value, draggedPaperNumber, droppedPaperNumber );
176+
this.model.repelAway( this.availableViewBoundsProperty.value, draggedPaperNumber, droppedPaperNumber,
177+
( leftPaperNumber, rightPaperNumber ) => {
178+
return {
179+
left: -CountingCommonConstants.MOVE_AWAY_DISTANCE[ leftPaperNumber.digitLength ],
180+
right: CountingCommonConstants.MOVE_AWAY_DISTANCE[ rightPaperNumber.digitLength ]
181+
};
182+
} );
176183
return; // A bit weird, but if repelled, no need to check for overlapping bits?
177184
}
178185
}

0 commit comments

Comments
 (0)