mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Created the Campaign foundation: schema, model, handler.
This commit is contained in:
parent
59956c57f9
commit
0b81796333
4 changed files with 143 additions and 0 deletions
7
app/models/Campaign.coffee
Normal file
7
app/models/Campaign.coffee
Normal file
|
@ -0,0 +1,7 @@
|
|||
CocoModel = require './CocoModel'
|
||||
|
||||
module.exports = class Campaign extends CocoModel
|
||||
@className: 'Campaign'
|
||||
@schema: require 'schemas/models/campaign.schema'
|
||||
urlRoot: '/db/campaign'
|
||||
saveBackups: true
|
105
app/schemas/models/campaign.schema.coffee
Normal file
105
app/schemas/models/campaign.schema.coffee
Normal file
|
@ -0,0 +1,105 @@
|
|||
|
||||
c = require './../schemas'
|
||||
|
||||
CampaignSchema = c.object()
|
||||
c.extendNamedProperties CampaignSchema # name first
|
||||
|
||||
_.extend CampaignSchema.properties,
|
||||
i18n: {type: 'object', title: 'i18n', format: 'i18n', props: ['name', 'body']}
|
||||
|
||||
ambientSound: c.object {},
|
||||
mp3: { type: 'string', format: 'sound-file' }
|
||||
ogg: { type: 'string', format: 'sound-file' }
|
||||
|
||||
backgroundImage: c.array {}, {
|
||||
image: { type: 'string', format: 'image-file' }
|
||||
width: { type: 'number' }
|
||||
}
|
||||
backgroundColor: { type: 'string' }
|
||||
backgroundColorTransparent: { type: 'string' }
|
||||
|
||||
adjacentCampaigns: { type: 'object', additionalItems: {
|
||||
title: 'Campaign'
|
||||
type: 'object'
|
||||
properties: {
|
||||
#- denormalized from other Campaigns, either updated automatically or fetched dynamically
|
||||
name: { type: 'string' }
|
||||
i18n: { type: 'object' }
|
||||
|
||||
#- normal properties
|
||||
position: c.point2d()
|
||||
rotation: { type: 'number', format: 'degrees' }
|
||||
color: { type: 'string' }
|
||||
}
|
||||
}}
|
||||
|
||||
levels: { type: 'object', additionalItems: {
|
||||
title: 'Level'
|
||||
type: 'object'
|
||||
properties: {
|
||||
#- denormalized from Level
|
||||
# TODO: take these properties from the Level schema and put them into schema references, use them here
|
||||
name: { readOnly: true }
|
||||
description: { readOnly: true }
|
||||
requiresSubscription: { type: 'boolean' }
|
||||
type: {'enum': ['campaign', 'ladder', 'ladder-tutorial', 'hero', 'hero-ladder', 'hero-coop']}
|
||||
slug: { readOnly: true }
|
||||
original: { readOnly: true }
|
||||
adventurer: { type: 'boolean' }
|
||||
practice: { type: 'boolean' }
|
||||
|
||||
# TODO: add these to the level, as well as the 'campaign' property
|
||||
disableSpaces: { type: 'boolean' }
|
||||
hidesSubmitUntilRun: { type: 'boolean' }
|
||||
hidesPlayButton: { type: 'boolean' }
|
||||
hidesRunShortcut: { type: 'boolean' }
|
||||
hidesHUD: { type: 'boolean' }
|
||||
hidesSay: { type: 'boolean' }
|
||||
hidesCodeToolbar: { type: 'boolean' }
|
||||
hidesRealTimePlayback: { type: 'boolean' }
|
||||
backspaceThrottle: { type: 'boolean' }
|
||||
lockDefaultCode: { type: 'boolean' }
|
||||
moveRightLoopSnippet: { type: 'boolean' }
|
||||
|
||||
realTimeSpeedFactor: { type: 'number' }
|
||||
autocompleteFontSizePx: { type: 'number' }
|
||||
|
||||
requiredCode: c.array {}, {
|
||||
type: 'string'
|
||||
}
|
||||
suspectCode: c.array {}, {
|
||||
type: 'object'
|
||||
properties: {
|
||||
name: { type: 'string' }
|
||||
pattern: { type: 'string' }
|
||||
}
|
||||
}
|
||||
|
||||
requiredGear: { type: 'object', additionalProperties: {
|
||||
type: 'string' # should be an originalID, denormalized on the editor side
|
||||
}}
|
||||
restrictedGear: { type: 'object', additionalProperties: {
|
||||
type: 'string' # should be an originalID, denormalized on the editor side
|
||||
}}
|
||||
allowedHeroes: { type: 'array', items: {
|
||||
type: 'string' # should be an originalID, denormalized on the editor side
|
||||
}}
|
||||
|
||||
#- denormalized/restructured from Achievements
|
||||
nextLevels: c.array {}
|
||||
unlocksHero: c.object { readOnly: true }, {
|
||||
image: { type: 'string', format: 'image-file' }
|
||||
original: { type: 'string' }
|
||||
}
|
||||
|
||||
#- normal properties
|
||||
position: c.point2d()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.extendBasicProperties CampaignSchema, 'campaign'
|
||||
c.extendTranslationCoverageProperties CampaignSchema
|
||||
|
||||
module.exports = CampaignSchema
|
9
server/campaign/Campaign.coffee
Normal file
9
server/campaign/Campaign.coffee
Normal file
|
@ -0,0 +1,9 @@
|
|||
mongoose = require 'mongoose'
|
||||
plugins = require '../plugins/plugins'
|
||||
|
||||
CampaignSchema = new mongoose.Schema(body: String, {strict: false})
|
||||
|
||||
CampaignSchema.plugin(plugins.NamedPlugin)
|
||||
CampaignSchema.plugin(plugins.TranslationCoveragePlugin)
|
||||
|
||||
module.exports = mongoose.model('campaign', CampaignSchema)
|
22
server/campaign/campaign_handler.coffee
Normal file
22
server/campaign/campaign_handler.coffee
Normal file
|
@ -0,0 +1,22 @@
|
|||
Campaign = require './Campaign'
|
||||
Handler = require '../commons/Handler'
|
||||
|
||||
CampaignHandler = class CampaignHandler extends Handler
|
||||
modelClass: Campaign
|
||||
editableProperties: [
|
||||
'name'
|
||||
'i18n'
|
||||
'i18nCoverage'
|
||||
'ambientSound'
|
||||
'backgroundImage'
|
||||
'backgroundColor'
|
||||
'backgroundColorTransparent'
|
||||
'adjacentCampaigns'
|
||||
'levels'
|
||||
]
|
||||
jsonSchema: require '../../app/schemas/models/campaign.schema'
|
||||
|
||||
hasAccess: (req) ->
|
||||
req.method is 'GET' or req.user?.isAdmin()
|
||||
|
||||
module.exports = new CampaignHandler()
|
Loading…
Reference in a new issue