diff --git a/app/lib/surface/CocoSprite.coffee b/app/lib/surface/CocoSprite.coffee index 3daaa5635..98187cb7b 100644 --- a/app/lib/surface/CocoSprite.coffee +++ b/app/lib/surface/CocoSprite.coffee @@ -73,7 +73,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass toString: -> "<CocoSprite: #{@thang?.id}>" buildSpriteSheet: -> - options = @thang?.getSpriteOptions() or {} + options = @thang?.getSpriteOptions?() or {} options.colorConfig = @options.colorConfig if @options.colorConfig options.async = false @thangType.getSpriteSheet options diff --git a/app/lib/surface/Surface.coffee b/app/lib/surface/Surface.coffee index a40403cf3..d12b11c59 100644 --- a/app/lib/surface/Surface.coffee +++ b/app/lib/surface/Surface.coffee @@ -65,6 +65,7 @@ module.exports = Surface = class Surface extends CocoClass shortcuts: '\\': 'onToggleDebug' 'g': 'onToggleGrid' + 'w': 'onTogglePathFinding' # external functions @@ -101,6 +102,61 @@ module.exports = Surface = class Surface extends CocoClass @onFrameChanged() Backbone.Mediator.publish 'surface:world-set-up' + onTogglePathFinding: -> + @hidePathFinding() + @showingPathFinding = not @showingPathFinding + if @showingPathFinding then @showPathFinding() else @hidePathFinding() + + hidePathFinding: -> + @surfaceLayer.removeChild @navRectangles if @navRectangles + @surfaceLayer.removeChild @navPaths if @navPaths + @navRectangles = @navPaths = null + + showPathFinding: -> + @hidePathFinding() + mesh = _.values(@world.navMeshes or {})[0] + return unless mesh + @navRectangles = new createjs.Container() + @navRectangles.layerPriority = -1 + @addMeshRectanglesToContainer mesh, @navRectangles + @surfaceLayer.addChild @navRectangles + @surfaceLayer.updateLayerOrder() + return @surfaceLayer.updateLayerOrder() unless @world.graph + @navPaths = new createjs.Container() + @navPaths.layerPriority = -1 + @addNavPathsToContainer @world.graph, @navPaths + @surfaceLayer.addChild @navPaths + @surfaceLayer.updateLayerOrder() + + addMeshRectanglesToContainer: (mesh, container) -> + for rect in mesh + shape = new createjs.Shape() + pos = @camera.worldToSurface {x:rect.x, y:rect.y} + dim = @camera.worldToSurface {x:rect.width, y:rect.height} + shape.graphics + .setStrokeStyle(3) + .beginFill('rgba(0, 0, 128, 0.3)') + .beginStroke('rgba(0, 0, 128, 0.7)') + .drawRect(pos.x - dim.x/2, pos.y - dim.y/2, dim.x, dim.y) + container.addChild shape + + addNavPathsToContainer: (graph, container) -> + for node in _.values graph + for edgeVertex in node.edges + @drawLine node.vertex, edgeVertex, container + + drawLine: (v1, v2, container) -> + shape = new createjs.Shape() + v1 = @camera.worldToSurface v1 + v2 = @camera.worldToSurface v2 + shape.graphics + .setStrokeStyle(1) + .moveTo(v1.x, v1.y) + .beginStroke('rgba(128, 0, 0, 0.4)') + .lineTo(v2.x, v2.y) + .endStroke() + container.addChild shape + setProgress: (progress, scrubDuration=500) -> progress = Math.max(Math.min(progress, 0.99), 0.0) diff --git a/app/locale/zh.coffee b/app/locale/zh.coffee index daa9f151f..32dc873c8 100644 --- a/app/locale/zh.coffee +++ b/app/locale/zh.coffee @@ -1,5 +1,5 @@ module.exports = nativeDescription: "中文", englishDescription: "Chinese", translation: -# common: + common: # loading: "Loading..." # saving: "Saving..." sending: "在发送中。。。" @@ -243,7 +243,7 @@ module.exports = nativeDescription: "中文", englishDescription: "Chinese", tra # edit_btn_preview: "Preview" # edit_article_title: "Edit Article" -# general: + general: # and: "and" or: "或" name: "名字" diff --git a/app/views/editor/thang/colors_tab_view.coffee b/app/views/editor/thang/colors_tab_view.coffee index b591e0a65..125ca2ab7 100644 --- a/app/views/editor/thang/colors_tab_view.coffee +++ b/app/views/editor/thang/colors_tab_view.coffee @@ -55,7 +55,7 @@ module.exports = class ColorsTabView extends CocoView animations = (a.animation for key, a of actionDict when a.animation) index = @offset % animations.length animation = animations[index] - return unless animation + return @updateContainer() unless animation @stage.removeChild(@movieClip) if @movieClip options = {colorConfig: {}} options.colorConfig[@currentColorGroupTreema.keyForParent] = @colorConfig @@ -69,6 +69,23 @@ module.exports = class ColorsTabView extends CocoView @movieClip.regY = @movieClip.nominalBounds.y @stage.addChild @movieClip + updateContainer: -> + actionDict = @thangType.getActions() + idle = actionDict.idle + @stage.removeChild(@container) if @container + return unless idle?.container + options = {colorConfig: {}} + options.colorConfig[@currentColorGroupTreema.keyForParent] = @colorConfig + @spriteBuilder.setOptions options + @spriteBuilder.buildColorMaps() + @container = @spriteBuilder.buildContainerFromStore idle.container + larger = Math.min(400 / @container.bounds.width, 400 / @container.bounds.height) + @container.scaleX = larger + @container.scaleY = larger + @container.regX = @container.bounds.x + @container.regY = @container.bounds.y + @stage.addChild @container + createShapeButtons: -> buttons = $('<div></div>').prop('id', 'shape-buttons') shapes = (shape for key, shape of @thangType.get('raw')?.shapes or {}) @@ -145,6 +162,7 @@ module.exports = class ColorsTabView extends CocoView shapes.push(key) if colors[shape.fc] @currentColorGroupTreema.set('/', shapes) + @updateMovieClip() class ColorGroupNode extends TreemaNode.nodeMap.array collection: false diff --git a/server/handlers/Handler.coffee b/server/handlers/Handler.coffee index 5159b7ca3..5428657bf 100644 --- a/server/handlers/Handler.coffee +++ b/server/handlers/Handler.coffee @@ -261,11 +261,11 @@ module.exports = class Handler getDocumentForIdOrSlug: (idOrSlug, done) -> idOrSlug = idOrSlug+'' - try - mongoose.Types.ObjectId.createFromHexString(idOrSlug) # throw error if not a valid ID (probably a slug) + isID = idOrSlug.length is 24 and idOrSlug.match(/[a-z0-9]/gi)?.length is 24 + if isID @modelClass.findById(idOrSlug).exec (err, document) -> done(err, document) - catch e + else @modelClass.findOne {slug: idOrSlug}, (err, document) -> done(err, document)