mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -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"
|
||||
default_value: "Default value"
|
||||
parameters: "Parameters"
|
||||
required_parameters: "Required Parameters"
|
||||
optional_parameters: "Optional Parameters"
|
||||
returns: "Returns"
|
||||
granted_by: "Granted by"
|
||||
|
||||
|
|
|
@ -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: [
|
||||
{
|
||||
|
|
|
@ -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,30 +103,47 @@ if (doc.type != 'function' && doc.type != 'snippet' && doc.owner != 'HTML' && do
|
|||
pre
|
||||
code.current-value(data-prop=doc.name)= value
|
||||
|
||||
mixin argumentEntry(arg)
|
||||
div
|
||||
code= arg.name
|
||||
span.spr :
|
||||
code= arg.type
|
||||
if arg.example
|
||||
| (
|
||||
span(data-i18n="skill_docs.ex") ex
|
||||
span.spr :
|
||||
code= arg.example
|
||||
| )
|
||||
if arg.description
|
||||
div!= marked(arg.description)
|
||||
if arg.default
|
||||
div
|
||||
em
|
||||
span(data-i18n="skill_docs.default_value") Default value
|
||||
span.spr :
|
||||
code= arg.default
|
||||
|
||||
if doc.args && doc.args.length
|
||||
- var hasOptionalArguments = _.any(doc.args, function(arg){ return arg.optional })
|
||||
p.args
|
||||
strong
|
||||
span(data-i18n="skill_docs.parameters") Parameters
|
||||
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
|
||||
div
|
||||
code= arg.name
|
||||
unless arg.optional
|
||||
+argumentEntry(arg)
|
||||
if hasOptionalArguments
|
||||
p.args
|
||||
strong
|
||||
span(data-i18n="skill_docs.optional_parameters") Optional Parameters
|
||||
span.spr :
|
||||
code= arg.type
|
||||
if arg.example
|
||||
| (
|
||||
span(data-i18n="skill_docs.ex") ex
|
||||
span.spr :
|
||||
code= arg.example
|
||||
| )
|
||||
if arg.description
|
||||
div!= marked(arg.description)
|
||||
if arg.default
|
||||
div
|
||||
em
|
||||
span(data-i18n="skill_docs.default_value") Default value
|
||||
span.spr :
|
||||
code= arg.default
|
||||
for arg in doc.args
|
||||
if arg.optional
|
||||
+argumentEntry(arg)
|
||||
|
||||
|
||||
if doc.returns
|
||||
p.returns
|
||||
|
|
|
@ -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('.'))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -157,14 +157,14 @@ module.exports = class TomeView extends CocoView
|
|||
if @options.observing
|
||||
difficulty = Math.max 0, difficulty - 1 # Show the difficulty they won, not the next one.
|
||||
Backbone.Mediator.publish 'tome:cast-spells', {
|
||||
@spells,
|
||||
preload,
|
||||
realTime,
|
||||
justBegin,
|
||||
@spells,
|
||||
preload,
|
||||
realTime,
|
||||
justBegin,
|
||||
difficulty,
|
||||
submissionCount: sessionState.submissionCount ? 0,
|
||||
flagHistory: sessionState.flagHistory ? [],
|
||||
god: @options.god,
|
||||
flagHistory: sessionState.flagHistory ? [],
|
||||
god: @options.god,
|
||||
fixedSeed: @options.fixedSeed
|
||||
}
|
||||
|
||||
|
@ -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: ->
|
||||
|
|
Loading…
Reference in a new issue