Add support for optional arguments, and web components

Refactor

Don't use globals in template
This commit is contained in:
Phoenix Eliot 2016-08-16 12:36:38 -07:00
parent 07f6f98c24
commit a1b012c7f5
6 changed files with 68 additions and 31 deletions

View file

@ -767,6 +767,8 @@
current_value: "Current Value"
default_value: "Default value"
parameters: "Parameters"
required_parameters: "Required Parameters"
optional_parameters: "Optional Parameters"
returns: "Returns"
granted_by: "Granted by"

View file

@ -165,6 +165,7 @@ me.FunctionArgumentSchema = me.object {
'default':
name: 'target'
type: 'object'
optional: false
example: 'this.getNearestEnemy()'
description: 'The target of this function.'
required: ['name', 'type', 'example', 'description']
@ -173,6 +174,7 @@ me.FunctionArgumentSchema = me.object {
i18n: { type: 'object', format: 'i18n', props: ['description'], description: 'Help translate this argument'}
# not actual JS types, just whatever they describe...
type: me.shortString(title: 'Type', description: 'Intended type of the argument.')
optional: {title: 'Optional', description: 'Whether an argument may be omitted when calling the function', type: 'boolean'}
example:
oneOf: [
{

View file

@ -95,7 +95,7 @@ if !selectedMethod
else if language == 'io'
span= (doc.ownerName == 'this' ? '' : doc.ownerName + ' ') + docName + '(' + argumentExamples.join(', ') + ')'
if (doc.type != 'function' && doc.type != 'snippet' && doc.owner != 'HTML' && doc.owner != 'CSS') || doc.name == 'now'
if (doc.type != 'function' && doc.type != 'snippet' && !_.contains(['HTML', 'CSS', 'WebJavaScript', 'jQuery'], doc.owner)) || doc.name == 'now'
p.value
strong
span(data-i18n="skill_docs.current_value") Current Value
@ -103,12 +103,7 @@ if (doc.type != 'function' && doc.type != 'snippet' && doc.owner != 'HTML' && do
pre
code.current-value(data-prop=doc.name)= value
if doc.args && doc.args.length
p.args
strong
span(data-i18n="skill_docs.parameters") Parameters
span.spr :
for arg in doc.args
mixin argumentEntry(arg)
div
code= arg.name
span.spr :
@ -128,6 +123,28 @@ if doc.args && doc.args.length
span.spr :
code= arg.default
if doc.args && doc.args.length
- var hasOptionalArguments = _.any(doc.args, function(arg){ return arg.optional })
p.args
strong
if hasOptionalArguments
span(data-i18n="skill_docs.required_parameters") Required Parameters
else
span(data-i18n="skill_docs.parameters") Parameters
span.spr :
for arg in doc.args
unless arg.optional
+argumentEntry(arg)
if hasOptionalArguments
p.args
strong
span(data-i18n="skill_docs.optional_parameters") Optional Parameters
span.spr :
for arg in doc.args
if arg.optional
+argumentEntry(arg)
if doc.returns
p.returns
strong

View file

@ -49,7 +49,7 @@ module.exports = class DocFormatter
@doc.type = 'snippet'
@doc.owner = 'snippets'
@doc.shortName = @doc.shorterName = @doc.title = @doc.name
else if @doc.owner in ['HTML', 'CSS']
else if @doc.owner in ['HTML', 'CSS', 'WebJavaScript', 'jQuery']
@doc.shortName = @doc.shorterName = @doc.title = @doc.name
else
@doc.owner ?= 'this'
@ -165,7 +165,19 @@ module.exports = class DocFormatter
[docName, args] = @getDocNameAndArguments()
argumentExamples = (arg.example or arg.default or arg.name for arg in @doc.args ? [])
argumentExamples.unshift args[0] if args.length > argumentExamples.length
content = popoverTemplate doc: @doc, docName: docName, language: @options.language, value: @formatValue(), marked: marked, argumentExamples: argumentExamples, writable: @options.writable, selectedMethod: @options.selectedMethod, cooldowns: @inferCooldowns(), item: @options.item
content = popoverTemplate {
doc: @doc
docName: docName
language: @options.language
value: @formatValue()
marked: marked
argumentExamples: argumentExamples
writable: @options.writable
selectedMethod: @options.selectedMethod
cooldowns: @inferCooldowns()
item: @options.item
_: _
}
owner = if @doc.owner is 'this' then @options.thang else window[@doc.owner]
content = @replaceSpriteName content
content = content.replace /\#\{(.*?)\}/g, (s, properties) => @formatValue downTheChain(owner, properties.split('.'))

View file

@ -157,6 +157,8 @@ module.exports = class SpellPaletteView extends CocoView
LoDash: 'programmableLoDashProperties'
Vector: 'programmableVectorProperties'
HTML: 'programmableHTMLProperties'
WebJavaScript: 'programmableWebJavaScriptProperties'
jQuery: 'programmableJQueryProperties'
CSS: 'programmableCSSProperties'
snippets: 'programmableSnippets'
else
@ -197,7 +199,7 @@ module.exports = class SpellPaletteView extends CocoView
return 'more' if entry.doc.owner is 'this' and entry.doc.name in (propGroups.more ? [])
entry.doc.owner
@entries = _.sortBy @entries, (entry) ->
order = ['this', 'more', 'Math', 'Vector', 'String', 'Object', 'Array', 'Function', 'HTML', 'CSS', 'snippets']
order = ['this', 'more', 'Math', 'Vector', 'String', 'Object', 'Array', 'Function', 'HTML', 'CSS', 'WebJavaScript', 'jQuery', 'snippets']
index = order.indexOf groupForEntry entry
index = String.fromCharCode if index is -1 then order.length else index
index += entry.doc.name
@ -248,7 +250,7 @@ module.exports = class SpellPaletteView extends CocoView
console.log @thang.id, "couldn't find item ThangType for", slot, thangTypeName
# Get any Math-, Vector-, etc.-owned properties into their own tabs
for owner, storage of propStorage when not (owner in ['this', 'more', 'snippets', 'HTML', 'CSS'])
for owner, storage of propStorage when not (owner in ['this', 'more', 'snippets', 'HTML', 'CSS', 'WebJavaScript', 'jQuery'])
continue unless @thang[storage]?.length
@tabs ?= {}
@tabs[owner] = []
@ -262,7 +264,7 @@ module.exports = class SpellPaletteView extends CocoView
# Assign any unassigned properties to the hero itself.
for owner, storage of propStorage
continue unless owner in ['this', 'more', 'snippets', 'HTML', 'CSS']
continue unless owner in ['this', 'more', 'snippets', 'HTML', 'CSS', 'WebJavaScript', 'jQuery']
for prop in _.reject(@thang[storage] ? [], (prop) -> itemsByProp[prop] or prop[0] is '_') # no private properties
continue if prop is 'say' and @options.level.get 'hidesSay' # Hide for Dungeon Campaign
continue if prop is 'moveXY' and @options.level.get('slug') is 'slalom' # Hide for Slalom

View file

@ -229,11 +229,13 @@ module.exports = class TomeView extends CocoView
return null unless hero = _.find @options.level.get('thangs'), id: 'Hero Placeholder'
return null unless programmableConfig = _.find(hero.components, (component) -> component.config?.programmableMethods).config
usesHTMLConfig = _.find(hero.components, (component) -> component.config?.programmableHTMLProperties).config
usesWebJavaScriptConfig = _.find(hero.components, (component) -> component.config?.programmableWebJavaScriptProperties)?.config
usesJQueryConfig = _.find(hero.components, (component) -> component.config?.programmableJQueryProperties)?.config
console.warn "Couldn't find usesHTML config; is it presented and not defaulted on the Hero Placeholder?" unless usesHTMLConfig
thang =
id: 'Hero Placeholder'
isProgrammable: true
thang = _.merge thang, programmableConfig, usesHTMLConfig
thang = _.merge thang, programmableConfig, usesHTMLConfig, usesWebJavaScriptConfig, usesJQueryConfig
thang
destroy: ->