This commit is contained in:
commit
fad096047a
5 changed files with 81 additions and 7 deletions
app
server/handlers
|
@ -73,7 +73,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
toString: -> "<CocoSprite: #{@thang?.id}>"
|
toString: -> "<CocoSprite: #{@thang?.id}>"
|
||||||
|
|
||||||
buildSpriteSheet: ->
|
buildSpriteSheet: ->
|
||||||
options = @thang?.getSpriteOptions() or {}
|
options = @thang?.getSpriteOptions?() or {}
|
||||||
options.colorConfig = @options.colorConfig if @options.colorConfig
|
options.colorConfig = @options.colorConfig if @options.colorConfig
|
||||||
options.async = false
|
options.async = false
|
||||||
@thangType.getSpriteSheet options
|
@thangType.getSpriteSheet options
|
||||||
|
|
|
@ -65,6 +65,7 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
shortcuts:
|
shortcuts:
|
||||||
'\\': 'onToggleDebug'
|
'\\': 'onToggleDebug'
|
||||||
'g': 'onToggleGrid'
|
'g': 'onToggleGrid'
|
||||||
|
'w': 'onTogglePathFinding'
|
||||||
|
|
||||||
# external functions
|
# external functions
|
||||||
|
|
||||||
|
@ -101,6 +102,61 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
@onFrameChanged()
|
@onFrameChanged()
|
||||||
Backbone.Mediator.publish 'surface:world-set-up'
|
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) ->
|
setProgress: (progress, scrubDuration=500) ->
|
||||||
progress = Math.max(Math.min(progress, 0.99), 0.0)
|
progress = Math.max(Math.min(progress, 0.99), 0.0)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module.exports = nativeDescription: "中文", englishDescription: "Chinese", translation:
|
module.exports = nativeDescription: "中文", englishDescription: "Chinese", translation:
|
||||||
# common:
|
common:
|
||||||
# loading: "Loading..."
|
# loading: "Loading..."
|
||||||
# saving: "Saving..."
|
# saving: "Saving..."
|
||||||
sending: "在发送中。。。"
|
sending: "在发送中。。。"
|
||||||
|
@ -243,7 +243,7 @@ module.exports = nativeDescription: "中文", englishDescription: "Chinese", tra
|
||||||
# edit_btn_preview: "Preview"
|
# edit_btn_preview: "Preview"
|
||||||
# edit_article_title: "Edit Article"
|
# edit_article_title: "Edit Article"
|
||||||
|
|
||||||
# general:
|
general:
|
||||||
# and: "and"
|
# and: "and"
|
||||||
or: "或"
|
or: "或"
|
||||||
name: "名字"
|
name: "名字"
|
||||||
|
|
|
@ -55,7 +55,7 @@ module.exports = class ColorsTabView extends CocoView
|
||||||
animations = (a.animation for key, a of actionDict when a.animation)
|
animations = (a.animation for key, a of actionDict when a.animation)
|
||||||
index = @offset % animations.length
|
index = @offset % animations.length
|
||||||
animation = animations[index]
|
animation = animations[index]
|
||||||
return unless animation
|
return @updateContainer() unless animation
|
||||||
@stage.removeChild(@movieClip) if @movieClip
|
@stage.removeChild(@movieClip) if @movieClip
|
||||||
options = {colorConfig: {}}
|
options = {colorConfig: {}}
|
||||||
options.colorConfig[@currentColorGroupTreema.keyForParent] = @colorConfig
|
options.colorConfig[@currentColorGroupTreema.keyForParent] = @colorConfig
|
||||||
|
@ -69,6 +69,23 @@ module.exports = class ColorsTabView extends CocoView
|
||||||
@movieClip.regY = @movieClip.nominalBounds.y
|
@movieClip.regY = @movieClip.nominalBounds.y
|
||||||
@stage.addChild @movieClip
|
@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: ->
|
createShapeButtons: ->
|
||||||
buttons = $('<div></div>').prop('id', 'shape-buttons')
|
buttons = $('<div></div>').prop('id', 'shape-buttons')
|
||||||
shapes = (shape for key, shape of @thangType.get('raw')?.shapes or {})
|
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]
|
shapes.push(key) if colors[shape.fc]
|
||||||
|
|
||||||
@currentColorGroupTreema.set('/', shapes)
|
@currentColorGroupTreema.set('/', shapes)
|
||||||
|
@updateMovieClip()
|
||||||
|
|
||||||
class ColorGroupNode extends TreemaNode.nodeMap.array
|
class ColorGroupNode extends TreemaNode.nodeMap.array
|
||||||
collection: false
|
collection: false
|
||||||
|
|
|
@ -261,11 +261,11 @@ module.exports = class Handler
|
||||||
|
|
||||||
getDocumentForIdOrSlug: (idOrSlug, done) ->
|
getDocumentForIdOrSlug: (idOrSlug, done) ->
|
||||||
idOrSlug = idOrSlug+''
|
idOrSlug = idOrSlug+''
|
||||||
try
|
isID = idOrSlug.length is 24 and idOrSlug.match(/[a-z0-9]/gi)?.length is 24
|
||||||
mongoose.Types.ObjectId.createFromHexString(idOrSlug) # throw error if not a valid ID (probably a slug)
|
if isID
|
||||||
@modelClass.findById(idOrSlug).exec (err, document) ->
|
@modelClass.findById(idOrSlug).exec (err, document) ->
|
||||||
done(err, document)
|
done(err, document)
|
||||||
catch e
|
else
|
||||||
@modelClass.findOne {slug: idOrSlug}, (err, document) ->
|
@modelClass.findOne {slug: idOrSlug}, (err, document) ->
|
||||||
done(err, document)
|
done(err, document)
|
||||||
|
|
||||||
|
|
Reference in a new issue