Merge branch 'master' into production

This commit is contained in:
Nick Winter 2014-11-12 11:02:10 -08:00
commit 0f4290078c
3 changed files with 30 additions and 13 deletions
app
server/levels/components

View file

@ -339,9 +339,10 @@ module.exports = class ThangType extends CocoModel
unless itemConfig = _.find(components, original: LevelComponent.ItemID)?.config unless itemConfig = _.find(components, original: LevelComponent.ItemID)?.config
console.warn @get('name'), 'is not an item, but you are asking for its stats.' console.warn @get('name'), 'is not an item, but you are asking for its stats.'
return props: [], stats: {} return props: [], stats: {}
stats = {}
props = itemConfig.programmableProperties ? [] props = itemConfig.programmableProperties ? []
props = props.concat itemConfig.moreProgrammableProperties ? [] props = props.concat itemConfig.moreProgrammableProperties ? []
stats = {} props = _.without props, 'canCast', 'spellNames', 'spells'
for stat, modifiers of itemConfig.stats ? {} for stat, modifiers of itemConfig.stats ? {}
stats[stat] = @formatStatDisplay stat, modifiers stats[stat] = @formatStatDisplay stat, modifiers
for stat in itemConfig.extraHUDProperties ? [] for stat in itemConfig.extraHUDProperties ? []

View file

@ -12,41 +12,47 @@ module.exports = class ItemDetailsView extends CocoView
constructor: -> constructor: ->
super(arguments...) super(arguments...)
@propDocs = {} @propDocs = {}
@spellDocs = {}
setItem: (@item) -> setItem: (@item) ->
if @item if @item
@spellDocs = {}
@item.name = utils.i18n @item.attributes, 'name' @item.name = utils.i18n @item.attributes, 'name'
@item.affordable = me.gems() >= @item.get('gems') @item.affordable = me.gems() >= @item.get('gems')
@item.owned = me.ownsItem @item.get('original') @item.owned = me.ownsItem @item.get('original')
@item.comingSoon = not @item.getFrontFacingStats().props.length and not _.size @item.getFrontFacingStats().stats # Temp: while there are placeholder items @item.comingSoon = not @item.getFrontFacingStats().props.length and not _.size @item.getFrontFacingStats().stats # Temp: while there are placeholder items
stats = @item.getFrontFacingStats() stats = @item.getFrontFacingStats()
props = (p for p in stats.props when not @propDocs[p]) props = (p for p in stats.props when not @propDocs[p])
if props.length > 0 if props.length > 0 or ('cast' in stats.props)
docs = new CocoCollection([], { docs = new CocoCollection([], {
url: '/db/level.component?view=prop-doc-lookup' url: '/db/level.component?view=prop-doc-lookup'
model: LevelComponent model: LevelComponent
project: [ project: [
'name'
'propertyDocumentation.name' 'propertyDocumentation.name'
'propertyDocumentation.description' 'propertyDocumentation.description'
'propertyDocumentation.i18n' 'propertyDocumentation.i18n'
] ]
}) })
docs.fetch({ data: { docs.fetch({ data: {
componentOriginals: [c.original for c in @item.get('components')].join(',') componentOriginals: [c.original for c in @item.get('components')].join(',')
propertyNames: props.join(',') propertyNames: props.join(',')
}}) }})
@listenToOnce docs, 'sync', @onDocsLoaded @listenToOnce docs, 'sync', @onDocsLoaded
@render() @render()
@$el.find('.nano:visible').nanoScroller() @$el.find('.nano:visible').nanoScroller()
onDocsLoaded: (levelComponents) -> onDocsLoaded: (levelComponents) ->
for component in levelComponents.models for component in levelComponents.models
for propDoc in component.get('propertyDocumentation') for propDoc in component.get('propertyDocumentation')
@propDocs[propDoc.name] = propDoc if /^cast.+/.test propDoc.name
@spellDocs[propDoc.name] = propDoc
else
@propDocs[propDoc.name] = propDoc
@render() @render()
getRenderData: -> getRenderData: ->
@ -57,20 +63,27 @@ module.exports = class ItemDetailsView extends CocoView
c.stats = _.values(stats.stats) c.stats = _.values(stats.stats)
_.last(c.stats).isLast = true if c.stats.length _.last(c.stats).isLast = true if c.stats.length
c.props = [] c.props = []
progLang = (me.get('aceConfig') ? {}).language or 'python' stats.props = stats.props.concat _.keys @spellDocs
codeLanguage = (me.get('aceConfig') ? {}).language or 'python'
for prop in stats.props for prop in stats.props
description = utils.i18n @propDocs[prop] ? {}, 'description' doc = @propDocs[prop] ? @spellDocs[prop] ? {}
description = utils.i18n doc, 'description'
if _.isObject description if _.isObject description
description = description[progLang] or _.values(description)[0] description = description[codeLanguage] or _.values(description)[0]
if _.isString description if _.isString description
description = description.replace(/#{spriteName}/g, 'hero') description = description.replace(/#{spriteName}/g, 'hero')
if fact = stats.stats.shieldDefenseFactor if fact = stats.stats.shieldDefenseFactor
description = description.replace(/#{shieldDefensePercent}%/g, fact.display) description = description.replace(/#{shieldDefensePercent}%/g, fact.display)
## We don't have the full components loaded here, so we can't really get most of these values.
#description = description.replace /#{([^.]+?)}/g, (match, keyChain) ->
# console.log 'gotta find', keyChain, 'from', match, 'and have', stats
# match
description = description.replace(/#{(.+?)}/g, '`$1`')
description = $(marked(description)).html() description = $(marked(description)).html()
c.props.push { c.props.push {
name: prop name: _.string.humanize prop
description: description or '...' description: description or '...'
} }
c c

View file

@ -37,9 +37,12 @@ LevelComponentHandler = class LevelComponentHandler extends Handler
properties = req.query.propertyNames.split(',') properties = req.query.propertyNames.split(',')
catch e catch e
return @sendBadInputError(res, 'Could not parse componentOriginals or propertyNames.') return @sendBadInputError(res, 'Could not parse componentOriginals or propertyNames.')
query['original'] = {$in: components} query['original'] = {$in: components}
query['propertyDocumentation.name'] = {$in: properties} query.$or = [
{'propertyDocumentation.name': {$in: properties}}
{'propertyDocumentation.name': {$regex: /^cast.+/}}
]
q = LevelComponent.find(query, projection) q = LevelComponent.find(query, projection)
q.exec (err, documents) => q.exec (err, documents) =>