mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-27 14:33:59 -04:00
Re-enabled spell tab entry docs.
This commit is contained in:
parent
d33c39c21e
commit
9a835ffc0a
4 changed files with 48 additions and 14 deletions
app/views/play/level/tome
server
|
@ -1,6 +1,9 @@
|
|||
SpellListEntryView = require './spell_list_entry_view'
|
||||
ThangAvatarView = require 'views/play/level/thang_avatar_view'
|
||||
template = require 'templates/play/level/tome/spell_list_tab_entry'
|
||||
popoverTemplate = require 'templates/play/level/tome/spell_palette_entry_popover'
|
||||
LevelComponent = require 'models/LevelComponent'
|
||||
{downTheChain} = require 'lib/world/world_utils'
|
||||
|
||||
module.exports = class SpellListTabEntryView extends SpellListEntryView
|
||||
template: template
|
||||
|
@ -47,17 +50,50 @@ module.exports = class SpellListTabEntryView extends SpellListEntryView
|
|||
@avatar.render()
|
||||
|
||||
buildDocs: ->
|
||||
# TODO
|
||||
#doc = Docs.getDocsFor(@thang, [@spell.name])[0]
|
||||
#@$el.find('code').attr('title', doc.title()).popover(
|
||||
# animation: true
|
||||
# html: true
|
||||
# placement: 'bottom'
|
||||
# trigger: 'hover'
|
||||
# content: doc.html()
|
||||
# container: @$el.parent()
|
||||
#)
|
||||
@docsBuilt = true
|
||||
lcs = @supermodel.getModels LevelComponent
|
||||
found = false
|
||||
for lc in lcs when not found
|
||||
for doc in lc.get('propertyDocumentation') ? []
|
||||
if doc.name is @spell.name
|
||||
found = true
|
||||
break
|
||||
return unless found
|
||||
doc.owner = 'this'
|
||||
doc.shortName = doc.shorterName = doc.title = "this.#{doc.name}();"
|
||||
@$el.popover(
|
||||
animation: true
|
||||
html: true
|
||||
placement: 'bottom'
|
||||
trigger: 'hover'
|
||||
content: @formatPopover doc
|
||||
container: @$el.parent()
|
||||
)
|
||||
|
||||
formatPopover: (doc) ->
|
||||
content = popoverTemplate doc: doc, marked: marked, argumentExamples: (arg.example or arg.default or arg.name for arg in doc.args ? [])
|
||||
owner = @thang
|
||||
content = content.replace /#{spriteName}/g, @thang.spriteName # No quotes like we'd get with @formatValue
|
||||
content.replace /\#\{(.*?)\}/g, (s, properties) => @formatValue downTheChain(owner, properties.split('.'))
|
||||
|
||||
formatValue: (v) ->
|
||||
# TODO: refactor and move spell_palette_entry_view version of this somewhere else
|
||||
# maybe think about making it common with what Aether does and the SpellDebugView, too
|
||||
if _.isNumber v
|
||||
if v == Math.round v
|
||||
return v
|
||||
return v.toFixed 2
|
||||
if _.isString v
|
||||
return "\"#{v}\""
|
||||
if v?.id
|
||||
return v.id
|
||||
if v?.name
|
||||
return v.name
|
||||
if _.isArray v
|
||||
return '[' + (@formatValue v2 for v2 in v).join(', ') + ']'
|
||||
if _.isPlainObject v
|
||||
return safeJSONStringify v, 2
|
||||
v
|
||||
|
||||
onMouseEnterAvatar: (e) -> # Don't call super
|
||||
onMouseLeaveAvatar: (e) -> # Don't call super
|
||||
|
|
|
@ -30,7 +30,6 @@ module.exports = class SpellPaletteView extends View
|
|||
|
||||
props = @thang.programmableProperties ? []
|
||||
snippets = @thang.programmableSnippets ? []
|
||||
console.log "yo got snippets", snippets
|
||||
shortenize = props.length + snippets.length > 6
|
||||
@entries = []
|
||||
@entries.push @addEntry(allDocs[prop] ? prop, shortenize) for prop in props
|
||||
|
|
|
@ -142,8 +142,7 @@ me.FunctionArgumentSchema = me.object {
|
|||
type: "object"
|
||||
example: "this.getNearestEnemy()"
|
||||
description: "The target of this function."
|
||||
"default": null
|
||||
required: ['name', 'type', 'example', 'description', 'default']
|
||||
required: ['name', 'type', 'example', 'description']
|
||||
},
|
||||
name: {type: 'string', pattern: me.identifierPattern, title: "Name", description: "Name of the function argument."}
|
||||
# not actual JS types, just whatever they describe...
|
||||
|
|
|
@ -20,7 +20,7 @@ PropertyDocumentationSchema = c.object {
|
|||
"default":
|
||||
name: "foo"
|
||||
type: "object"
|
||||
description: "This Component provides a 'foo' property to satisfy all one's foobar needs. Use it wisely."
|
||||
description: 'The `foo` property can satisfy all the #{spriteName}\'s foobar needs. Use it wisely.'
|
||||
required: ['name', 'type', 'description']
|
||||
},
|
||||
name: {type: 'string', title: "Name", description: "Name of the property."}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue