Refactor ModVersion into Mod and ModVersion

* Remove V1 of the mod version parser and shift V2 up to be V1
* Add a parser for mod.cg files, and refactor the the mod-version.cg
  files to push the appropriate content up to the mod.cg
* Remove the concept of "silent" from BaseModel along with logging
  each event as they are fired (which is what really prompted the
  need for it in the first place)
* Move use of the Storage class to be completely the province of the
  controllers most closely related to models affected
* Convert the ModVersionController to the ModController and have it
  take on responsibility for choosing the mod version
* Update BaseModel to support simple accessors for the current state
* Update CraftingPlan to be able to remove uncraftable items
* Implement the Mod model
This commit is contained in:
Andrew Miner
2015-01-18 10:48:12 -08:00
parent 76dc863372
commit d1621bb9f6
39 changed files with 922 additions and 1176 deletions
@@ -0,0 +1,69 @@
###
Crafting Guide - mod_controller.coffee
Copyright (c) 2014-2015 by Redwood Labs
All rights reserved.
###
BaseController = require './base_controller'
{Event} = require '../constants'
Mod = require '../models/mod'
{RequiredMods} = require '../constants'
########################################################################################################################
module.exports = class ModController extends BaseController
constructor: (options={})->
if not options.model? then throw new Error 'options.model is required'
if not options.plan? then throw new Error 'options.plan is required'
options.templateName = 'mod'
super options
@_plan = options.plan
@_storage = options.storage
# Event Methods ################################################################################
onEnabledChanged: ->
return unless @rendered
enabled = @$(':checked').length > 0
if enabled
@model.activeVersion = Mod.Version.Latest
else
@model.activeVersion = Mod.Version.None
@_plan.removeUncraftableItems()
# BaseController Overrides #####################################################################
onWillRender: ->
if not @model.isLoaded then @model.fetch()
if @_storage? then @_storage.register "mod:#{@model.slug}", @model, 'activeVersion'
@model.on Event.change + ':activeModVersion', (mod, modVersion)=>
if modVersion? and not modVersion.isLoaded then modVersion.fetch()
onDidRender: ->
@$enabled = @$('td:nth-child(1) input')
@$name = @$('td:nth-child(2) p')
@$description = @$('td:nth-child(3) p')
super
refresh: ->
if @model.slug in RequiredMods
@$enabled.attr 'checked', 'checked'
@$enabled.attr 'disabled', 'disabled'
else
@$enabled.removeAttr 'disabled'
if @model.activeVersion is Mod.Version.None
@$enabled.removeAttr 'checked'
else
@$enabled.attr 'checked', 'checked'
@$name.html "#{@model.name}"
@$description.html "#{@model.description}"
# Backbone.View Overrides ######################################################################
events:
'change input[type="checkbox"]': 'onEnabledChanged'