This commit is contained in:
GlenDC 2014-01-21 18:01:58 +01:00
commit c12e232ec1
19 changed files with 98 additions and 39 deletions

View file

@ -218,7 +218,7 @@ module.exports = class Camera extends CocoClass
updateZoom: (force=false) ->
# Update when we're focusing on a Thang, tweening, or forcing it, unless we're locked
return if @locked or (not force and not @newTarget and not @target?.name)
return if (not force) and (@locked or (not @newTarget and not @target?.name))
if @newTarget
t = @tweenProgress
@zoom = @oldZoom + t * (@newZoom - @oldZoom)

View file

@ -61,9 +61,19 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
@actionQueue = []
@marks = {}
@labels = {}
@ticker = 0
@displayObject = new createjs.Container()
if @thangType.get('actions')
@onThangTypeLoaded()
else
@stillLoading = true
@thangType.fetch()
@thangType.once 'sync', @onThangTypeLoaded, @
onThangTypeLoaded: ->
@stillLoading = false
@actions = @thangType.getActions()
@buildFromSpriteSheet @buildSpriteSheet()
@ticker = 0
destroy: ->
super()
@ -87,7 +97,6 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
# temp, until these are re-exported with perspective
if @options.camera and @thangType.get('name') in ['Dungeon Floor', 'Grass', 'Goal Trigger', 'Obstacle']
sprite.scaleY *= @options.camera.y2x
@displayObject = new createjs.Container()
@imageObject = sprite
@displayObject.addChild(sprite)
@addHealthBar()
@ -135,6 +144,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
update: ->
# Gets the sprite to reflect what the current state of the thangs and surface are
return if @stillLoading
@updatePosition()
@updateScale()
@updateAlpha()

View file

@ -230,7 +230,7 @@ module.exports = class SpriteBoss extends CocoClass
@selectedSprite = sprite
alive = sprite?.thang.health > 0
Backbone.Mediator.publish "surface:sprite-selected",
Backbone.Mediator.publish 'surface:sprite-selected',
thang: if sprite then sprite.thang else null
sprite: sprite
spellName: spellName ? e?.spellName

View file

@ -114,6 +114,7 @@ module.exports = Surface = class Surface extends CocoClass
showPathFinding: ->
@hidePathFinding()
mesh = _.values(@world.navMeshes or {})[0]
return unless mesh
@navRectangles = new createjs.Container()
@ -121,10 +122,12 @@ module.exports = Surface = class Surface extends CocoClass
@addMeshRectanglesToContainer mesh, @navRectangles
@surfaceLayer.addChild @navRectangles
@surfaceLayer.updateLayerOrder()
return @surfaceLayer.updateLayerOrder() unless @world.graph
graph = _.values(@world.graphs or {})[0]
return @surfaceLayer.updateLayerOrder() unless graph
@navPaths = new createjs.Container()
@navPaths.layerPriority = -1
@addNavPathsToContainer @world.graph, @navPaths
@addNavPathsToContainer graph, @navPaths
@surfaceLayer.addChild @navPaths
@surfaceLayer.updateLayerOrder()

View file

@ -68,6 +68,7 @@ class Rectangle
distanceSquaredToPoint: (p) ->
# Doesn't handle rotation; just supposed to be faster than distanceToPoint
p = Vector.subtract(p, @getPos())
dx = Math.max(Math.abs(p.x) - @width / 2, 0)
dy = Math.max(Math.abs(p.y) - @height / 2, 0)
dx * dx + dy * dy

View file

@ -22,12 +22,13 @@ module.exports = class ThangType extends CocoModel
resetSpriteSheetCache: ->
@buildActions()
@spriteSheets = {}
@building = {}
getActions: ->
return @actions or @buildActions()
buildActions: ->
@actions = _.cloneDeep(@get('actions'))
@actions = _.cloneDeep(@get('actions') or {})
for name, action of @actions
action.name = name
for relatedName, relatedAction of action.relatedActions ? {}
@ -138,10 +139,12 @@ module.exports = class ThangType extends CocoModel
console.warn 'Building', @get('name'), 'and blocking the main thread.'
spriteSheet = @builder.build()
@spriteSheets[key] = spriteSheet
delete @building[key]
spriteSheet
onBuildSpriteSheetComplete: (e, key) ->
@spriteSheets[key] = e.target.spriteSheet
delete @building[key]
@trigger 'build-complete'
@builder = null
@vectorParser = null

View file

@ -58,6 +58,17 @@
h3
margin: 0 -20px 0 0
width: 100%
h4
margin: 0 0 10px
clear: both
padding: 5px
background: rgba(150, 150, 150, 0.5)
width: $addPaletteWidth - 20px
box-sizing: border-box
.clearfix
margin-bottom: 20px
.add-thang-palette-icon
position: relative

