Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial commit #1

Merged
merged 13 commits into from
Jun 15, 2016
Merged

initial commit #1

merged 13 commits into from
Jun 15, 2016

Conversation

kintel
Copy link
Member

@kintel kintel commented Nov 22, 2015

No description provided.


![codecov.io](http://codecov.io/github/anyWareSculpture/shared-views/branch.svg?branch=master)

## Usage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should update this section to talk specifically about shared views


*/

const _ = require('lodash');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been avoiding loading big libraries like lodash into our code for fear of bloating our built code. For the most part, I've found it unnecessary. See my comments below on the _. lines.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expected lodash entry points to be picked out by browserify, including only the actually used code paths in to our build code. Is that not the case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think browserify does that? The more important concern though is that it really isn't necessary in this case. The _.range usage isn't very extensible and we already provide properties for that.

mole: {
success: 'sounds/Game_01/G01_Success_01.wav',
failure: 'sounds/Game_01/G01_Negative_01.wav',
panels: [0,1,2].map(stripId => _.range(10).map(panelId => `sounds/Game_01/G01_LED_${("0"+(stripId*10+panelId+1)).slice(-2)}.wav`))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the LightArray#stripIds property and the panelIds property on each strip instead of an array and _.range(). See panel-view.js for an example of usage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the code to get these file names is repeated, can you put it in some method and move the directory path to config?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: when moving this into the config you're not going to have access to the store. You should adopt a similar approach to what I've done in default-config.js in game-logic. Take a look at the CONTROL_MAPPINGS definition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should they be LightArray#stripIds properties? These are not tracked data, merely a configuration which are only used internally in the audio view. Not sure why arrays should be avoided in this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think of those properties like metadata on the tracked data. That array gives you access to all of the stripIds created. It doesn't need to be tracked because it doesn't change. It's distinct from a constant though because it is local to each light array and doesn't apply to all light arrays.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean. Could you write a code snippet explaining how you would populate such a data structure?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Since this should probably eventually end up in config anyway, I would populate it like this:

// in config.js constructor:
this.SOUNDS = {
  //...
  MOLE: {
    //...
    PANEL_ACTIVE: {
      // stripId
      '0': {
          // Note: SOUNDS_PATH.MOLE_GAME = "sounds/Game_01"
          // panelId
          '0': join(this.SOUNDS_PATH.MOLE_GAME, 'G01_LED_001.wav'),
          '1': join(this.SOUNDS_PATH.MOLE_GAME, 'G01_LED_002.wav'),
          // Example revised sound
          '2': join(this.SOUNDS_PATH.MOLE_GAME, 'G01_LED_003_rev.wav'),
          '3': join(this.SOUNDS_PATH.MOLE_GAME, 'G01_LED_004.wav'),
      }
    }
  }
  //...
}
// Note that this is just an example so you may come up with better names than I just did. :) 

There's a number of reasons I'd write the code like this and it has several benefits.

All of these numbers that represent the strips and panels, though they look sequential, don't have to be. They're IDs with no defined order. We may have to change panel ID 2 to 7 one day because something went wrong. We shouldn't work on the assumption that they are sequential in our code.

Another reason I'd do it like this is because while this may seem to be unnecessarily repetitive, it gives us a lot of freedom to configure the sounds individually however we like. Someone does the work to write this out once and we can adjust every sound whenever we want. In the code I have above, we're not limited by the seemingly sequential nature of the IDs that I was describing before. We can also have whatever filenames we want.

Imagine a scenario where we had two versions of a single panel's sound. What if we need to test that revision and want to swap a "_rev" prefix into the filename somewhere. It's worth it to have all of this laid out like this in the configuration class.

You can abstract out the name building as much as you'd like, even more than I did if it makes it easier. Just make sure that it's easy to configure and change.

This way of doing it also makes it easy to reason about and access from the code. You can simply use [stripId][panelId] on the relevant part of your configuration object. See how CONTROL_MAPPINGS is used in the disk view code.

panels: [0,1,2].map(stripId => _.range(10).map(panelId => `sounds/Game_03/G03_LED_${("0"+(stripId*10+panelId+1)).slice(-2)}.wav`)),
success: 'sounds/Game_03/G03_Success_01.wav',
failure: 'sounds/Game_03/G03_Negative_01.wav',
show: 'sounds/Game_03/G03_Light_Show_01.wav'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with all of these paths. Could you move these to config? Also, if you need to do this, be careful when concatenating paths because we could run into weird bugs with / being forgotten and whatnot.

}

if (this.store.isPlayingMoleGame) {
const lightArray = this.lightArray;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than repeating these loops here, could you put the loops in the outermost context and then put the if statements inside? That way you only have to traverse the lightArray once.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider the event handlers temporary code for now. We need changes to game logic to be able to do the right thing. There's a separate card on trello for that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By event handlers do you mean change handlers? (Sorry I'm not sure what code you're referring to.)
If you're referring to what I think you are referring to:
Even if it is temporary code, moving the conditions inside the loops will dramatically decrease the amount of code you have in that handler and make everyone's lives easier for when this temporary code becomes "real" code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove the temporary code for now, leaving us with infrastructure.

}

_handleChanges(changes) {
if (this._animating) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't defined in the constructor. Please make sure you do that.

@kintel kintel mentioned this pull request Nov 24, 2015
@kintel kintel merged commit 6d14ffc into master Jun 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants