Permalink
Browse files

Merge pull request #195 from stravid/feature/animated-screens

PR: feature/animated-screens
  • Loading branch information...
2 parents 64d17a7 + c107d32 commit 5fb628e38e31d166942c2e2794c3505122293b3f @stravid committed Jun 1, 2012
Showing with 942 additions and 110 deletions.
  1. +2 −2 app/assets/javascripts/slotcars/build/build_screen.js.coffee
  2. +1 −2 app/assets/javascripts/slotcars/errors/error_screen.js.coffee
  3. +6 −1 app/assets/javascripts/slotcars/factories/screen_factory.js.coffee
  4. +4 −3 app/assets/javascripts/slotcars/home/home_screen.js.coffee
  5. +1 −7 app/assets/javascripts/slotcars/home/views/home_screen_view.js.coffee
  6. +0 −5 app/assets/javascripts/slotcars/play/game.js.coffee
  7. +3 −3 app/assets/javascripts/slotcars/play/play_screen.js.coffee
  8. +0 −4 app/assets/javascripts/slotcars/play/views/play_screen_view.js.coffee
  9. +15 −0 app/assets/javascripts/slotcars/shared/lib/animation.js.coffee
  10. +2 −3 app/assets/javascripts/slotcars/shared/lib/base_game.js.coffee
  11. +41 −0 app/assets/javascripts/slotcars/shared/mixins/animatable.js.coffee
  12. +3 −2 app/assets/javascripts/slotcars/shared/mixins/appendable.js.coffee
  13. +3 −2 app/assets/javascripts/slotcars/shared/mixins/panable.js.coffee
  14. +7 −0 app/assets/javascripts/slotcars/shared/views/base_game_view_container.js.coffee
  15. +8 −2 app/assets/javascripts/slotcars/slotcars_application.js.coffee
  16. +3 −2 app/assets/javascripts/slotcars/tracks/tracks_screen.js.coffee
  17. +3 −1 app/assets/javascripts/slotcars/tracks/views/page_view.js.coffee
  18. +1 −1 app/assets/javascripts/slotcars/tracks/views/tracks_view.js.coffee
  19. +634 −0 app/assets/javascripts/vendor/jquery.animate-enhanced.js
  20. +10 −2 app/assets/stylesheets/global.css.scss
  21. +0 −22 app/views/layouts/application.html.erb
  22. +3 −3 app/views/layouts/slotcars.html.erb
  23. 0 app/views/tracks/index.html.erb
  24. +4 −1 spec/javascripts/helpers/jasmine/custom_matchers.js.coffee
  25. +20 −1 spec/javascripts/unit/slotcars/factories/screen_factory_spec.js.coffee
  26. +0 −18 spec/javascripts/unit/slotcars/play/game_spec.js.coffee
  27. +6 −8 spec/javascripts/unit/slotcars/play/play_screen_spec.js.coffee
  28. +29 −0 spec/javascripts/unit/slotcars/shared/lib/animation_spec.js.coffee
  29. +5 −9 spec/javascripts/unit/slotcars/shared/lib/base_game_spec.js.coffee
  30. +99 −0 spec/javascripts/unit/slotcars/shared/mixins/animatable_spec.js.coffee
  31. +12 −6 spec/javascripts/unit/slotcars/shared/mixins/appendable_spec.js.coffee
  32. +17 −0 spec/javascripts/unit/slotcars/shared/views/base_game_view_container_spec.js.coffee
