mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-01 07:54:11 -05:00
Add support for optional arguments, and web components
Refactor Don't use globals in template
This commit is contained in:
parent
07f6f98c24
commit
a1b012c7f5
6 changed files with 68 additions and 31 deletions
|
@ -767,6 +767,8 @@
|
||||||
current_value: "Current Value"
|
current_value: "Current Value"
|
||||||
default_value: "Default value"
|
default_value: "Default value"
|
||||||
parameters: "Parameters"
|
parameters: "Parameters"
|
||||||
|
required_parameters: "Required Parameters"
|
||||||
|
optional_parameters: "Optional Parameters"
|
||||||
returns: "Returns"
|
returns: "Returns"
|
||||||
granted_by: "Granted by"
|
granted_by: "Granted by"
|
||||||
|
|
||||||
|
|
|
@ -165,6 +165,7 @@ me.FunctionArgumentSchema = me.object {
|
||||||
'default':
|
'default':
|
||||||
name: 'target'
|
name: 'target'
|
||||||
type: 'object'
|
type: 'object'
|
||||||
|
optional: false
|
||||||
example: 'this.getNearestEnemy()'
|
example: 'this.getNearestEnemy()'
|
||||||
description: 'The target of this function.'
|
description: 'The target of this function.'
|
||||||
required: ['name', 'type', 'example', 'description']
|
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'}
|
i18n: { type: 'object', format: 'i18n', props: ['description'], description: 'Help translate this argument'}
|
||||||
# not actual JS types, just whatever they describe...
|
# not actual JS types, just whatever they describe...
|
||||||
type: me.shortString(title: 'Type', description: 'Intended type of the argument.')
|
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:
|
example:
|
||||||
oneOf: [
|
oneOf: [
|
||||||
{
|
{
|
||||||
|
|
|
@ -95,7 +95,7 @@ if !selectedMethod
|
||||||
else if language == 'io'
|
else if language == 'io'
|
||||||
span= (doc.ownerName == 'this' ? '' : doc.ownerName + ' ') + docName + '(' + argumentExamples.join(', ') + ')'
|
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
|
p.value
|
||||||
strong
|
strong
|
||||||
span(data-i18n="skill_docs.current_value") Current Value
|
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
|
pre
|
||||||
code.current-value(data-prop=doc.name)= value
|
code.current-value(data-prop=doc.name)= value
|
||||||
|
|
||||||
if doc.args && doc.args.length
|
mixin argumentEntry(arg)
|
||||||
p.args
|
|
||||||
strong
|
|
||||||
span(data-i18n="skill_docs.parameters") Parameters
|
|
||||||
span.spr :
|
|
||||||
for arg in doc.args
|
|
||||||
div
|
div
|
||||||
code= arg.name
|
code= arg.name
|
||||||
span.spr :
|
span.spr :
|
||||||
|
@ -128,6 +123,28 @@ if doc.args && doc.args.length
|
||||||
span.spr :
|
span.spr :
|
||||||
code= arg.default
|
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
|
if doc.returns
|
||||||
p.returns
|
p.returns
|
||||||
strong
|
strong
|
||||||
|
|
|
@ -49,7 +49,7 @@ module.exports = class DocFormatter
|
||||||
@doc.type = 'snippet'
|
@doc.type = 'snippet'
|
||||||
@doc.owner = 'snippets'
|
@doc.owner = 'snippets'
|
||||||
@doc.shortName = @doc.shorterName = @doc.title = @doc.name
|
@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
|
@doc.shortName = @doc.shorterName = @doc.title = @doc.name
|
||||||
else
|
else
|
||||||
@doc.owner ?= 'this'
|
@doc.owner ?= 'this'
|
||||||
|
@ -165,7 +165,19 @@ module.exports = class DocFormatter
|
||||||
[docName, args] = @getDocNameAndArguments()
|
[docName, args] = @getDocNameAndArguments()
|
||||||
argumentExamples = (arg.example or arg.default or arg.name for arg in @doc.args ? [])
|
argumentExamples = (arg.example or arg.default or arg.name for arg in @doc.args ? [])
|
||||||
argumentExamples.unshift args[0] if args.length > argumentExamples.length
|
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]
|
owner = if @doc.owner is 'this' then @options.thang else window[@doc.owner]
|
||||||
content = @replaceSpriteName content
|
content = @replaceSpriteName content
|
||||||
content = content.replace /\#\{(.*?)\}/g, (s, properties) => @formatValue downTheChain(owner, properties.split('.'))
|
content = content.replace /\#\{(.*?)\}/g, (s, properties) => @formatValue downTheChain(owner, properties.split('.'))
|
||||||
|
|
|
@ -157,6 +157,8 @@ module.exports = class SpellPaletteView extends CocoView
|
||||||
LoDash: 'programmableLoDashProperties'
|
LoDash: 'programmableLoDashProperties'
|
||||||
Vector: 'programmableVectorProperties'
|
Vector: 'programmableVectorProperties'
|
||||||
HTML: 'programmableHTMLProperties'
|
HTML: 'programmableHTMLProperties'
|
||||||
|
WebJavaScript: 'programmableWebJavaScriptProperties'
|
||||||
|
jQuery: 'programmableJQueryProperties'
|
||||||
CSS: 'programmableCSSProperties'
|
CSS: 'programmableCSSProperties'
|
||||||
snippets: 'programmableSnippets'
|
snippets: 'programmableSnippets'
|
||||||
else
|
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 ? [])
|
return 'more' if entry.doc.owner is 'this' and entry.doc.name in (propGroups.more ? [])
|
||||||
entry.doc.owner
|
entry.doc.owner
|
||||||
@entries = _.sortBy @entries, (entry) ->
|
@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 = order.indexOf groupForEntry entry
|
||||||
index = String.fromCharCode if index is -1 then order.length else index
|
index = String.fromCharCode if index is -1 then order.length else index
|
||||||
index += entry.doc.name
|
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
|
console.log @thang.id, "couldn't find item ThangType for", slot, thangTypeName
|
||||||
|
|
||||||
# Get any Math-, Vector-, etc.-owned properties into their own tabs
|
# 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
|
continue unless @thang[storage]?.length
|
||||||
@tabs ?= {}
|
@tabs ?= {}
|
||||||
@tabs[owner] = []
|
@tabs[owner] = []
|
||||||
|
@ -262,7 +264,7 @@ module.exports = class SpellPaletteView extends CocoView
|
||||||
|
|
||||||
# Assign any unassigned properties to the hero itself.
|
# Assign any unassigned properties to the hero itself.
|
||||||
for owner, storage of propStorage
|
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
|
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 '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
|
continue if prop is 'moveXY' and @options.level.get('slug') is 'slalom' # Hide for Slalom
|
||||||
|
|
|
@ -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 hero = _.find @options.level.get('thangs'), id: 'Hero Placeholder'
|
||||||
return null unless programmableConfig = _.find(hero.components, (component) -> component.config?.programmableMethods).config
|
return null unless programmableConfig = _.find(hero.components, (component) -> component.config?.programmableMethods).config
|
||||||
usesHTMLConfig = _.find(hero.components, (component) -> component.config?.programmableHTMLProperties).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
|
console.warn "Couldn't find usesHTML config; is it presented and not defaulted on the Hero Placeholder?" unless usesHTMLConfig
|
||||||
thang =
|
thang =
|
||||||
id: 'Hero Placeholder'
|
id: 'Hero Placeholder'
|
||||||
isProgrammable: true
|
isProgrammable: true
|
||||||
thang = _.merge thang, programmableConfig, usesHTMLConfig
|
thang = _.merge thang, programmableConfig, usesHTMLConfig, usesWebJavaScriptConfig, usesJQueryConfig
|
||||||
thang
|
thang
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
|
|
Loading…
Reference in a new issue