View file

@ -66,7 +66,7 @@
background-color: white
border-radius: 4px
#canvases
#spritesheets
border: 1px solid green
max-width: 100%
max-height: 600px

View file

@ -12,9 +12,11 @@
.add-thangs-palette.thangs-column
h3(data-i18n="editor.level_tab_thangs_add") Add Thangs
#thangs-list
for thangType in thangTypes
div.add-thang-palette-icon(data-thang-type=thangType.name)
- path = '/file/db/thang.type/'+thangType.original+'/portrait.png'
img(title="Add " + thangType.name, src=path, alt="")
for group in groups
h4= group.name
for thangType in group.thangs
div.add-thang-palette-icon(data-thang-type=thangType.name)
- path = '/file/db/thang.type/'+thangType.original+'/portrait.png'
img(title="Add " + thangType.name, src=path, alt="")
div.clearfix
#editor-level-thang-edit.hide

View file

@ -15,7 +15,7 @@ block content
li
a(href="#editor-thang-components-tab-view", data-toggle="tab") Components
li
a(href="#editor-thang-canvases-view", data-toggle="tab") Canvases
a(href="#editor-thang-spritesheets-view", data-toggle="tab") Spritesheets
li
a(href="#editor-thang-colors-tab-view", data-toggle="tab")#color-tab Colors
@ -68,8 +68,8 @@ block content
#thang-components-edit-view
div.tab-pane#editor-thang-canvases-view
div.tab-pane#editor-thang-spritesheets-view
div#canvases
div#spritesheets
.clearfix

View file

@ -7,6 +7,7 @@ table.table
|: #{documents.length}
tr
th#portrait-col
th(data-i18n="general.name") Name
th(data-i18n="general.description") Description
th(data-i18n="general.version") Version
@ -14,6 +15,9 @@ table.table
for data in documents
- data = data.attributes;
tr
td
- path = '/file/db/thang.type/'+data.original+'/portrait.png'
img(title="Add " + data.name, src=path, alt="").portrait
td
a(href="/editor/thang/#{data.slug || data._id}")
| #{data.name}

View file

@ -19,7 +19,7 @@ componentOriginals =
"physics.Physical" : "524b75ad7fc0f6d519000001"
class ThangTypeSearchCollection extends CocoCollection
url: '/db/thang_type/search'
url: '/db/thang_type/search?project=true'
model: ThangType
module.exports = class ThangsTabView extends View
@ -63,7 +63,24 @@ module.exports = class ThangsTabView extends View
getRenderData: (context={}) =>
context = super(context)
context.thangTypes = (thangType.attributes for thangType in @supermodel.getModels(ThangType) when not _.isEmpty thangType.get('actions'))
thangTypes = (thangType.attributes for thangType in @supermodel.getModels(ThangType))
thangTypes = _.uniq thangTypes, false, 'original'
groupMap = {}
for thangType in thangTypes
groupMap[thangType.kind] ?= []
groupMap[thangType.kind].push thangType
groups = []
for groupName in Object.keys(groupMap).sort()
someThangTypes = groupMap[groupName]
someThangTypes = _.sortBy someThangTypes, 'name'
group =
name: groupName
thangs: someThangTypes
groups.push group
context.thangTypes = thangTypes
context.groups = groups
context
afterRender: ->
@ -325,7 +342,7 @@ module.exports = class ThangsTabView extends View
physical.config.pos = x: pos.x, y: pos.y, z: physical.config.pos.z if physical
thang = thangType: thangType.get('original'), id: thangID, components: components
@thangsTreema.insert '', thang
@supermodel.populateModel @level # Make sure we grab any new data for the thang we just added
@supermodel.populateModel thangType # Make sure we grab any new data for the thang we just added
editThang: (e) ->
if e.target # click event
@ -351,19 +368,21 @@ class ThangsNode extends TreemaNode.nodeMap.array
valueClass: 'treema-array-replacement'
getChildren: ->
children = super(arguments...)
# uncomment this if you want to hide all the walls in the the thangs treema
#children = (c for c in children when not _.string.startsWith(c[1].thangType, 'dungeon_wall'))
# TODO: add some filtering to only work with certain types of units at a time
return children
class ThangNode extends TreemaObjectNode
valueClass: 'treema-thang'
collection: false
@thangNameMap: {}
buildValueForDisplay: (valEl) ->
pos = _.find(@data.components, (c) -> c.config?.pos?)?.config.pos # TODO: hack
s = "#{@data.thangType}"
if isObjectID s
thangType = _.find @settings.supermodel.getModels(ThangType), (m) -> m.get('original') is s
s = thangType.get('name')
unless name = ThangNode.thangNameMap[s]
thangType = _.find @settings.supermodel.getModels(ThangType), (m) -> m.get('original') is s
name = ThangNode.thangNameMap[s] = thangType.get 'name'
s = name
s += " - " + @data.id if @data.id isnt s
if pos
s += " (#{Math.round(pos.x)}, #{Math.round(pos.y)})"

