From 07f6f98c240d0507919e52b89cfe99b278a59607 Mon Sep 17 00:00:00 2001 From: Rob Date: Tue, 16 Aug 2016 13:20:38 -0700 Subject: [PATCH 1/2] Refactor remote server readpref and connection strings. --- server/commons/database.coffee | 8 ++------ server_config.coffee | 9 +-------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/server/commons/database.coffee b/server/commons/database.coffee index 41027df82..a3d292ec4 100644 --- a/server/commons/database.coffee +++ b/server/commons/database.coffee @@ -12,7 +12,7 @@ module.exports = connect: () -> address = module.exports.generateMongoConnectionString() - winston.info "Connecting to Mongo with connection string #{address}" + winston.info "Connecting to Mongo with connection string #{address}, readpref: #{config.mongo.readpref}" mongoose.connect address mongoose.connection.once 'open', -> Grid.gfs = Grid(mongoose.connection.db, mongoose.mongo) @@ -25,11 +25,7 @@ module.exports = mongooseCache.install(mongoose, {max: 1000, maxAge: maxAge, debug: false}, Aggregate) generateMongoConnectionString: -> - if not global.testing and config.tokyo - address = config.mongo.mongoose_tokyo_replica_string - else if not global.testing and config.saoPaulo - address = config.mongo.mongoose_saoPaulo_replica_string - else if not global.testing and config.mongo.mongoose_replica_string + if not global.testing and config.mongo.mongoose_replica_string address = config.mongo.mongoose_replica_string else dbName = config.mongo.db diff --git a/server_config.coffee b/server_config.coffee index b18aa8a18..0b1d371ea 100644 --- a/server_config.coffee +++ b/server_config.coffee @@ -23,8 +23,7 @@ config.mongo = analytics_db: process.env.COCO_MONGO_ANALYTICS_DATABASE_NAME or 'analytics' analytics_collection: process.env.COCO_MONGO_ANALYTICS_COLLECTION or 'analytics.log.event' mongoose_replica_string: process.env.COCO_MONGO_MONGOOSE_REPLICA_STRING or '' - mongoose_tokyo_replica_string: process.env.COCO_MONGO_MONGOOSE_TOKYO_REPLICA_STRING or '' - mongoose_saoPaulo_replica_string : process.env.COCO_MONGO_MONGOOSE_SAOPAULO_REPLICA_STRING or '' + readpref: process.env.COCO_MONGO_READPREF or 'primary' if process.env.COCO_MONGO_LS_REPLICA_STRING? config.mongo.level_session_replica_string = process.env.COCO_MONGO_LS_REPLICA_STRING @@ -32,12 +31,6 @@ if process.env.COCO_MONGO_LS_REPLICA_STRING? if process.env.COCO_MONGO_LS_AUX_REPLICA_STRING? config.mongo.level_session_aux_replica_string = process.env.COCO_MONGO_LS_AUX_REPLICA_STRING - -if config.tokyo or config.saoPaulo - config.mongo.readpref = 'nearest' -else - config.mongo.readpref = 'primary' - config.apple = verifyURL: process.env.COCO_APPLE_VERIFY_URL or 'https://sandbox.itunes.apple.com/verifyReceipt' From a1b012c7f58bcf2f28254b6bc4d57d4a041ade81 Mon Sep 17 00:00:00 2001 From: Phoenix Eliot Date: Tue, 16 Aug 2016 12:36:38 -0700 Subject: [PATCH 2/2] Add support for optional arguments, and web components Refactor Don't use globals in template --- app/locale/en.coffee | 2 + app/schemas/schemas.coffee | 2 + .../tome/spell_palette_entry_popover.jade | 55 ++++++++++++------- app/views/play/level/tome/DocFormatter.coffee | 16 +++++- .../play/level/tome/SpellPaletteView.coffee | 8 ++- app/views/play/level/tome/TomeView.coffee | 16 +++--- 6 files changed, 68 insertions(+), 31 deletions(-) diff --git a/app/locale/en.coffee b/app/locale/en.coffee index 0d1469950..1385e564c 100644 --- a/app/locale/en.coffee +++ b/app/locale/en.coffee @@ -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" diff --git a/app/schemas/schemas.coffee b/app/schemas/schemas.coffee index 9df53b58a..9ecd1f059 100644 --- a/app/schemas/schemas.coffee +++ b/app/schemas/schemas.coffee @@ -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: [ { diff --git a/app/templates/play/level/tome/spell_palette_entry_popover.jade b/app/templates/play/level/tome/spell_palette_entry_popover.jade index dd5306643..e05714298 100644 --- a/app/templates/play/level/tome/spell_palette_entry_popover.jade +++ b/app/templates/play/level/tome/spell_palette_entry_popover.jade @@ -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 diff --git a/app/views/play/level/tome/DocFormatter.coffee b/app/views/play/level/tome/DocFormatter.coffee index e8eb4b693..72d2f3e4d 100644 --- a/app/views/play/level/tome/DocFormatter.coffee +++ b/app/views/play/level/tome/DocFormatter.coffee @@ -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('.')) diff --git a/app/views/play/level/tome/SpellPaletteView.coffee b/app/views/play/level/tome/SpellPaletteView.coffee index e8d4a6405..5e13ebe29 100644 --- a/app/views/play/level/tome/SpellPaletteView.coffee +++ b/app/views/play/level/tome/SpellPaletteView.coffee @@ -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 diff --git a/app/views/play/level/tome/TomeView.coffee b/app/views/play/level/tome/TomeView.coffee index f141adfc4..aebf5fb27 100644 --- a/app/views/play/level/tome/TomeView.coffee +++ b/app/views/play/level/tome/TomeView.coffee @@ -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: ->