mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-14 05:55:00 -04:00
Fixed #69.
This commit is contained in:
parent
3e0518cd70
commit
6df5ca00b2
6 changed files with 81 additions and 68 deletions
app
lib
schemas/models
views
account
editor
|
@ -116,7 +116,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
flagThang = thangType: '53fa25f25bc220000052c2be', id: 'Placeholder Flag', components: []
|
||||
for thang in (@level.get('thangs') or []).concat [flagThang]
|
||||
thangIDs.push thang.thangType
|
||||
@loadItemThangsEquippedByLevelThang(thang)
|
||||
@loadThangsRequiredByLevelThang(thang)
|
||||
for comp in thang.components or []
|
||||
componentVersions.push _.pick(comp, ['original', 'majorVersion'])
|
||||
|
||||
|
@ -160,23 +160,27 @@ module.exports = class LevelLoader extends CocoClass
|
|||
|
||||
@worldNecessities = @worldNecessities.concat worldNecessities
|
||||
|
||||
loadItemThangsEquippedByLevelThang: (levelThang) ->
|
||||
@loadItemThangsFromComponentList levelThang.components
|
||||
loadThangsRequiredByLevelThang: (levelThang) ->
|
||||
@loadThangsRequiredFromComponentList levelThang.components
|
||||
|
||||
loadItemThangsEquippedByThangType: (thangType) ->
|
||||
@loadItemThangsFromComponentList thangType.get('components')
|
||||
loadThangsRequiredByThangType: (thangType) ->
|
||||
@loadThangsRequiredFromComponentList thangType.get('components')
|
||||
|
||||
loadItemThangsFromComponentList: (components) ->
|
||||
equipsThangComponent = _.find components, (c) -> c.original is LevelComponent.EquipsID
|
||||
inventory = equipsThangComponent?.config?.inventory
|
||||
for itemThangType in _.values inventory
|
||||
url = "/db/thang.type/#{itemThangType}/version?project=name,components,original"
|
||||
loadThangsRequiredFromComponentList: (components) ->
|
||||
requiredThangTypes = []
|
||||
for component in components when component.config
|
||||
if component.original is LevelComponent.EquipsID
|
||||
requiredThangTypes.push itemThangType for itemThangType in _.values (component.config.inventory ? {})
|
||||
else if component.config.requiredThangTypes
|
||||
requiredThangTypes = requiredThangTypes.concat component.config.requiredThangTypes
|
||||
for thangType in requiredThangTypes
|
||||
url = "/db/thang.type/#{thangType}/version?project=name,components,original"
|
||||
@worldNecessities.push @maybeLoadURL(url, ThangType, 'thang')
|
||||
|
||||
onThangNamesLoaded: (thangNames) ->
|
||||
for thangType in thangNames.models
|
||||
@loadDefaultComponentsForThangType(thangType)
|
||||
@loadItemThangsEquippedByThangType(thangType)
|
||||
@loadThangsRequiredByThangType(thangType)
|
||||
|
||||
loadDefaultComponentsForThangType: (thangType) ->
|
||||
return unless components = thangType.get('components')
|
||||
|
@ -188,7 +192,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
index = @worldNecessities.indexOf(resource)
|
||||
if resource.name is 'thang'
|
||||
@loadDefaultComponentsForThangType(resource.model)
|
||||
@loadItemThangsEquippedByThangType(resource.model)
|
||||
@loadThangsRequiredByThangType(resource.model)
|
||||
|
||||
return unless index >= 0
|
||||
@worldNecessities.splice(index, 1)
|
||||
|
|
|
@ -143,7 +143,7 @@ _.extend LevelComponentSchema.properties,
|
|||
format: 'hidden'
|
||||
dependencies: c.array {title: 'Dependencies', description: 'An array of Components upon which this Component depends.', uniqueItems: true}, DependencySchema
|
||||
propertyDocumentation: c.array {title: 'Property Documentation', description: 'An array of documentation entries for each notable property this Component will add to its Thang which other Components might want to also use.'}, PropertyDocumentationSchema
|
||||
configSchema: _.extend metaschema, {title: 'Configuration Schema', description: 'A schema for validating the arguments that can be passed to this Component as configuration.', default: {type: 'object', additionalProperties: false}}
|
||||
configSchema: _.extend metaschema, {title: 'Configuration Schema', description: 'A schema for validating the arguments that can be passed to this Component as configuration.', default: {type: 'object'}}
|
||||
official:
|
||||
type: 'boolean'
|
||||
title: 'Official'
|
||||
|
|
|
@ -82,7 +82,7 @@ module.exports = class JobProfileTreemaView extends CocoView
|
|||
{name: 'Provide your name.', weight: 1, fn: modified 'name'}
|
||||
{name: 'Choose your city.', weight: 1, fn: modified 'city'}
|
||||
{name: 'Pick your country.', weight: 0, fn: exists 'country'}
|
||||
{name: 'List at least five skills.', weight: 2, fn: -> jobProfile.skills.length >= 5}
|
||||
{name: 'List at least five skills.', weight: 2, fn: -> jobProfile.skills?.length >= 5}
|
||||
{name: 'Write a short description to summarize yourself at a glance.', weight: 2, fn: modified 'shortDescription'}
|
||||
{name: 'Fill in your main description to sell yourself and describe the work you\'re looking for.', weight: 3, fn: modified 'longDescription'}
|
||||
{name: 'List your work experience.', weight: 3, fn: listStarted 'work', ['role', 'employer']}
|
||||
|
@ -95,7 +95,7 @@ module.exports = class JobProfileTreemaView extends CocoView
|
|||
getData: ->
|
||||
return {} unless me.get('jobProfile') or @hasEditedProfile
|
||||
_.pick @jobProfileTreema.data, (value, key) => key in @editableSettings
|
||||
|
||||
|
||||
destroy: ->
|
||||
@jobProfileTreema?.destroy()
|
||||
super()
|
||||
|
|
|
@ -30,7 +30,7 @@ module.exports = class ThangComponentConfigView extends CocoView
|
|||
afterRender: ->
|
||||
super()
|
||||
@buildTreema()
|
||||
|
||||
|
||||
setConfig: (config) ->
|
||||
@handlingChange = true
|
||||
@editThangTreema.set('/', config)
|
||||
|
@ -51,7 +51,7 @@ module.exports = class ThangComponentConfigView extends CocoView
|
|||
schema = $.extend true, {}, @component.get('configSchema')
|
||||
schema.default ?= {}
|
||||
_.merge schema.default, @additionalDefaults if @additionalDefaults
|
||||
|
||||
|
||||
if @level?.get('type') is 'hero'
|
||||
schema.required = []
|
||||
treemaOptions =
|
||||
|
@ -77,6 +77,7 @@ module.exports = class ThangComponentConfigView extends CocoView
|
|||
'seconds': nodes.SecondsNode
|
||||
'speed': nodes.SpeedNode
|
||||
'acceleration': nodes.AccelerationNode
|
||||
'thang-type': nodes.ThangTypeNode
|
||||
'item-thang-type': nodes.ItemThangTypeNode
|
||||
|
||||
@editThangTreema = @$el.find('.treema').treema treemaOptions
|
||||
|
@ -92,7 +93,7 @@ module.exports = class ThangComponentConfigView extends CocoView
|
|||
@trigger 'changed', { component: @component, config: @config }
|
||||
|
||||
data: -> @editThangTreema.data
|
||||
|
||||
|
||||
destroy: ->
|
||||
@editThangTreema?.destroy()
|
||||
super()
|
||||
|
|
|
@ -33,16 +33,16 @@ module.exports = class LevelFeedbackView extends CocoView
|
|||
|
||||
getRenderData: (context={}) ->
|
||||
context = super(context)
|
||||
context.moment = moment
|
||||
context.allFeedback = []
|
||||
context.averageRating = 0
|
||||
context.totalRatings = 0
|
||||
if @allFeedback
|
||||
context.allFeedback = (m.attributes for m in @allFeedback.models when @allFeedback.models.length < 20 or m.get('review'))
|
||||
context.averageRating = _.reduce((m.get('rating') for m in @allFeedback.models), (acc, x) -> acc + (x ? 5)) / (@allFeedback.models.length or 1)
|
||||
context.averageRating = _.reduce((m.get('rating') for m in @allFeedback.models), (acc, x) -> acc + (x ? 5)) / (@allFeedback.models.length)
|
||||
context.totalRatings = @allFeedback.models.length
|
||||
else
|
||||
context.allFeedback = []
|
||||
context.averageRating = 0
|
||||
context.totalRatings = 0
|
||||
context.loading = true
|
||||
context.moment = moment
|
||||
context
|
||||
|
||||
onViewSwitched: (e) ->
|
||||
|
|
|
@ -200,6 +200,9 @@ module.exports.AccelerationNode = class AccelerationNode extends TreemaNode.node
|
|||
|
||||
module.exports.ThangTypeNode = class ThangTypeNode extends TreemaNode.nodeMap.string
|
||||
valueClass: 'treema-thang-type'
|
||||
@thangTypes: null
|
||||
@thangTypesCollection: null
|
||||
|
||||
constructor: (args...) ->
|
||||
super args...
|
||||
data = @getData()
|
||||
|
@ -223,63 +226,68 @@ module.exports.ThangTypeNode = class ThangTypeNode extends TreemaNode.nodeMap.st
|
|||
else
|
||||
@data = null
|
||||
|
||||
module.exports.ItemThangTypeNode = ItemThangTypeNode = class ItemThangTypeNode extends TreemaNode.nodeMap.string
|
||||
valueClass: 'treema-item-thang-type'
|
||||
@items: null
|
||||
@itemsCollection: null
|
||||
module.exports.ThangTypeNode = ThangTypeNode = class ThangTypeNode extends TreemaNode.nodeMap.string
|
||||
valueClass: 'treema-thang-type'
|
||||
@thangTypesCollection: null # Lives in ThangTypeNode parent class
|
||||
@thangTypes: null # Lives in ThangTypeNode or subclasses
|
||||
|
||||
constructor: ->
|
||||
super(arguments...)
|
||||
@getItems()
|
||||
unless ItemThangTypeNode.itemsCollection.loaded
|
||||
ItemThangTypeNode.itemsCollection.once('sync', @refreshDisplay, @)
|
||||
|
||||
@getThangTypes()
|
||||
unless ThangTypeNode.thangTypesCollection.loaded
|
||||
ThangTypeNode.thangTypesCollection.once('sync', @refreshDisplay, @)
|
||||
|
||||
buildValueForDisplay: (valEl, data) ->
|
||||
@buildValueForDisplaySimply(valEl, @getCurrentItem() or '')
|
||||
@buildValueForDisplaySimply(valEl, @getCurrentThangType() or '')
|
||||
valEl
|
||||
|
||||
|
||||
buildValueForEditing: (valEl, data) ->
|
||||
super(valEl, data)
|
||||
if ItemThangTypeNode.items
|
||||
source = (item.name for item in ItemThangTypeNode.items when @keyForParent in item.slots)
|
||||
input = valEl.find('input').autocomplete(source: source, minLength: 0, delay: 0, autoFocus: true)
|
||||
input.val(@getCurrentItem() or '')
|
||||
input = valEl.find 'input'
|
||||
if @constructor.thangTypes
|
||||
source = (thangType.name for thangType in @constructor.thangTypes when @filterThangType thangType)
|
||||
input.autocomplete(source: source, minLength: 0, delay: 0, autoFocus: true)
|
||||
input.val(@getCurrentThangType() or '')
|
||||
valEl
|
||||
|
||||
getCurrentItem: ->
|
||||
window.itemData = @getData()
|
||||
window.items = ItemThangTypeNode.items
|
||||
return null unless ItemThangTypeNode.items
|
||||
original = @getData()
|
||||
return null unless original
|
||||
item = _.find ItemThangTypeNode.items, { original: original }
|
||||
item?.name or '...'
|
||||
|
||||
getItems: ->
|
||||
return if ItemThangTypeNode.itemsCollection
|
||||
ItemThangTypeNode.itemsCollection = new CocoCollection([], {
|
||||
|
||||
filterThangType: (thangType) -> true
|
||||
|
||||
getCurrentThangType: ->
|
||||
return null unless @constructor.thangTypes
|
||||
return null unless original = @getData()
|
||||
thangType = _.find @constructor.thangTypes, { original: original }
|
||||
thangType?.name or '...'
|
||||
|
||||
getThangTypes: ->
|
||||
return if ThangTypeNode.thangTypesCollection
|
||||
ThangTypeNode.thangTypesCollection = new CocoCollection([], {
|
||||
url: '/db/thang.type'
|
||||
project:['name', 'components', 'original']
|
||||
model: ThangType
|
||||
})
|
||||
res = ItemThangTypeNode.itemsCollection.fetch()
|
||||
ItemThangTypeNode.itemsCollection.once 'sync', => @processItems(ItemThangTypeNode.itemsCollection)
|
||||
|
||||
processItems: (itemCollection) ->
|
||||
ItemThangTypeNode.items = []
|
||||
for itemThang in itemCollection.models
|
||||
itemComponent = _.find itemThang.get('components'), {original: LevelComponent.ItemID}
|
||||
continue unless itemComponent
|
||||
slots = itemComponent.config?.slots
|
||||
continue unless slots?.length
|
||||
ItemThangTypeNode.items.push {
|
||||
name: itemThang.get('name')
|
||||
original: itemThang.get('original')
|
||||
slots: slots
|
||||
}
|
||||
res = ThangTypeNode.thangTypesCollection.fetch()
|
||||
ThangTypeNode.thangTypesCollection.once 'sync', => @processThangTypes(ThangTypeNode.thangTypesCollection)
|
||||
|
||||
processThangTypes: (thangTypeCollection) ->
|
||||
@constructor.thangTypes = []
|
||||
@processThangType thangType for thangType in thangTypeCollection.models
|
||||
|
||||
processThangType: (thangType) ->
|
||||
@constructor.thangTypes.push name: thangType.get('name'), original: thangType.get('original')
|
||||
|
||||
saveChanges: ->
|
||||
thangTypeName = @$el.find('input').val()
|
||||
item = _.find(ItemThangTypeNode.items, {name: thangTypeName})
|
||||
return @remove() unless item
|
||||
@data = item.original
|
||||
thangType = _.find(@constructor.thangTypes, {name: thangTypeName})
|
||||
return @remove() unless thangType
|
||||
@data = thangType.original
|
||||
|
||||
module.exports.ItemThangTypeNode = ItemThangTypeNode = class ItemThangTypeNode extends ThangTypeNode
|
||||
valueClass: 'treema-item-thang-type'
|
||||
|
||||
filterThangType: (thangType) ->
|
||||
@keyForParent in thangType.slots
|
||||
|
||||
processThangType: (thangType) ->
|
||||
return unless itemComponent = _.find thangType.get('components'), {original: LevelComponent.ItemID}
|
||||
return unless itemComponent.config?.slots?.length
|
||||
@constructor.thangTypes.push name: thangType.get('name'), original: thangType.get('original'), slots: itemComponent.config.slots
|
||||
|
|
Loading…
Add table
Reference in a new issue