View file

@ -188,10 +188,10 @@ module.exports = class ThangTypeEditView extends View
options = @getSpriteOptions()
@thangType.resetSpriteSheetCache()
spriteSheet = @thangType.buildSpriteSheet(options)
$('#canvases').empty()
$('#spritesheets').empty()
return unless spriteSheet
for image in spriteSheet._images
$('#canvases').append(image)
$('#spritesheets').append(image)
@showAnimation()
@updatePortrait()

View file

@ -5,8 +5,8 @@ app = require('application')
class SearchCollection extends Backbone.Collection
initialize: (modelURL, @model, @term) ->
@url = "#{modelURL}/search"
@url += "?term=#{term}&project=yes" if @term
@url = "#{modelURL}/search?project=yes"
@url += "&term=#{term}" if @term
module.exports = class ThangTypeHomeView extends View
template: template

View file

@ -87,7 +87,11 @@ module.exports = class PlayLevelView extends View
setLevel: (@level, @supermodel) ->
@god?.level = @level.serialize @supermodel
@load()
if @world
serializedLevel = @level.serialize(@supermodel)
@world.loadFromLevel serializedLevel, false
else
@load()
load: ->
@levelLoader = new LevelLoader(@levelID, @supermodel, @sessionID)

View file

@ -46,20 +46,20 @@
"mongoose": "3.6.x",
"mongoose-text-search": "~0.0.2",
"request": "2.12.x",
"tv4": "",
"tv4": "1.0.x",
"lodash": "~2.0.0",
"underscore.string": "2.3.x",
"async": "0.2.x",
"connect": "2.7.x",
"nodemailer": "0.4.x",
"coffee-script": "",
"coffee-script": "1.6.x",
"graceful-fs": "~2.0.1",
"node-force-domain": "~0.1.0",
"mailchimp-api": "",
"mailchimp-api": "2.0.x",
"express-useragent": "~0.0.9",
"gridfs-stream": "",
"stream-buffers": "",
"sendwithus": ""
"gridfs-stream": "0.4.x",
"stream-buffers": "0.2.x",
"sendwithus": "2.0.x"
},
"devDependencies": {
"jade": "0.33.x",
@ -73,7 +73,7 @@
"clean-css-brunch": "> 1.0 < 1.8",
"auto-reload-brunch": "> 1.0 < 1.8",
"brunch": "~1.7.4",
"jasmine-node": "",
"jasmine-node": "1.12.x",
"nodemon": "0.7.5",
"marked": "0.2.x",
"telepath-brunch": "https://github.com/nwinter/telepath-brunch/tarball/master",

View file

@ -92,7 +92,7 @@ module.exports = class Handler
unless @modelClass.schema.uses_coco_search
return @sendNotFoundError(res)
project = {original:1, name:1, version:1, description: 1, slug:1}
project = {original:1, name:1, version:1, description: 1, slug:1, kind: 1}
term = req.query.term
matchedObjects = []
filters = [{filter: {index: true}}]
@ -114,7 +114,7 @@ module.exports = class Handler
@modelClass.textSearch term, filter, callback
else
args = [filter.filter]
args.push filter.project if req.query.project
args.push project if req.query.project
@modelClass.find(args...).limit(100).exec callback
versions: (req, res, id) ->

View file

@ -18,8 +18,9 @@ ThangTypeHandler = class ThangTypeHandler extends Handler
'scale',
'positions',
'snap',
'components'
'colorGroups'
'components',
'colorGroups',
'kind'
]
hasAccess: (req) ->

View file

@ -105,6 +105,7 @@ _.extend ThangTypeSchema.properties,
shapes: c.object {title: 'Shapes', additionalProperties: ShapeObjectSchema}
containers: c.object {title: 'Containers', additionalProperties: ContainerObjectSchema}
animations: c.object {title: 'Animations', additionalProperties: RawAnimationObjectSchema}
kind: c.shortString { enum: ['Unit', 'Floor', 'Wall', 'Doodad', 'Misc'], default: 'Misc', title: 'Kind' }
actions: c.object { title: 'Actions', additionalProperties: { $ref: '#/definitions/action' } }
soundTriggers: c.object { title: "Sound Triggers", additionalProperties: c.array({}, { $ref: '#/definitions/sound' }) },