-
Notifications
You must be signed in to change notification settings - Fork 126
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
Add web soundtrack #236
Add web soundtrack #236
Conversation
@devmattrick thanks for your contribution! Looks great so far, will review it later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devmattrick, great work!
I would like to merge the first commit with minor renaming. The next commits need little more work.
Can you remove the next commit from this PR and send a new PR for the second issue?
rose/web/game.js
Outdated
@@ -17,16 +17,21 @@ var ROSE = (function() { | |||
this.controller = new Controller(); | |||
this.rate = new Rate([0.5, 1.0, 2.0, 5.0, 10.0]); | |||
|
|||
var loader = new ImageLoader(function() { | |||
var imageLoader = new ImageLoader(function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to avoid mixedCase names in our code, they are more error prone and harder to read and write. Can rename this to image_loader?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The third commit should be squashed into the seconds, and it would be nice to move both to a new PR.
rose/web/game.css
Outdated
@@ -41,6 +41,17 @@ body { | |||
margin: 0; | |||
} | |||
|
|||
#toggle_mute { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe sound_ctl?
rose/web/game.css
Outdated
padding: 8px 8px; | ||
position: absolute; | ||
left: 50%; | ||
transform: translateX(-50%); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This puts the sound button in a rather central location. I think we need to align this to the right, before or after the game rate control.
rose/web/game.js
Outdated
|
||
this.context = $("#game").get(0).getContext("2d"); | ||
this.dashboard = new Dashboard(imageLoader); | ||
this.track = new Track(imageLoader); | ||
this.obstacles = new Obstacles(imageLoader); | ||
this.cars = new Cars(imageLoader); | ||
this.finish_line = new FinishLine(imageLoader); | ||
this.sound_controller = new SoundController(soundLoader); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a sound_controller in the application is nice idea. But this object has no behavior currently.
We are starting with adding the current soundtrack, and having a way to mute it, but I think in the long term we would like to have different sounds for different game states:
- No players connected - maybe no sound
- Player connected, game not started - revving engines?
- Game running - racing sounds
- Game ended - applause
So I expect that this sound controller will have some behavior like toggle_sound(), and bind this api to the button. Then the same api can be used also from application code if needed.
rose/web/game.js
Outdated
this.loader = loader; | ||
|
||
var localStorageMute = localStorage.getItem('muted'); | ||
this.muted = (typeof localStorageMute !== 'undefined') ? localStorageMute == "true" : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to move the code loading and saving the config to a method of this object.
Also, is "muted" specific enough? maybe we like to save the config under "rose.sound.muted"?
rose/web/game.js
Outdated
|
||
var self = this; | ||
|
||
$("#toggle_mute img").attr('src', icons[this.muted]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a bug here, after muting the sound and reloading the page, I see the wrong button. But maybe I'm just confused by seeing the unmute button when I expect the mute button.
Maybe we need to have sound-on.svg and sound-off.svg instead of mute and unmute. When the sound is muted, we show the sound-off icon, and when the sound is not muted, the sound-on icon.
In this case, when the sound is muted, I expect to see a grayish button, meaning "sound is off". When sound is not muted, I expect the see more lighter button showing "sound is on".
rose/web/game.js
Outdated
|
||
loader.load("res/soundtrack/Nyan_Cat.ogg", function(sound) { | ||
sound.muted = self.muted; | ||
sound.loop = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need this in the previous commit? The sound should always loop, regardless of having a way to mute it.
rose/web/game.js
Outdated
event.preventDefault(); | ||
|
||
self.muted = !self.muted; | ||
$(this).children('img').attr('src', icons[self.muted]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use:
$("#toggle_sound img").attr(...)
rose/web/index.html
Outdated
@@ -14,6 +14,8 @@ | |||
<button id="start" disabled>Start</button> | |||
<button id="stop" disabled>Stop</button> | |||
|
|||
<button id="toggle_mute"><img src="res/icons/mute.svg"></button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This possibly starts with the wrong icon, I wonder if we should have a third icon for the loading step, or make this button disabled until we read the state from local storage.
Thanks for the suggestions, I'll work on it as soon as I get a chance! |
This reverts commit dd9e694.
rose/web/game.js
Outdated
}); | ||
} | ||
|
||
SoundController.prototype.toggle_sound = function(sound_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how you are going to use this in the next version, since when clicking sound button, we have to:
- play/pause sound
- replace the icon
It seems that the entire sound controller belongs to the next PR, this PR is happy with the plain loader, playing the file when it was loaded, as in the first commit.
This reverts commit 8d877e2.
@devmattrick thanks for this fine work! I hope you can find time to send the next PR for #231. |
Adds a soundtrack to the webpage upon startup. Fixes RedHat-Israel#230.
Adds a soundtrack to the webpage upon startup (also allows the ability to mute/ unmute and stores it in local storage), resolving both #230 and #231.
Please let me know if you'd like any changes made!