phetsims / build-an-atom

"Build an Atom" is an educational simulation in HTML5, by PhET Interactive Simulations.
http://phet.colorado.edu/en/simulation/build-an-atom
GNU General Public License v3.0
11 stars 10 forks source link

Stars not saved #179

Open samreid opened 6 years ago

samreid commented 6 years ago

Stars not saved

image

See #156

samreid commented 6 years ago

I noticed this code in BAAGameModel.js

    this.bestScores = []; // Properties that track progress on each game level.
    this.scores = []; // Properties that track score at each game level
    this.bestTimeVisible = []; // Properties that track whether to show best time at each game level
    self.bestTimes = []; // Best times at each level.
    _.times( ShredConstants.LEVEL_NAMES.length, function() {
      self.bestScores.push( new Property( 0 ) );
      self.scores.push( new Property( 0 ) );
      self.bestTimes.push( new Property( null ) );
      self.bestTimeVisible.push( new Property( false ) );
    } );

It seems it may be better to reorganize this around the idea of each level. For instance, something like:

    this.levels =[];
    _.times( ShredConstants.LEVEL_NAMES.length, function() {
      this.levels.push(new Level()); // Level keeps track of its own score, bestTime, etc.
    } );
samreid commented 6 years ago

Next problem: the names of the levels are not amenable to tandemizing (they use hyphens instead of camel case):

LEVEL_NAMES: [ 'periodic-table-game', 'mass-and-charge-game', 'symbol-game', 'advanced-symbol-game' ],
samreid commented 6 years ago

I tried tandemizing the Property values in the _.times but it did not solve anything.

samreid commented 6 years ago

This code in BAAGameScreenView creates a snapshot of Property values and does not dynamically update, it may explain the disconnect (at least for LevelCompleted):

          // Add the dialog node that indicates that the level has been completed.
          rootNode.addChild( new LevelCompletedNode(
            gameModel.levelProperty.get(),
            gameModel.scoreProperty.get(),
            BAAGameModel.MAX_POINTS_PER_GAME_LEVEL,
            BAAGameModel.CHALLENGES_PER_LEVEL,
            gameModel.timerEnabledProperty.get(),
            gameModel.elapsedTimeProperty.get(),
            gameModel.bestTimes[ gameModel.levelProperty.get() ].value,
            gameModel.newBestTime,
            function() { gameModel.stateProperty.set( BAAGameState.CHOOSING_LEVEL ); }, {
              centerX: self.layoutBounds.width / 2,
              centerY: self.layoutBounds.height / 2,
              levelVisible: false,
              maxWidth: self.layoutBounds.width,
              tandem: tandem.createTandem( 'levelCompletedNode' )
            }
          ) );
        }
samreid commented 6 years ago

It's been great to have @jbphet's help on this, I'll put on hold until we resume collaboration.