Skip to content

Commit

Permalink
TS conversion step, see #160
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Mar 23, 2022
1 parent 2db73fb commit febc9f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
10 changes: 5 additions & 5 deletions js/demo/sim-like-components/model/BoxOfBalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ const createRandomColor = () => {
};

class BoxOfBalls {

// an array the contains the balls that are in this box
public readonly balls: ObservableArray<Ball>;

// the bounding box
private readonly box: Shape;
private readonly balls: ObservableArray<Ball>;

constructor( width: number, height: number ) {

// @public (read-only) {Shape.rect} - the bounding box
this.box = Shape.rect( 50, 0, width, height );

// @public (read-only) {ObservableArrayDef}
this.balls = createObservableArray();
}

Expand Down
33 changes: 16 additions & 17 deletions js/demo/sim-like-components/model/SimLikeComponentsModel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2018-2020, University of Colorado Boulder

// @ts-nocheck

/**
* A model that exists only for the purposes of demonstrating sonification, particularly how view and model elements are
* used together to hook up sonification elements.
Expand All @@ -16,24 +14,26 @@ import BoxOfBalls from './BoxOfBalls.js';

class SimLikeComponentsModel {

/**
* @constructor
*/
constructor() {
// a box containing bouncing balls
public readonly boxOfBalls: BoxOfBalls;

// @public (read-only) {BoxOfBalls) - box containing bouncing balls, size empirically determined
this.boxOfBalls = new BoxOfBalls( 135, 80 );
// controls the number of balls in the box
public readonly numberOfBallsProperty: NumberProperty;

// @public {NumberProperty} - controls the number of balls in the box
this.numberOfBallsProperty = new NumberProperty( 0 );
// controls whether the balls are bouncing around in the box or still
public readonly ballsMovingProperty: BooleanProperty;

// @public {BooleanProperty} - controls whether the balls are bouncing around in the box or still
this.ballsMovingProperty = new BooleanProperty( false );
// tracks whether a reset is happening
public readonly resetInProgressProperty: BooleanProperty;

// @public {BooleanProperty} - tracks whether a reset is happening
constructor() {

this.boxOfBalls = new BoxOfBalls( 135, 80 ); // size empirically determined
this.numberOfBallsProperty = new NumberProperty( 0 );
this.ballsMovingProperty = new BooleanProperty( false );
this.resetInProgressProperty = new BooleanProperty( false );

// add or remove balls as the count changes
// Add or remove balls as the count changes.
this.numberOfBallsProperty.link( desiredNumberOfBalls => {
const numberBallsInBox = this.boxOfBalls.balls.lengthProperty.get();
if ( desiredNumberOfBalls > numberBallsInBox ) {
Expand All @@ -50,10 +50,10 @@ class SimLikeComponentsModel {
}

/**
* @param {number} dt - delta time, in seconds
* @param dt - delta time, in seconds
* @public
*/
step( dt ) {
step( dt: number ) {
if ( this.ballsMovingProperty.value ) {
this.boxOfBalls.step( dt );
}
Expand All @@ -68,7 +68,6 @@ class SimLikeComponentsModel {
this.ballsMovingProperty.reset();
this.resetInProgressProperty.value = false;
}

}

tambo.register( 'SimLikeComponentsModel', SimLikeComponentsModel );
Expand Down

0 comments on commit febc9f3

Please sign in to comment.