@@ -1,8 +1,8 @@
-#= require slotcars/shared/mixins/appendable
#= require slotcars/factories/screen_factory
-Build.BuildScreen = Ember.Object.extend Shared.Appendable,
+Build.BuildScreen = Ember.Object.extend
+ view: null
_builder: null
_buildScreenStateManager: null
@@ -1,7 +1,6 @@
-#= require slotcars/shared/mixins/appendable
#= require slotcars/factories/screen_factory
-Errors.ErrorScreen = Ember.Object.extend Shared.Appendable,
+Errors.ErrorScreen = Ember.Object.extend
init: -> @view = Errors.ErrorScreenView.create()
@@ -3,4 +3,9 @@
Shared.ScreenFactory = Shared.Factory.extend
- registerScreen: (id, screenType) -> @registerType id, screenType
+ registerScreen: (id, screenType) -> @registerType id, screenType
+
+ getInstanceOf: (typeId, createParamters={}) ->
+ instance = @_super typeId, createParamters
+ Shared.Appendable.apply instance
+ Shared.Animatable.apply instance
@@ -1,13 +1,14 @@
-#= require slotcars/shared/mixins/appendable
#= require slotcars/factories/screen_factory
#= require slotcars/shared/components/container
-Home.HomeScreen = Ember.Object.extend Shared.Appendable, Shared.Container,
+Home.HomeScreen = Ember.Object.extend Shared.Container,
+
+ view: null
init: ->
@view = Home.HomeScreenView.create()
accountWidget = Shared.WidgetFactory.getInstance().getInstanceOf 'AccountWidget'
accountWidget.addToContainerAtLocation this, 'rightColumn'
-Shared.ScreenFactory.getInstance().registerScreen 'HomeScreen', Home.HomeScreen
+Shared.ScreenFactory.getInstance().registerScreen 'HomeScreen', Home.HomeScreen
@@ -1,10 +1,4 @@
Home.HomeScreenView = Ember.View.extend
- elementId: 'home_screen_view'
+ elementId: 'home-screen-view'
templateName: 'slotcars_home_templates_home_screen_view_template'
-
- onTouchMouseMove: (event) ->
- event.originalEvent.preventDefault()
-
- didInsertElement: ->
- @$(document.body).on 'touchMouseMove', (event) => @onTouchMouseMove(event)
@@ -34,8 +34,3 @@ Play.Game = Shared.BaseGame.extend
@_baseGameViewContainer.set 'clockView', @_clockView
@_baseGameViewContainer.set 'gameView', @_gameView
@_baseGameViewContainer.set 'ghostView', @_ghostView
-
- destroy: ->
- @_super()
- @_gameView.destroy()
- @_clockView.destroy()
@@ -1,8 +1,8 @@
-#= require slotcars/shared/mixins/appendable
#= require slotcars/factories/screen_factory
-Play.PlayScreen = Ember.Object.extend Shared.Appendable,
+Play.PlayScreen = Ember.Object.extend
+ view: null
trackId: null
track: null
car: null
@@ -52,6 +52,6 @@ Play.PlayScreen = Ember.Object.extend Shared.Appendable,
@_super()
@_game.destroy() if @_game?
@_playScreenNotificationsController.destroy() if @_playScreenNotificationsController?
- @_playScreenNotificationsView.remove() if @_playScreenNotificationsView?
+ @_playScreenNotificationsView.destroy() if @_playScreenNotificationsView?
Shared.ScreenFactory.getInstance().registerScreen 'PlayScreen', Play.PlayScreen
@@ -3,7 +3,3 @@ Play.PlayScreenView = Ember.View.extend
elementId: 'play-screen-view'
templateName: 'slotcars_play_templates_play_screen_view_template'
contentView: null
- clockView: null
- gameView: null
- carView: null
-
@@ -0,0 +1,15 @@
+Shared.Animation = Ember.Object.extend
+
+ options: {} # useful properties: duration, delay
+ fn: null
+ callback: null
+
+ run: ->
+ @options.delay = @options.delay || 0
+
+ Ember.run.later (=>
+ @fn()
+ Ember.run.later (=> @callback()), @options.duration
+ ), @options.delay
+
+ return this
@@ -40,8 +40,7 @@ Shared.BaseGame = Ember.Object.extend
@screenView.set 'contentView', @_baseGameViewContainer
destroy: ->
- @screenView.set 'contentView', null
- @_carView.destroy()
- @_trackView.destroy()
@_baseGameViewContainer.destroy()
+ @screenView.set 'contentView', null
@_gameController.destroy()
+ @_super()
@@ -0,0 +1,41 @@
+Shared.Animatable = Ember.Mixin.create
+
+ animation: null
+ view: Ember.required()
+
+ append: ->
+ originalDidInsertElementMethod = @view.didInsertElement
+
+ @view.didInsertElement = =>
+ @animateIn() if @animateIn
+ originalDidInsertElementMethod() if originalDidInsertElementMethod
+
+ @_super()
+
+ animate: (options, fn, callback=->) ->
+ @animation = Shared.Animation.create(
+ options: options
+ fn: fn
+ callback: callback
+ ).run()
+
+ animateIn: ->
+ @view.$().css({ top: 3, opacity: 0 })
+ @animate { delay: 350 }
+ , => @view.$().animate { top: '-=3', opacity: 1 }, { duration: 300 }
+
+ animateOut: ->
+ @animate { duration: 450 }
+ , => @view.$().animate { top: '+=3', opacity: 0 }, { duration: 400 }
+
+ destroy: ->
+ if @animateOut
+ @animateOut()
+ _super = @_super
+ delay = (@animation.options.duration || 0) + (@animation.options.delay || 0)
+ Ember.run.later (=>
+ _super.apply this
+ @animation.destroy()
+ ), delay
+ else
+ @_super()
@@ -3,10 +3,11 @@ Shared.Appendable = Ember.Mixin.create
view: Ember.required()
append: ->
+ @view.set 'classNames', ['screen']
+ @view.appendTo('#screen-container')
+
Shared.FastTriggerable.apply @view
- @view.append()
destroy: ->
@_super()
- @view.remove()
@view.destroy()
@@ -2,12 +2,13 @@ Shared.Panable = Ember.Mixin.create
car: Ember.required()
classNames: ['panable']
-
+
onCarPositionChange: ( ->
position = @car.position
drawPosition =
x: position.x * @scaleFactor + SCREEN_WIDTH / 2
y: position.y * @scaleFactor + SCREEN_HEIGHT / 2
+ @$().css '-webkit-backface-visibility', 'hidden'
@$().css '-webkit-transform', "translate3d(#{-drawPosition.x}px,#{-drawPosition.y}px,0)"
- ).observes 'car.position'
+ ).observes 'car.position'
@@ -7,3 +7,10 @@ Shared.BaseGameViewContainer = Ember.View.extend
ghostView: null
clockView: null
gameView: null
+
+ destroy: ->
+ @trackView.destroy() if @trackView
+ @carView.destroy() if @carView
+ @clockView.destroy() if @clockView
+ @gameView.destroy() if @gameView
+ @_super()
@@ -1,24 +1,30 @@
+#= require configuration
+
#= require vendor/raphael
+#= require vendor/jquery.animate-enhanced
#= require embient/ember
#= require embient/ember-routemanager
#= require embient/ember-data
#= require embient/ember-layout
#= require namespaces
-#= require configuration
-
#= require_tree ../helpers
#= require_tree ../slotcars
window.SlotcarsApplication = Ember.Application.extend
_currentScreen: null
ready: ->
+ (jQuery document).on 'touchMouseMove', (event) => @onTouchMouseMove(event)
+
Shared.routeManager = Shared.RouteManager.create delegate: this
Shared.routeManager.start()
Shared.routeLocalLinks Shared.routeManager
+ onTouchMouseMove: (event) ->
+ event.originalEvent.preventDefault() # prevent scrolling on the iPad
+
showScreen: (screenId, createParamters) ->
@_destroyCurrentScreen()
@_currentScreen = Shared.ScreenFactory.getInstance().getInstanceOf screenId, createParamters
@@ -1,7 +1,8 @@
-#= require slotcars/shared/mixins/appendable
#= require slotcars/factories/screen_factory
-Tracks.TracksScreen = Ember.Object.extend Shared.Appendable,
+Tracks.TracksScreen = Ember.Object.extend
+
+ view: null
init: ->
@view = Tracks.TracksScreenView.create()
@@ -16,6 +16,8 @@ Tracks.PageView = Ember.View.extend
disableTransitions: -> @$().css '-webkit-transition', ''
- enableTransitions: -> @$().css '-webkit-transition', '-webkit-transform 0.2s ease-in-out'
+ enableTransitions: ->
+ @$().css '-webkit-backface-visibility', 'hidden'
+ @$().css '-webkit-transition', '-webkit-transform 0.2s ease-in-out'
moveToOrigin: -> @moveTo 0
@@ -69,7 +69,7 @@ Tracks.TracksView = Ember.View.extend
(@$ '#swiper').off 'touchMouseMove'
(@$ '#swiper').off 'touchMouseUp'
- @onSwipeEnd @lastSwipePosition - @swipeStartPosition
+ @onSwipeEnd @lastSwipePosition - @swipeStartPosition if @lastSwipePosition?
onSwipeEnd: (delta) ->
return if @currentPage is 1 && delta > 0
Oops, something went wrong.

0 comments on commit 5fb628e

Please sign in to comment.