mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-11 08:11:21 -05:00
Merge branch 'master' into production
This commit is contained in:
commit
70f341b17a
14 changed files with 72 additions and 42 deletions
|
@ -238,13 +238,13 @@ self.retrieveValueFromFrame = function retrieveValueFromFrame(args) {
|
||||||
|
|
||||||
self.enableFlowOnThangSpell = function (thangID, spellID, userCodeMap) {
|
self.enableFlowOnThangSpell = function (thangID, spellID, userCodeMap) {
|
||||||
try {
|
try {
|
||||||
if (userCodeMap[thangID][spellID].originalOptions.includeFlow === true &&
|
var options = userCodeMap[thangID][spellID].originalOptions;
|
||||||
userCodeMap[thangID][spellID].originalOptions.noSerializationInFlow === true)
|
if (options.includeFlow === true && options.noSerializationInFlow === true)
|
||||||
return;
|
return;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
userCodeMap[thangID][spellID].originalOptions.includeFlow = true;
|
options.includeFlow = true;
|
||||||
userCodeMap[thangID][spellID].originalOptions.noSerializationInFlow = true;
|
options.noSerializationInFlow = true;
|
||||||
var temporaryAether = Aether.deserialize(userCodeMap[thangID][spellID]);
|
var temporaryAether = Aether.deserialize(userCodeMap[thangID][spellID]);
|
||||||
temporaryAether.transpile(temporaryAether.raw);
|
temporaryAether.transpile(temporaryAether.raw);
|
||||||
userCodeMap[thangID][spellID] = temporaryAether.serialize();
|
userCodeMap[thangID][spellID] = temporaryAether.serialize();
|
||||||
|
|
|
@ -21,7 +21,6 @@ module.exports = class GoalsScriptModule extends ScriptModule
|
||||||
channel: 'level-add-goals'
|
channel: 'level-add-goals'
|
||||||
event:
|
event:
|
||||||
goals: @noteGroup.goals.add
|
goals: @noteGroup.goals.add
|
||||||
worldName: @view.world.name
|
|
||||||
return note
|
return note
|
||||||
|
|
||||||
removeNote: ->
|
removeNote: ->
|
||||||
|
@ -29,7 +28,4 @@ module.exports = class GoalsScriptModule extends ScriptModule
|
||||||
channel: 'level-remove-goals'
|
channel: 'level-remove-goals'
|
||||||
event:
|
event:
|
||||||
goals: @noteGroup.goals.remove
|
goals: @noteGroup.goals.remove
|
||||||
worldName: @view.world.name
|
|
||||||
return note
|
return note
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ module.exports = class Camera extends CocoClass
|
||||||
# what the camera is pointed at right now
|
# what the camera is pointed at right now
|
||||||
target: DEFAULT_TARGET
|
target: DEFAULT_TARGET
|
||||||
zoom: DEFAULT_ZOOM
|
zoom: DEFAULT_ZOOM
|
||||||
|
canvasScaleFactorX: 1
|
||||||
|
canvasScaleFactorY: 1
|
||||||
|
|
||||||
# properties for tracking going between targets
|
# properties for tracking going between targets
|
||||||
oldZoom: null
|
oldZoom: null
|
||||||
|
@ -40,14 +42,16 @@ module.exports = class Camera extends CocoClass
|
||||||
subscriptions:
|
subscriptions:
|
||||||
'camera-zoom-in': 'onZoomIn'
|
'camera-zoom-in': 'onZoomIn'
|
||||||
'camera-zoom-out': 'onZoomOut'
|
'camera-zoom-out': 'onZoomOut'
|
||||||
'surface:mouse-scrolled': 'onMouseScrolled'
|
'camera-zoom-to': 'onZoomTo'
|
||||||
'level:restarted': 'onLevelRestarted'
|
'level:restarted': 'onLevelRestarted'
|
||||||
|
'surface:mouse-scrolled': 'onMouseScrolled'
|
||||||
'sprite:mouse-down': 'onMouseDown'
|
'sprite:mouse-down': 'onMouseDown'
|
||||||
'sprite:dragged': 'onMouseDragged'
|
'sprite:dragged': 'onMouseDragged'
|
||||||
'camera-zoom-to': 'onZoomTo'
|
|
||||||
|
|
||||||
constructor: (@canvasWidth, @canvasHeight, angle=Math.asin(0.75), hFOV=d2r(30)) ->
|
constructor: (@canvas, angle=Math.asin(0.75), hFOV=d2r(30)) ->
|
||||||
super()
|
super()
|
||||||
|
@canvasWidth = parseInt(@canvas.attr('width'), 10)
|
||||||
|
@canvasHeight = parseInt(@canvas.attr('height'), 10)
|
||||||
@offset = {x: 0, y: 0}
|
@offset = {x: 0, y: 0}
|
||||||
@calculateViewingAngle angle
|
@calculateViewingAngle angle
|
||||||
@calculateFieldOfView hFOV
|
@calculateFieldOfView hFOV
|
||||||
|
@ -151,6 +155,7 @@ module.exports = class Camera extends CocoClass
|
||||||
onZoomIn: (e) -> @zoomTo @target, @zoom * 1.15, 300
|
onZoomIn: (e) -> @zoomTo @target, @zoom * 1.15, 300
|
||||||
onZoomOut: (e) -> @zoomTo @target, @zoom / 1.15, 300
|
onZoomOut: (e) -> @zoomTo @target, @zoom / 1.15, 300
|
||||||
onMouseScrolled: (e) ->
|
onMouseScrolled: (e) ->
|
||||||
|
return unless e.canvas is @canvas
|
||||||
ratio = 1 + 0.05 * Math.sqrt(Math.abs(e.deltaY))
|
ratio = 1 + 0.05 * Math.sqrt(Math.abs(e.deltaY))
|
||||||
ratio = 1 / ratio if e.deltaY > 0
|
ratio = 1 / ratio if e.deltaY > 0
|
||||||
newZoom = @zoom * ratio
|
newZoom = @zoom * ratio
|
||||||
|
@ -169,10 +174,12 @@ module.exports = class Camera extends CocoClass
|
||||||
@zoomTo target, newZoom, 0
|
@zoomTo target, newZoom, 0
|
||||||
|
|
||||||
onMouseDown: (e) ->
|
onMouseDown: (e) ->
|
||||||
|
return unless e.canvas is @canvas
|
||||||
return if @dragDisabled
|
return if @dragDisabled
|
||||||
@lastPos = {x: e.originalEvent.rawX, y: e.originalEvent.rawY}
|
@lastPos = {x: e.originalEvent.rawX, y: e.originalEvent.rawY}
|
||||||
|
|
||||||
onMouseDragged: (e) ->
|
onMouseDragged: (e) ->
|
||||||
|
return unless e.canvas is @canvas
|
||||||
return if @dragDisabled
|
return if @dragDisabled
|
||||||
target = @boundTarget(@target, @zoom)
|
target = @boundTarget(@target, @zoom)
|
||||||
newPos =
|
newPos =
|
||||||
|
|
|
@ -465,7 +465,11 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
|
|
||||||
onMouseEvent: (e, ourEventName) ->
|
onMouseEvent: (e, ourEventName) ->
|
||||||
return if @letterboxOn
|
return if @letterboxOn
|
||||||
Backbone.Mediator.publish ourEventName, sprite: @, thang: @thang, originalEvent: e
|
p = @imageObject
|
||||||
|
p = p.parent while p.parent
|
||||||
|
newEvent = sprite: @, thang: @thang, originalEvent: e, canvas:p
|
||||||
|
@trigger ourEventName, newEvent
|
||||||
|
Backbone.Mediator.publish ourEventName, newEvent
|
||||||
|
|
||||||
addHealthBar: ->
|
addHealthBar: ->
|
||||||
return unless @thang?.health? and "health" in (@thang?.hudProperties ? [])
|
return unless @thang?.health? and "health" in (@thang?.hudProperties ? [])
|
||||||
|
|
|
@ -20,6 +20,7 @@ module.exports = class Mark extends CocoClass
|
||||||
@build()
|
@build()
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
|
createjs.Tween.removeTweens @mark
|
||||||
@mark?.parent?.removeChild @mark
|
@mark?.parent?.removeChild @mark
|
||||||
@markSprite?.destroy()
|
@markSprite?.destroy()
|
||||||
@sprite = null
|
@sprite = null
|
||||||
|
|
|
@ -26,7 +26,7 @@ module.exports = class PointChooser extends CocoClass
|
||||||
onMouseDown: (e) =>
|
onMouseDown: (e) =>
|
||||||
console.log "got stagemousedown", e, key.shift
|
console.log "got stagemousedown", e, key.shift
|
||||||
return unless key.shift
|
return unless key.shift
|
||||||
@setPoint @options.camera.canvasToWorld {x: e.stageX, y: e.stageY}
|
@setPoint @options.camera.screenToWorld {x: e.stageX, y: e.stageY}
|
||||||
Backbone.Mediator.publish 'choose-point', point: @point
|
Backbone.Mediator.publish 'choose-point', point: @point
|
||||||
|
|
||||||
updateShape: ->
|
updateShape: ->
|
||||||
|
|
|
@ -16,12 +16,12 @@ module.exports = class RegionChooser extends CocoClass
|
||||||
|
|
||||||
onMouseDown: (e) =>
|
onMouseDown: (e) =>
|
||||||
return unless key.shift
|
return unless key.shift
|
||||||
@firstPoint = @options.camera.canvasToWorld {x: e.stageX, y: e.stageY}
|
@firstPoint = @options.camera.screenToWorld {x: e.stageX, y: e.stageY}
|
||||||
@options.camera.dragDisabled = true
|
@options.camera.dragDisabled = true
|
||||||
|
|
||||||
onMouseMove: (e) =>
|
onMouseMove: (e) =>
|
||||||
return unless @firstPoint
|
return unless @firstPoint
|
||||||
@secondPoint = @options.camera.canvasToWorld {x: e.stageX, y: e.stageY}
|
@secondPoint = @options.camera.screenToWorld {x: e.stageX, y: e.stageY}
|
||||||
@restrictRegion() if @options.restrictRatio
|
@restrictRegion() if @options.restrictRatio
|
||||||
@updateShape()
|
@updateShape()
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ module.exports = class SpriteBoss extends CocoClass
|
||||||
'bus:player-left': 'onPlayerLeft'
|
'bus:player-left': 'onPlayerLeft'
|
||||||
# 'level-set-debug': 'onSetDebug'
|
# 'level-set-debug': 'onSetDebug'
|
||||||
'level-highlight-sprites': 'onHighlightSprites'
|
'level-highlight-sprites': 'onHighlightSprites'
|
||||||
'sprite:mouse-up': 'onSpriteMouseUp'
|
|
||||||
'surface:stage-mouse-down': 'onStageMouseDown'
|
'surface:stage-mouse-down': 'onStageMouseDown'
|
||||||
'level-select-sprite': 'onSelectSprite'
|
'level-select-sprite': 'onSelectSprite'
|
||||||
'level-suppress-selection-sounds': 'onSuppressSelectionSounds'
|
'level-suppress-selection-sounds': 'onSuppressSelectionSounds'
|
||||||
|
@ -47,7 +46,7 @@ module.exports = class SpriteBoss extends CocoClass
|
||||||
toString: -> "<SpriteBoss: #{@spriteArray.length} sprites>"
|
toString: -> "<SpriteBoss: #{@spriteArray.length} sprites>"
|
||||||
|
|
||||||
thangTypeFor: (type) ->
|
thangTypeFor: (type) ->
|
||||||
_.find @options.thangTypes, (m) -> m.get('actions') and m.get('original') is type or m.get('name') is type
|
_.find @options.thangTypes, (m) -> m.get('original') is type or m.get('name') is type
|
||||||
|
|
||||||
createLayers: ->
|
createLayers: ->
|
||||||
@spriteLayers = {}
|
@spriteLayers = {}
|
||||||
|
@ -152,6 +151,7 @@ module.exports = class SpriteBoss extends CocoClass
|
||||||
options = @createSpriteOptions thang: thang
|
options = @createSpriteOptions thang: thang
|
||||||
options.resolutionFactor = if thangType.get('kind') is 'Floor' then 2 else SPRITE_RESOLUTION_FACTOR
|
options.resolutionFactor = if thangType.get('kind') is 'Floor' then 2 else SPRITE_RESOLUTION_FACTOR
|
||||||
sprite = new CocoSprite thangType, options
|
sprite = new CocoSprite thangType, options
|
||||||
|
@listenTo sprite, 'sprite:mouse-up', @onSpriteMouseUp
|
||||||
@addSprite sprite, null, layer
|
@addSprite sprite, null, layer
|
||||||
sprite.setDebug @debug
|
sprite.setDebug @debug
|
||||||
sprite
|
sprite
|
||||||
|
|
|
@ -400,7 +400,7 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
canvasWidth = parseInt @canvas.attr('width'), 10
|
canvasWidth = parseInt @canvas.attr('width'), 10
|
||||||
canvasHeight = parseInt @canvas.attr('height'), 10
|
canvasHeight = parseInt @canvas.attr('height'), 10
|
||||||
@camera?.destroy()
|
@camera?.destroy()
|
||||||
@camera = new Camera canvasWidth, canvasHeight
|
@camera = new Camera @canvas
|
||||||
AudioPlayer.camera = @camera
|
AudioPlayer.camera = @camera
|
||||||
@layers.push @surfaceLayer = new Layer name: "Surface", layerPriority: 0, transform: Layer.TRANSFORM_SURFACE, camera: @camera
|
@layers.push @surfaceLayer = new Layer name: "Surface", layerPriority: 0, transform: Layer.TRANSFORM_SURFACE, camera: @camera
|
||||||
@layers.push @surfaceTextLayer = new Layer name: "Surface Text", layerPriority: 1, transform: Layer.TRANSFORM_SURFACE_TEXT, camera: @camera
|
@layers.push @surfaceTextLayer = new Layer name: "Surface Text", layerPriority: 1, transform: Layer.TRANSFORM_SURFACE_TEXT, camera: @camera
|
||||||
|
@ -425,6 +425,7 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
oldHeight = parseInt @canvas.attr('height'), 10
|
oldHeight = parseInt @canvas.attr('height'), 10
|
||||||
newWidth = @canvas.width()
|
newWidth = @canvas.width()
|
||||||
newHeight = @canvas.height()
|
newHeight = @canvas.height()
|
||||||
|
return unless newWidth > 0 and newHeight > 0
|
||||||
#if InstallTrigger? # Firefox rendering performance goes down as canvas size goes up
|
#if InstallTrigger? # Firefox rendering performance goes down as canvas size goes up
|
||||||
# newWidth = Math.min 924, newWidth
|
# newWidth = Math.min 924, newWidth
|
||||||
# newHeight = Math.min 589, newHeight
|
# newHeight = Math.min 589, newHeight
|
||||||
|
@ -544,6 +545,7 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
deltaX: e.deltaX
|
deltaX: e.deltaX
|
||||||
deltaY: e.deltaY
|
deltaY: e.deltaY
|
||||||
screenPos: @mouseScreenPos
|
screenPos: @mouseScreenPos
|
||||||
|
canvas: @canvas
|
||||||
Backbone.Mediator.publish 'surface:mouse-scrolled', event unless @disabled
|
Backbone.Mediator.publish 'surface:mouse-scrolled', event unless @disabled
|
||||||
|
|
||||||
hookUpChooseControls: ->
|
hookUpChooseControls: ->
|
||||||
|
|
|
@ -85,6 +85,12 @@ module.exports = class World
|
||||||
frameToLoadUntil = @totalFrames
|
frameToLoadUntil = @totalFrames
|
||||||
i = @frames.length
|
i = @frames.length
|
||||||
while i < frameToLoadUntil
|
while i < frameToLoadUntil
|
||||||
|
if @debugging
|
||||||
|
for thang in @thangs when thang.isProgrammable
|
||||||
|
userCode = @userCodeMap[thang.id] ? {}
|
||||||
|
for methodName, aether of userCode
|
||||||
|
framesToLoadFlowBefore = if methodName is 'plan' then 200 else 1 # Adjust if plan() is taking even longer
|
||||||
|
aether._shouldSkipFlow = i < loadUntilFrame - framesToLoadFlowBefore
|
||||||
try
|
try
|
||||||
@getFrame(i)
|
@getFrame(i)
|
||||||
++i # increment this after we have succeeded in getting the frame, otherwise we'll have to do that frame again
|
++i # increment this after we have succeeded in getting the frame, otherwise we'll have to do that frame again
|
||||||
|
|
|
@ -100,10 +100,8 @@ module.exports = class ThangTypeEditView extends View
|
||||||
initStage: ->
|
initStage: ->
|
||||||
canvas = @$el.find('#canvas')
|
canvas = @$el.find('#canvas')
|
||||||
@stage = new createjs.Stage(canvas[0])
|
@stage = new createjs.Stage(canvas[0])
|
||||||
canvasWidth = parseInt(canvas.attr('width'), 10)
|
|
||||||
canvasHeight = parseInt(canvas.attr('height'), 10)
|
|
||||||
@camera?.destroy()
|
@camera?.destroy()
|
||||||
@camera = new Camera canvasWidth, canvasHeight
|
@camera = new Camera canvas
|
||||||
|
|
||||||
@torsoDot = @makeDot('blue')
|
@torsoDot = @makeDot('blue')
|
||||||
@mouthDot = @makeDot('yellow')
|
@mouthDot = @makeDot('yellow')
|
||||||
|
|
|
@ -14,15 +14,15 @@ module.exports = class ControlBarView extends View
|
||||||
|
|
||||||
events:
|
events:
|
||||||
'click #multiplayer-button': ->
|
'click #multiplayer-button': ->
|
||||||
window.tracker?.trackEvent 'Clicked Multiplayer', level: @worldName, label: @worldName
|
window.tracker?.trackEvent 'Clicked Multiplayer', level: @level.get('name'), label: @level.get('name')
|
||||||
@showMultiplayerModal()
|
@showMultiplayerModal()
|
||||||
|
|
||||||
'click #docs-button': ->
|
'click #docs-button': ->
|
||||||
window.tracker?.trackEvent 'Clicked Docs', level: @worldName, label: @worldName
|
window.tracker?.trackEvent 'Clicked Docs', level: @level.get('name'), label: @level.get('name')
|
||||||
@showGuideModal()
|
@showGuideModal()
|
||||||
|
|
||||||
'click #restart-button': ->
|
'click #restart-button': ->
|
||||||
window.tracker?.trackEvent 'Clicked Restart', level: @worldName, label: @worldName
|
window.tracker?.trackEvent 'Clicked Restart', level: @level.get('name'), label: @level.get('name')
|
||||||
@showRestartModal()
|
@showRestartModal()
|
||||||
|
|
||||||
'click #next-game-button': ->
|
'click #next-game-button': ->
|
||||||
|
|
|
@ -35,8 +35,20 @@ module.exports = class DebugView extends View
|
||||||
@lastFrameRequested = -1
|
@lastFrameRequested = -1
|
||||||
@workerIsSimulating = false
|
@workerIsSimulating = false
|
||||||
|
|
||||||
|
|
||||||
|
pad2: (num) ->
|
||||||
|
if not num? or num is 0 then "00" else ((if num < 10 then "0" else "") + num)
|
||||||
|
|
||||||
|
calculateCurrentTimeString: =>
|
||||||
|
time = @currentFrame / @frameRate
|
||||||
|
mins = Math.floor(time / 60)
|
||||||
|
secs = (time - mins * 60).toFixed(1)
|
||||||
|
"#{mins}:#{@pad2 secs}"
|
||||||
|
|
||||||
|
|
||||||
setTooltipKeyAndValue: (key, value) =>
|
setTooltipKeyAndValue: (key, value) =>
|
||||||
@$el.find("code").text "#{key}: #{value}"
|
message = "Time: #{@calculateCurrentTimeString()}\n#{key}: #{value}"
|
||||||
|
@$el.find("code").text message
|
||||||
@$el.show().css(@pos)
|
@$el.show().css(@pos)
|
||||||
|
|
||||||
setTooltipText: (text) =>
|
setTooltipText: (text) =>
|
||||||
|
@ -128,9 +140,11 @@ module.exports = class DebugView extends View
|
||||||
|
|
||||||
onNewWorld: (e) ->
|
onNewWorld: (e) ->
|
||||||
@thang = @options.thang = e.world.thangMap[@thang.id] if @thang
|
@thang = @options.thang = e.world.thangMap[@thang.id] if @thang
|
||||||
|
@frameRate = e.world.frameRate
|
||||||
|
|
||||||
onFrameChanged: (data) ->
|
onFrameChanged: (data) ->
|
||||||
@currentFrame = data.frame
|
@currentFrame = data.frame
|
||||||
|
@frameRate = data.world.frameRate
|
||||||
|
|
||||||
update: ->
|
update: ->
|
||||||
if @variableChain
|
if @variableChain
|
||||||
|
|
|
@ -295,7 +295,7 @@ module.exports = class PlayLevelView extends View
|
||||||
@victorySeen = true
|
@victorySeen = true
|
||||||
victoryTime = (new Date()) - @loadEndTime
|
victoryTime = (new Date()) - @loadEndTime
|
||||||
if victoryTime > 10 * 1000 # Don't track it if we're reloading an already-beaten level
|
if victoryTime > 10 * 1000 # Don't track it if we're reloading an already-beaten level
|
||||||
application.tracker?.trackEvent 'Saw Victory', level: @world.name, label: @world.name
|
application.tracker?.trackEvent 'Saw Victory', level: @level.get('name'), label: @level.get('name')
|
||||||
application.tracker?.trackTiming victoryTime, 'Level Victory Time', @levelID, @levelID, 100
|
application.tracker?.trackTiming victoryTime, 'Level Victory Time', @levelID, @levelID, 100
|
||||||
|
|
||||||
showVictory: ->
|
showVictory: ->
|
||||||
|
@ -309,12 +309,12 @@ module.exports = class PlayLevelView extends View
|
||||||
@tome.reloadAllCode()
|
@tome.reloadAllCode()
|
||||||
Backbone.Mediator.publish 'level:restarted'
|
Backbone.Mediator.publish 'level:restarted'
|
||||||
$('#level-done-button', @$el).hide()
|
$('#level-done-button', @$el).hide()
|
||||||
application.tracker?.trackEvent 'Confirmed Restart', level: @world.name, label: @world.name
|
application.tracker?.trackEvent 'Confirmed Restart', level: @level.get('name'), label: @level.get('name')
|
||||||
|
|
||||||
onInfiniteLoop: (e) ->
|
onInfiniteLoop: (e) ->
|
||||||
return unless e.firstWorld
|
return unless e.firstWorld
|
||||||
@openModalView new InfiniteLoopModal()
|
@openModalView new InfiniteLoopModal()
|
||||||
application.tracker?.trackEvent 'Saw Initial Infinite Loop', level: @world.name, label: @world.name
|
application.tracker?.trackEvent 'Saw Initial Infinite Loop', level: @level.get('name'), label: @level.get('name')
|
||||||
|
|
||||||
onPlayNextLevel: ->
|
onPlayNextLevel: ->
|
||||||
nextLevelID = @getNextLevelID()
|
nextLevelID = @getNextLevelID()
|
||||||
|
@ -485,7 +485,9 @@ module.exports = class PlayLevelView extends View
|
||||||
|
|
||||||
onNewWorld: (e) ->
|
onNewWorld: (e) ->
|
||||||
return if @headless
|
return if @headless
|
||||||
|
scripts = @world.scripts # Since these worlds don't have scripts, preserve them.
|
||||||
@world = e.world
|
@world = e.world
|
||||||
|
@world.scripts = scripts
|
||||||
thangTypes = @supermodel.getModels(ThangType)
|
thangTypes = @supermodel.getModels(ThangType)
|
||||||
for [spriteName, message] in @world.thangDialogueSounds()
|
for [spriteName, message] in @world.thangDialogueSounds()
|
||||||
continue unless thangType = _.find thangTypes, (m) -> m.get('name') is spriteName
|
continue unless thangType = _.find thangTypes, (m) -> m.get('name') is spriteName
|
||||||
|
|
Loading…
Reference in a new issue