mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-30 10:56:53 -05:00
Adding communication with iPad app.
This commit is contained in:
parent
8de75024fc
commit
2f07c3e8d3
13 changed files with 188 additions and 68 deletions
|
@ -37,6 +37,8 @@ preload = (arrayOfImages) ->
|
||||||
Application = initialize: ->
|
Application = initialize: ->
|
||||||
Router = require('Router')
|
Router = require('Router')
|
||||||
@isProduction = -> document.location.href.search('codecombat.com') isnt -1
|
@isProduction = -> document.location.href.search('codecombat.com') isnt -1
|
||||||
|
@isIPadApp = webkit?.messageHandlers? and navigator.userAgent?.indexOf('iPad') isnt -1
|
||||||
|
$('body').addClass 'ipad' if @isIPadApp
|
||||||
@tracker = new Tracker()
|
@tracker = new Tracker()
|
||||||
@facebookHandler = new FacebookHandler()
|
@facebookHandler = new FacebookHandler()
|
||||||
@gplusHandler = new GPlusHandler()
|
@gplusHandler = new GPlusHandler()
|
||||||
|
|
|
@ -21,20 +21,16 @@ definitionSchemas =
|
||||||
|
|
||||||
init = ->
|
init = ->
|
||||||
watchForErrors()
|
watchForErrors()
|
||||||
|
setUpIOSLogging()
|
||||||
path = document.location.pathname
|
path = document.location.pathname
|
||||||
testing = path.startsWith '/test'
|
testing = path.startsWith '/test'
|
||||||
demoing = path.startsWith '/demo'
|
demoing = path.startsWith '/demo'
|
||||||
initializeServices() unless testing or demoing
|
initializeServices() unless testing or demoing
|
||||||
|
setUpBackboneMediator()
|
||||||
# Set up Backbone.Mediator schemas
|
|
||||||
setUpDefinitions()
|
|
||||||
setUpChannels()
|
|
||||||
Backbone.Mediator.setValidationEnabled document.location.href.search(/codecombat.com/) is -1
|
|
||||||
app.initialize()
|
app.initialize()
|
||||||
Backbone.history.start({ pushState: true })
|
Backbone.history.start({ pushState: true })
|
||||||
handleNormalUrls()
|
handleNormalUrls()
|
||||||
setUpMoment() # Set up i18n for moment
|
setUpMoment() # Set up i18n for moment
|
||||||
|
|
||||||
treemaExt = require 'treema-ext'
|
treemaExt = require 'treema-ext'
|
||||||
treemaExt.setup()
|
treemaExt.setup()
|
||||||
|
|
||||||
|
@ -59,13 +55,15 @@ handleNormalUrls = ->
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
setUpChannels = ->
|
setUpBackboneMediator = ->
|
||||||
for channel of channelSchemas
|
Backbone.Mediator.addDefSchemas schemas for definition, schemas of definitionSchemas
|
||||||
Backbone.Mediator.addChannelSchemas channelSchemas[channel]
|
Backbone.Mediator.addChannelSchemas schemas for channel, schemas of channelSchemas
|
||||||
|
Backbone.Mediator.setValidationEnabled document.location.href.search(/codecombat.com/) is -1
|
||||||
setUpDefinitions = ->
|
if webkit?.messageHandlers
|
||||||
for definition of definitionSchemas
|
originalPublish = Backbone.Mediator.publish
|
||||||
Backbone.Mediator.addDefSchemas definitionSchemas[definition]
|
Backbone.Mediator.publish = ->
|
||||||
|
originalPublish.apply Backbone.Mediator, arguments
|
||||||
|
webkit.messageHandlers.backboneEventHandler?.postMessage channel: arguments[0], event: serializeForIOS(arguments[1] ? {})
|
||||||
|
|
||||||
setUpMoment = ->
|
setUpMoment = ->
|
||||||
{me} = require 'lib/auth'
|
{me} = require 'lib/auth'
|
||||||
|
@ -94,11 +92,53 @@ watchForErrors = ->
|
||||||
return if currentErrors >= 3
|
return if currentErrors >= 3
|
||||||
return unless me.isAdmin() or document.location.href.search(/codecombat.com/) is -1 or document.location.href.search(/\/editor\//) isnt -1
|
return unless me.isAdmin() or document.location.href.search(/codecombat.com/) is -1 or document.location.href.search(/\/editor\//) isnt -1
|
||||||
++currentErrors
|
++currentErrors
|
||||||
msg = "Error: #{msg}<br>Check the JS console for more."
|
message = "Error: #{msg}<br>Check the JS console for more."
|
||||||
#msg += "\nLine: #{line}" if line?
|
#msg += "\nLine: #{line}" if line?
|
||||||
#msg += "\nColumn: #{col}" if col?
|
#msg += "\nColumn: #{col}" if col?
|
||||||
#msg += "\nError: #{error}" if error?
|
#msg += "\nError: #{error}" if error?
|
||||||
#msg += "\nStack: #{stack}" if stack = error?.stack
|
#msg += "\nStack: #{stack}" if stack = error?.stack
|
||||||
noty text: msg, layout: 'topCenter', type: 'error', killer: false, timeout: 5000, dismissQueue: true, maxVisible: 3, callback: {onClose: -> --currentErrors}
|
noty text: message, layout: 'topCenter', type: 'error', killer: false, timeout: 5000, dismissQueue: true, maxVisible: 3, callback: {onClose: -> --currentErrors}
|
||||||
|
Backbone.Mediator.publish 'application:error', message: msg # For iOS app
|
||||||
|
|
||||||
|
setUpIOSLogging = ->
|
||||||
|
return unless webkit?.messageHandlers
|
||||||
|
for level in ['debug', 'log', 'info', 'warn', 'error']
|
||||||
|
do (level) ->
|
||||||
|
originalLog = console[level]
|
||||||
|
console[level] = ->
|
||||||
|
originalLog.apply console, arguments
|
||||||
|
try
|
||||||
|
webkit?.messageHandlers?.consoleLogHandler?.postMessage level: level, arguments: (a?.toString?() ? ('' + a) for a in arguments)
|
||||||
|
catch e
|
||||||
|
webkit?.messageHandlers?.consoleLogHandler?.postMessage level: level, arguments: ['could not post log: ' + e]
|
||||||
|
|
||||||
|
# This is so hacky... hopefully it's restrictive enough to not be slow.
|
||||||
|
# We could also keep a list of events we are actually subscribed for and only try to send those over.
|
||||||
|
seen = null
|
||||||
|
window.serializeForIOS = serializeForIOS = (obj, depth=3) ->
|
||||||
|
return {} unless depth
|
||||||
|
root = not seen?
|
||||||
|
seen ?= []
|
||||||
|
clone = {}
|
||||||
|
keysHandled = 0
|
||||||
|
for own key, value of obj
|
||||||
|
continue if ++keysHandled > 20
|
||||||
|
if not value
|
||||||
|
clone[key] = value
|
||||||
|
else if value is window or value.firstElementChild or value.preventDefault
|
||||||
|
null # Don't include these things
|
||||||
|
else if value in seen
|
||||||
|
null # No circular references
|
||||||
|
else if _.isArray value
|
||||||
|
clone[key] = (serializeForIOS(child, depth - 1) for child in value)
|
||||||
|
seen.push value
|
||||||
|
else if _.isObject value
|
||||||
|
value = value.attributes if value.id and value.attributes
|
||||||
|
clone[key] = serializeForIOS value, depth - 1
|
||||||
|
seen.push value
|
||||||
|
else
|
||||||
|
clone[key] = value
|
||||||
|
seen = null if root
|
||||||
|
clone
|
||||||
|
|
||||||
$ -> init()
|
$ -> init()
|
||||||
|
|
|
@ -77,8 +77,8 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
'ctrl+\\, ⌘+\\': 'onToggleDebug'
|
'ctrl+\\, ⌘+\\': 'onToggleDebug'
|
||||||
'ctrl+o, ⌘+o': 'onTogglePathFinding'
|
'ctrl+o, ⌘+o': 'onTogglePathFinding'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#- Initialization
|
#- Initialization
|
||||||
|
|
||||||
constructor: (@world, @canvas, givenOptions) ->
|
constructor: (@world, @canvas, givenOptions) ->
|
||||||
|
@ -136,7 +136,7 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
|
|
||||||
|
|
||||||
#- Setting the world
|
#- Setting the world
|
||||||
|
|
||||||
setWorld: (@world) ->
|
setWorld: (@world) ->
|
||||||
@worldLoaded = true
|
@worldLoaded = true
|
||||||
lastFrame = Math.min(@getCurrentFrame(), @world.frames.length - 1)
|
lastFrame = Math.min(@getCurrentFrame(), @world.frames.length - 1)
|
||||||
|
@ -227,10 +227,10 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
++@totalFramesDrawn
|
++@totalFramesDrawn
|
||||||
@stage.update e
|
@stage.update e
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#- Setting play/pause and progress
|
#- Setting play/pause and progress
|
||||||
|
|
||||||
setProgress: (progress, scrubDuration=500) ->
|
setProgress: (progress, scrubDuration=500) ->
|
||||||
progress = Math.max(Math.min(progress, 1), 0.0)
|
progress = Math.max(Math.min(progress, 1), 0.0)
|
||||||
|
|
||||||
|
@ -309,7 +309,7 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
|
|
||||||
|
|
||||||
#- Changes and events that only need to happen when the frame has changed
|
#- Changes and events that only need to happen when the frame has changed
|
||||||
|
|
||||||
onFrameChanged: (force) ->
|
onFrameChanged: (force) ->
|
||||||
@currentFrame = Math.min(@currentFrame, @world.frames.length)
|
@currentFrame = Math.min(@currentFrame, @world.frames.length)
|
||||||
@debugDisplay?.updateFrame @currentFrame
|
@debugDisplay?.updateFrame @currentFrame
|
||||||
|
@ -335,8 +335,8 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
|
|
||||||
getProgress: -> @currentFrame / @world.frames.length
|
getProgress: -> @currentFrame / @world.frames.length
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#- Subscription callbacks
|
#- Subscription callbacks
|
||||||
|
|
||||||
onToggleDebug: (e) ->
|
onToggleDebug: (e) ->
|
||||||
|
@ -484,7 +484,7 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
Backbone.Mediator.publish 'surface:mouse-scrolled', event unless @disabled
|
Backbone.Mediator.publish 'surface:mouse-scrolled', event unless @disabled
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#- Canvas callbacks
|
#- Canvas callbacks
|
||||||
|
|
||||||
onResize: (e) =>
|
onResize: (e) =>
|
||||||
|
@ -509,7 +509,8 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
## newHeight = Math.min 589, newHeight
|
## newHeight = Math.min 589, newHeight
|
||||||
#@canvas.width newWidth
|
#@canvas.width newWidth
|
||||||
#@canvas.height newHeight
|
#@canvas.height newHeight
|
||||||
@canvas.attr width: newWidth, height: newHeight
|
scaleFactor = if application.isIPadApp then 2 else 1 # Retina
|
||||||
|
@canvas.attr width: newWidth * scaleFactor, height: newHeight * scaleFactor
|
||||||
@stage.scaleX *= newWidth / oldWidth
|
@stage.scaleX *= newWidth / oldWidth
|
||||||
@stage.scaleY *= newHeight / oldHeight
|
@stage.scaleY *= newHeight / oldHeight
|
||||||
@camera.onResize newWidth, newHeight
|
@camera.onResize newWidth, newHeight
|
||||||
|
@ -517,7 +518,7 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
|
|
||||||
|
|
||||||
#- Real-time playback
|
#- Real-time playback
|
||||||
|
|
||||||
onRealTimePlaybackWaiting: (e) ->
|
onRealTimePlaybackWaiting: (e) ->
|
||||||
@onRealTimePlaybackStarted e
|
@onRealTimePlaybackStarted e
|
||||||
|
|
||||||
|
@ -539,8 +540,8 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
@canvas.toggleClass 'flag-color-selected', Boolean(e.color)
|
@canvas.toggleClass 'flag-color-selected', Boolean(e.color)
|
||||||
e.pos = @camera.screenToWorld @mouseScreenPos if @mouseScreenPos
|
e.pos = @camera.screenToWorld @mouseScreenPos if @mouseScreenPos
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#- Paths - TODO: move to SpriteBoss? but only update on frame drawing instead of on every frame update?
|
#- Paths - TODO: move to SpriteBoss? but only update on frame drawing instead of on every frame update?
|
||||||
|
|
||||||
updatePaths: ->
|
updatePaths: ->
|
||||||
|
@ -561,9 +562,9 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
return if not @paths
|
return if not @paths
|
||||||
@paths.parent.removeChild @paths
|
@paths.parent.removeChild @paths
|
||||||
@paths = null
|
@paths = null
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#- Screenshot
|
#- Screenshot
|
||||||
|
|
||||||
screenshot: (scale=0.25, format='image/jpeg', quality=0.8, zoom=2) ->
|
screenshot: (scale=0.25, format='image/jpeg', quality=0.8, zoom=2) ->
|
||||||
|
@ -578,10 +579,10 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
@stage.uncache()
|
@stage.uncache()
|
||||||
imageData
|
imageData
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#- Path finding debugging
|
#- Path finding debugging
|
||||||
|
|
||||||
onTogglePathFinding: (e) ->
|
onTogglePathFinding: (e) ->
|
||||||
e?.preventDefault?()
|
e?.preventDefault?()
|
||||||
@hidePathFinding()
|
@hidePathFinding()
|
||||||
|
@ -640,11 +641,11 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
.lineTo(v2.x, v2.y)
|
.lineTo(v2.x, v2.y)
|
||||||
.endStroke()
|
.endStroke()
|
||||||
container.addChild shape
|
container.addChild shape
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#- Teardown
|
#- Teardown
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
@camera?.destroy()
|
@camera?.destroy()
|
||||||
createjs.Ticker.removeEventListener('tick', @tick)
|
createjs.Ticker.removeEventListener('tick', @tick)
|
||||||
|
@ -672,4 +673,3 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
clearTimeout @surfacePauseTimeout if @surfacePauseTimeout
|
clearTimeout @surfacePauseTimeout if @surfacePauseTimeout
|
||||||
clearTimeout @surfaceZoomPauseTimeout if @surfaceZoomPauseTimeout
|
clearTimeout @surfaceZoomPauseTimeout if @surfaceZoomPauseTimeout
|
||||||
super()
|
super()
|
||||||
|
|
||||||
|
|
|
@ -195,6 +195,7 @@ module.exports = class SuperModel extends Backbone.Model
|
||||||
@progress = newProg
|
@progress = newProg
|
||||||
@trigger('update-progress', @progress)
|
@trigger('update-progress', @progress)
|
||||||
@trigger('loaded-all') if @finished()
|
@trigger('loaded-all') if @finished()
|
||||||
|
Backbone.Mediator.publish 'supermodel:load-progress-changed', progress: @progress
|
||||||
|
|
||||||
setMaxProgress: (@maxProgress) ->
|
setMaxProgress: (@maxProgress) ->
|
||||||
resetProgress: -> @progress = 0
|
resetProgress: -> @progress = 0
|
||||||
|
|
|
@ -4,6 +4,10 @@ module.exports =
|
||||||
'application:idle-changed': c.object {},
|
'application:idle-changed': c.object {},
|
||||||
idle: {type: 'boolean'}
|
idle: {type: 'boolean'}
|
||||||
|
|
||||||
|
'application:error': c.object {},
|
||||||
|
message: {type: 'string'}
|
||||||
|
stack: {type: 'string'}
|
||||||
|
|
||||||
'audio-player:loaded': c.object {required: ['sender']},
|
'audio-player:loaded': c.object {required: ['sender']},
|
||||||
sender: {type: 'object'}
|
sender: {type: 'object'}
|
||||||
|
|
||||||
|
@ -31,3 +35,6 @@ module.exports =
|
||||||
'ladder:game-submitted': c.object {required: ['session', 'level']},
|
'ladder:game-submitted': c.object {required: ['session', 'level']},
|
||||||
session: {type: 'object'}
|
session: {type: 'object'}
|
||||||
level: {type: 'object'}
|
level: {type: 'object'}
|
||||||
|
|
||||||
|
'supermodel:load-progress-changed': c.object {required: ['progress']},
|
||||||
|
progress: {type: 'number', minimum: 0, maximum: 1}
|
||||||
|
|
|
@ -109,3 +109,5 @@ module.exports =
|
||||||
'tome:toggle-maximize': c.object {title: 'Toggle Maximize', description: 'Published when we want to make the Tome take up most of the screen'}
|
'tome:toggle-maximize': c.object {title: 'Toggle Maximize', description: 'Published when we want to make the Tome take up most of the screen'}
|
||||||
|
|
||||||
'tome:maximize-toggled': c.object {title: 'Maximize Toggled', description: 'Published when the Tome has changed maximize/minimize state.'}
|
'tome:maximize-toggled': c.object {title: 'Maximize Toggled', description: 'Published when the Tome has changed maximize/minimize state.'}
|
||||||
|
|
||||||
|
'tome:select-primary-sprite': c.object {title: 'Select Primary Sprite', description: 'Published to get the most important sprite\'s code selected.'}
|
||||||
|
|
|
@ -210,3 +210,56 @@ html.fullscreen-editor
|
||||||
width: 95%
|
width: 95%
|
||||||
height: 100%
|
height: 100%
|
||||||
right: 0
|
right: 0
|
||||||
|
|
||||||
|
body.ipad #level-view
|
||||||
|
// Full-width Surface, preserving aspect ratio.
|
||||||
|
height: 1024px * (589 / 924)
|
||||||
|
overflow: hidden
|
||||||
|
|
||||||
|
#code-area, .footer, #thang-hud
|
||||||
|
display: none
|
||||||
|
|
||||||
|
#control-bar-view
|
||||||
|
position: absolute
|
||||||
|
background: transparent
|
||||||
|
z-index: 1
|
||||||
|
|
||||||
|
.home
|
||||||
|
i
|
||||||
|
@include opacity(1)
|
||||||
|
.home-text
|
||||||
|
display: none
|
||||||
|
|
||||||
|
.title
|
||||||
|
left: 20%
|
||||||
|
width: 60%
|
||||||
|
text-align: center
|
||||||
|
color: white
|
||||||
|
|
||||||
|
a, .editor-dash
|
||||||
|
display: none
|
||||||
|
|
||||||
|
#level-chat-view
|
||||||
|
bottom: 40px
|
||||||
|
|
||||||
|
#playback-view
|
||||||
|
background-color: transparent
|
||||||
|
z-index: 3
|
||||||
|
bottom: 30px
|
||||||
|
margin-bottom: -30px
|
||||||
|
|
||||||
|
button
|
||||||
|
background-color: #333
|
||||||
|
|
||||||
|
.scrubber .progress
|
||||||
|
background-color: rgba(255, 255, 255, 0.4)
|
||||||
|
|
||||||
|
#canvas-wrapper, #control-bar-view, #playback-view, #thang-hud
|
||||||
|
width: 100%
|
||||||
|
|
||||||
|
#canvas-wrapper
|
||||||
|
height: 653px
|
||||||
|
|
||||||
|
canvas#surface
|
||||||
|
margin: 0 auto
|
||||||
|
overflow: hidden
|
||||||
|
|
|
@ -2,11 +2,11 @@ h4.home
|
||||||
|
|
||||||
a(href=homeLink || "/")
|
a(href=homeLink || "/")
|
||||||
i.icon-home.icon-white
|
i.icon-home.icon-white
|
||||||
span(data-i18n="play_level.home") Home
|
span(data-i18n="play_level.home").home-text Home
|
||||||
|
|
||||||
h4.title
|
h4.title
|
||||||
| #{worldName}
|
| #{worldName}
|
||||||
span.spl.spr -
|
span.spl.spr.editor-dash -
|
||||||
a(href=editorLink, data-i18n="nav.editor", title="Open " + worldName + " in the Level Editor") Editor
|
a(href=editorLink, data-i18n="nav.editor", title="Open " + worldName + " in the Level Editor") Editor
|
||||||
if multiplayerSession
|
if multiplayerSession
|
||||||
- found = false
|
- found = false
|
||||||
|
|
|
@ -66,7 +66,7 @@ module.exports = class CocoView extends Backbone.View
|
||||||
$.noty.closeAll()
|
$.noty.closeAll()
|
||||||
|
|
||||||
destroyAceEditor: (editor) ->
|
destroyAceEditor: (editor) ->
|
||||||
# convenience method to make sure the ace editor is as destroyed as can be
|
# convenience method to make sure the ace editor is as destroyed as can be
|
||||||
return unless editor
|
return unless editor
|
||||||
session = editor.getSession()
|
session = editor.getSession()
|
||||||
session.setMode ''
|
session.setMode ''
|
||||||
|
@ -155,7 +155,7 @@ module.exports = class CocoView extends Backbone.View
|
||||||
res.load()
|
res.load()
|
||||||
@$el.find('.progress').show()
|
@$el.find('.progress').show()
|
||||||
$(e.target).closest('.loading-error-alert').remove()
|
$(e.target).closest('.loading-error-alert').remove()
|
||||||
|
|
||||||
onSkipResource: (e) ->
|
onSkipResource: (e) ->
|
||||||
res = @supermodel.getResource($(e.target).data('resource-index'))
|
res = @supermodel.getResource($(e.target).data('resource-index'))
|
||||||
return unless res and res.isFailed
|
return unless res and res.isFailed
|
||||||
|
@ -319,6 +319,10 @@ module.exports = class CocoView extends Backbone.View
|
||||||
isMac: ->
|
isMac: ->
|
||||||
navigator.platform.toUpperCase().indexOf('MAC') isnt -1
|
navigator.platform.toUpperCase().indexOf('MAC') isnt -1
|
||||||
|
|
||||||
|
isIPadApp: ->
|
||||||
|
return @_isIPadApp if @_isIPadApp?
|
||||||
|
return @_isIPadApp = webkit?.messageHandlers? and navigator.userAgent?.indexOf('iPad') isnt -1
|
||||||
|
|
||||||
initSlider: ($el, startValue, changeCallback) ->
|
initSlider: ($el, startValue, changeCallback) ->
|
||||||
slider = $el.slider({animate: 'fast'})
|
slider = $el.slider({animate: 'fast'})
|
||||||
slider.slider('value', startValue)
|
slider.slider('value', startValue)
|
||||||
|
|
|
@ -131,6 +131,7 @@ module.exports = class PlayLevelView extends RootView
|
||||||
updateProgress: (progress) ->
|
updateProgress: (progress) ->
|
||||||
super(progress)
|
super(progress)
|
||||||
return if @seenDocs
|
return if @seenDocs
|
||||||
|
return if @isIPadApp()
|
||||||
return unless @levelLoader.session.loaded and @levelLoader.level.loaded
|
return unless @levelLoader.session.loaded and @levelLoader.level.loaded
|
||||||
return unless showFrequency = @levelLoader.level.get('showsGuide')
|
return unless showFrequency = @levelLoader.level.get('showsGuide')
|
||||||
session = @levelLoader.session
|
session = @levelLoader.session
|
||||||
|
@ -173,10 +174,11 @@ module.exports = class PlayLevelView extends RootView
|
||||||
@insertSubView @loadingView = new LevelLoadingView {}
|
@insertSubView @loadingView = new LevelLoadingView {}
|
||||||
@$el.find('#level-done-button').hide()
|
@$el.find('#level-done-button').hide()
|
||||||
$('body').addClass('is-playing')
|
$('body').addClass('is-playing')
|
||||||
|
$('body').bind('touchmove', false) if @isIPadApp()
|
||||||
|
|
||||||
afterInsert: ->
|
afterInsert: ->
|
||||||
super()
|
super()
|
||||||
@showWizardSettingsModal() if not me.get('name')
|
@showWizardSettingsModal() if not me.get('name') and not @isIPadApp()
|
||||||
|
|
||||||
# Partially Loaded Setup ####################################################
|
# Partially Loaded Setup ####################################################
|
||||||
|
|
||||||
|
@ -259,7 +261,7 @@ module.exports = class PlayLevelView extends RootView
|
||||||
@insertSubView new ChatView levelID: @levelID, sessionID: @session.id, session: @session
|
@insertSubView new ChatView levelID: @levelID, sessionID: @session.id, session: @session
|
||||||
worldName = utils.i18n @level.attributes, 'name'
|
worldName = utils.i18n @level.attributes, 'name'
|
||||||
@controlBar = @insertSubView new ControlBarView {worldName: worldName, session: @session, level: @level, supermodel: @supermodel, playableTeams: @world.playableTeams}
|
@controlBar = @insertSubView new ControlBarView {worldName: worldName, session: @session, level: @level, supermodel: @supermodel, playableTeams: @world.playableTeams}
|
||||||
#Backbone.Mediator.publish('level:set-debug', debug: true) if me.displayName() is 'Nick'
|
Backbone.Mediator.publish('level:set-debug', debug: true) if @isIPadApp() # if me.displayName() is 'Nick'
|
||||||
|
|
||||||
initVolume: ->
|
initVolume: ->
|
||||||
volume = me.get('volume')
|
volume = me.get('volume')
|
||||||
|
@ -343,6 +345,8 @@ module.exports = class PlayLevelView extends RootView
|
||||||
if state.selected
|
if state.selected
|
||||||
# TODO: Should also restore selected spell here by saving spellName
|
# TODO: Should also restore selected spell here by saving spellName
|
||||||
Backbone.Mediator.publish 'level:select-sprite', thangID: state.selected, spellName: null
|
Backbone.Mediator.publish 'level:select-sprite', thangID: state.selected, spellName: null
|
||||||
|
else if @isIPadApp()
|
||||||
|
Backbone.Mediator.publish 'tome:select-primary-sprite', {}
|
||||||
if state.playing?
|
if state.playing?
|
||||||
Backbone.Mediator.publish 'level:set-playing', playing: state.playing
|
Backbone.Mediator.publish 'level:set-playing', playing: state.playing
|
||||||
|
|
||||||
|
|
|
@ -80,11 +80,14 @@ module.exports = class ThangListEntryView extends CocoView
|
||||||
score += 9001 * _.size(s.thangs)
|
score += 9001 * _.size(s.thangs)
|
||||||
score
|
score
|
||||||
|
|
||||||
onClick: (e) ->
|
select: ->
|
||||||
return unless @controlsEnabled
|
|
||||||
@sortSpells()
|
@sortSpells()
|
||||||
Backbone.Mediator.publish 'level:select-sprite', thangID: @thang.id, spellName: @spells[0]?.name
|
Backbone.Mediator.publish 'level:select-sprite', thangID: @thang.id, spellName: @spells[0]?.name
|
||||||
|
|
||||||
|
onClick: (e) ->
|
||||||
|
return unless @controlsEnabled
|
||||||
|
@select()
|
||||||
|
|
||||||
onMouseEnter: (e) ->
|
onMouseEnter: (e) ->
|
||||||
return unless @controlsEnabled and @spells.length
|
return unless @controlsEnabled and @spells.length
|
||||||
@clearTimeouts()
|
@clearTimeouts()
|
||||||
|
|
|
@ -11,7 +11,8 @@ module.exports = class ThangListView extends CocoView
|
||||||
id: 'thang-list-view'
|
id: 'thang-list-view'
|
||||||
template: template
|
template: template
|
||||||
|
|
||||||
subscriptions: {}
|
subscriptions:
|
||||||
|
'tome:select-primary-sprite': 'onSelectPrimarySprite'
|
||||||
|
|
||||||
constructor: (options) ->
|
constructor: (options) ->
|
||||||
super options
|
super options
|
||||||
|
@ -89,6 +90,9 @@ module.exports = class ThangListView extends CocoView
|
||||||
@sortThangs()
|
@sortThangs()
|
||||||
@addThangListEntries()
|
@addThangListEntries()
|
||||||
|
|
||||||
|
onSelectPrimarySprite: (e) ->
|
||||||
|
@entries[0]?.select()
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
entry.destroy() for entry in @entries
|
entry.destroy() for entry in @entries
|
||||||
super()
|
super()
|
||||||
|
|
|
@ -4,7 +4,7 @@ librarianLib = require 'test/demo/fixtures/librarian'
|
||||||
|
|
||||||
class WebGLDemoView extends RootView
|
class WebGLDemoView extends RootView
|
||||||
template: -> '<canvas id="visible-canvas" width="1200" height="700" style="background: #ddd"><canvas id="invisible-canvas" width="0" height="0" style="display: none">'
|
template: -> '<canvas id="visible-canvas" width="1200" height="700" style="background: #ddd"><canvas id="invisible-canvas" width="0" height="0" style="display: none">'
|
||||||
|
|
||||||
testMovieClipWithRasterizedSpriteChildren: ->
|
testMovieClipWithRasterizedSpriteChildren: ->
|
||||||
# put two rasterized sprites into a movie clip and show that
|
# put two rasterized sprites into a movie clip and show that
|
||||||
stage = new createjs.Stage(@$el.find('canvas')[0])
|
stage = new createjs.Stage(@$el.find('canvas')[0])
|
||||||
|
@ -25,7 +25,7 @@ class WebGLDemoView extends RootView
|
||||||
mc.timeline.addTween createjs.Tween.get(child1Sprite).to(x: 0).to({x: 60}, 50).to({x: 0}, 50)
|
mc.timeline.addTween createjs.Tween.get(child1Sprite).to(x: 0).to({x: 60}, 50).to({x: 0}, 50)
|
||||||
mc.timeline.addTween createjs.Tween.get(child2Sprite).to(x: 60).to({x: 0}, 50).to({x: 60}, 50)
|
mc.timeline.addTween createjs.Tween.get(child2Sprite).to(x: 60).to({x: 0}, 50).to({x: 60}, 50)
|
||||||
mc.gotoAndPlay "start"
|
mc.gotoAndPlay "start"
|
||||||
|
|
||||||
testMovieClipWithEmptyObjectChildren: ->
|
testMovieClipWithEmptyObjectChildren: ->
|
||||||
# See if I can have the movie clip animate empty objects so we have the properties in
|
# See if I can have the movie clip animate empty objects so we have the properties in
|
||||||
# an object that we can update our real sprites with
|
# an object that we can update our real sprites with
|
||||||
|
@ -41,13 +41,13 @@ class WebGLDemoView extends RootView
|
||||||
mc.gotoAndPlay "start"
|
mc.gotoAndPlay "start"
|
||||||
window.d1 = d1
|
window.d1 = d1
|
||||||
window.d2 = d2
|
window.d2 = d2
|
||||||
|
|
||||||
f = ->
|
f = ->
|
||||||
console.log(JSON.stringify([d1, d2]))
|
console.log(JSON.stringify([d1, d2]))
|
||||||
setInterval(f, 1000)
|
setInterval(f, 1000)
|
||||||
# Seems to work. Can perhaps have the movieclip do the heavy lifting of moving containers around
|
# Seems to work. Can perhaps have the movieclip do the heavy lifting of moving containers around
|
||||||
# and then copy the info over to individual sprites in a separate stage
|
# and then copy the info over to individual sprites in a separate stage
|
||||||
|
|
||||||
testWaterfallRasteredPerformance: ->
|
testWaterfallRasteredPerformance: ->
|
||||||
# rasterize waterfall movieclip (this is what we do now)
|
# rasterize waterfall movieclip (this is what we do now)
|
||||||
stage = new createjs.Stage(@$el.find('canvas')[0])
|
stage = new createjs.Stage(@$el.find('canvas')[0])
|
||||||
|
@ -141,7 +141,7 @@ class WebGLDemoView extends RootView
|
||||||
# 20 waterfalls w/graphics: 25%
|
# 20 waterfalls w/graphics: 25%
|
||||||
# 100 waterfalls w/graphics: 90%
|
# 100 waterfalls w/graphics: 90%
|
||||||
# 100 waterfalls w/out graphics: 42%
|
# 100 waterfalls w/out graphics: 42%
|
||||||
|
|
||||||
# these waterfalls have 20 containers in them, so you'd be able to update 2000 containers
|
# these waterfalls have 20 containers in them, so you'd be able to update 2000 containers
|
||||||
# at 20FPS using 42% CPU
|
# at 20FPS using 42% CPU
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ class WebGLDemoView extends RootView
|
||||||
invisibleStage = new createjs.Stage(@$el.find('#invisible-canvas')[0])
|
invisibleStage = new createjs.Stage(@$el.find('#invisible-canvas')[0])
|
||||||
visibleStage = new createjs.Stage(@$el.find('#visible-canvas')[0])
|
visibleStage = new createjs.Stage(@$el.find('#visible-canvas')[0])
|
||||||
createjs.Ticker.addEventListener "tick", invisibleStage
|
createjs.Ticker.addEventListener "tick", invisibleStage
|
||||||
|
|
||||||
builder = new createjs.SpriteSheetBuilder()
|
builder = new createjs.SpriteSheetBuilder()
|
||||||
frames = []
|
frames = []
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ class WebGLDemoView extends RootView
|
||||||
|
|
||||||
waterfall = new waterfallLib.waterfallRed_JSCC()
|
waterfall = new waterfallLib.waterfallRed_JSCC()
|
||||||
invisibleStage.addChild(waterfall)
|
invisibleStage.addChild(waterfall)
|
||||||
|
|
||||||
#visibleStage.children = waterfall.children # hoped this would work, but you need the ticker
|
#visibleStage.children = waterfall.children # hoped this would work, but you need the ticker
|
||||||
listener = {
|
listener = {
|
||||||
handleEvent: ->
|
handleEvent: ->
|
||||||
|
@ -224,11 +224,11 @@ class WebGLDemoView extends RootView
|
||||||
c.y = i * 3
|
c.y = i * 3
|
||||||
visibleStage.addChild(c)
|
visibleStage.addChild(c)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
window.visibleStage = visibleStage
|
window.visibleStage = visibleStage
|
||||||
# About 45% with SpriteStage, over 100% with regular stage
|
# About 45% with SpriteStage, over 100% with regular stage
|
||||||
|
|
||||||
|
|
||||||
testAnimateSomeWaterfalls: ->
|
testAnimateSomeWaterfalls: ->
|
||||||
# Performance testing
|
# Performance testing
|
||||||
invisibleStage = new createjs.Stage(@$el.find('#invisible-canvas')[0])
|
invisibleStage = new createjs.Stage(@$el.find('#invisible-canvas')[0])
|
||||||
|
@ -256,7 +256,7 @@ class WebGLDemoView extends RootView
|
||||||
movieClips = []
|
movieClips = []
|
||||||
spriteContainers = []
|
spriteContainers = []
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
while i < 100
|
while i < 100
|
||||||
# beStatic = false
|
# beStatic = false
|
||||||
beStatic = i % 2
|
beStatic = i % 2
|
||||||
|
@ -274,11 +274,11 @@ class WebGLDemoView extends RootView
|
||||||
c.scaleX = 0.3
|
c.scaleX = 0.3
|
||||||
c.scaleY = 0.3
|
c.scaleY = 0.3
|
||||||
visibleStage.addChild(c)
|
visibleStage.addChild(c)
|
||||||
|
|
||||||
movieClips.push(waterfall)
|
movieClips.push(waterfall)
|
||||||
spriteContainers.push(c)
|
spriteContainers.push(c)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
createjs.Ticker.addEventListener "tick", invisibleStage
|
createjs.Ticker.addEventListener "tick", invisibleStage
|
||||||
listener = {
|
listener = {
|
||||||
handleEvent: ->
|
handleEvent: ->
|
||||||
|
@ -287,7 +287,7 @@ class WebGLDemoView extends RootView
|
||||||
visibleStage.update()
|
visibleStage.update()
|
||||||
}
|
}
|
||||||
createjs.Ticker.addEventListener "tick", listener
|
createjs.Ticker.addEventListener "tick", listener
|
||||||
|
|
||||||
# All waterfalls animating: 50%
|
# All waterfalls animating: 50%
|
||||||
# Stopping all waterfalls movieclips: 18%
|
# Stopping all waterfalls movieclips: 18%
|
||||||
# Removing movieclips from the animation stage and just showing a static frame: 9%
|
# Removing movieclips from the animation stage and just showing a static frame: 9%
|
||||||
|
@ -351,7 +351,7 @@ class WebGLDemoView extends RootView
|
||||||
visibleStage.update()
|
visibleStage.update()
|
||||||
}
|
}
|
||||||
createjs.Ticker.addEventListener "tick", listener
|
createjs.Ticker.addEventListener "tick", listener
|
||||||
|
|
||||||
# It works, and we can set the movie clip to go to an arbitrary frame.
|
# It works, and we can set the movie clip to go to an arbitrary frame.
|
||||||
# So we can set up the frame rates ourselves. Will have to, because movie clips
|
# So we can set up the frame rates ourselves. Will have to, because movie clips
|
||||||
# don't have frame rate systems like sprites do.
|
# don't have frame rate systems like sprites do.
|
||||||
|
@ -413,12 +413,12 @@ class WebGLDemoView extends RootView
|
||||||
visibleStage.update()
|
visibleStage.update()
|
||||||
}
|
}
|
||||||
createjs.Ticker.addEventListener "tick", listener
|
createjs.Ticker.addEventListener "tick", listener
|
||||||
|
|
||||||
# well this is a bit better. 33% CPU for 100 waterfalls going at various speeds
|
# well this is a bit better. 33% CPU for 100 waterfalls going at various speeds
|
||||||
# and 23% if half the waterfalls are being updated.
|
# and 23% if half the waterfalls are being updated.
|
||||||
# still, you take a pretty big hit for manipulating the positions of containers with the movieclip
|
# still, you take a pretty big hit for manipulating the positions of containers with the movieclip
|
||||||
|
|
||||||
|
|
||||||
testLibrarianHorde: ->
|
testLibrarianHorde: ->
|
||||||
visibleStage = new createjs.SpriteStage(@$el.find('#visible-canvas')[0])
|
visibleStage = new createjs.SpriteStage(@$el.find('#visible-canvas')[0])
|
||||||
builder = new createjs.SpriteSheetBuilder()
|
builder = new createjs.SpriteSheetBuilder()
|
||||||
|
@ -470,10 +470,10 @@ class WebGLDemoView extends RootView
|
||||||
visibleStage.update()
|
visibleStage.update()
|
||||||
}
|
}
|
||||||
createjs.Ticker.addEventListener "tick", listener
|
createjs.Ticker.addEventListener "tick", listener
|
||||||
|
|
||||||
# 20% CPU
|
# 20% CPU
|
||||||
|
|
||||||
|
|
||||||
afterRender: ->
|
afterRender: ->
|
||||||
# @testMovieClipWithRasterizedSpriteChildren()
|
# @testMovieClipWithRasterizedSpriteChildren()
|
||||||
# @testMovieClipWithEmptyObjectChildren()
|
# @testMovieClipWithEmptyObjectChildren()
|
||||||
|
@ -491,4 +491,4 @@ module.exports = ->
|
||||||
v = new WebGLDemoView()
|
v = new WebGLDemoView()
|
||||||
v.render()
|
v.render()
|
||||||
window.v = v
|
window.v = v
|
||||||
v
|
v
|
||||||
|
|
Loading…
Reference in a new issue