Add better support for turning mods on/off

* Make the Minecraft "mod" enabled at all times
* Sort the list of mods to move required mods to the top
* Automatically enable a mod which has a recipe selected (e.g., from
  a query param)
This commit is contained in:
Andrew Miner
2014-12-29 14:07:57 -08:00
parent 2dd4b7014f
commit c46bb8860c
7 changed files with 45 additions and 8 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
"tools": ["Crafting Table"] "tools": ["Crafting Table"]
}, { }, {
"output": [[1, "Quartz Cutting Knife"]], "output": [[1, "Quartz Cutting Knife"]],
"input": [[1, "Iron"], [2, "Stick"], [2, "Certus Quartz"]], "input": [[1, "Iron Ingot"], [2, "Stick"], [2, "Certus Quartz"]],
"tools": ["Crafting Table"] "tools": ["Crafting Table"]
}, { }, {
"output": [[1, "Basic Processor Assembly"]], "output": [[1, "Basic Processor Assembly"]],
+4
View File
@@ -35,6 +35,10 @@ exports.Opacity = Opacity = {}
Opacity.hidden = 1e-6 Opacity.hidden = 1e-6
Opacity.shown = 1 Opacity.shown = 1
exports.RequiredMods = [
'Minecraft'
]
exports.UrlParam = UrlParam = {} exports.UrlParam = UrlParam = {}
UrlParam.quantity = 'count' UrlParam.quantity = 'count'
UrlParam.recipe = 'recipeName' UrlParam.recipe = 'recipeName'
@@ -110,10 +110,12 @@ module.exports = class CraftingTableController extends BaseController
_craft: -> _craft: ->
if @model.catalog.hasRecipe @model.name if @model.catalog.hasRecipe @model.name
router.navigate "/item/#{encodeURIComponent(@model.name)}" router.navigate "/item/#{encodeURIComponent(@model.name)}"
@model.craft()
else else
router.navigate "/item" router.navigate "/item"
@model.craft()
@refresh()
_updateNameAutocomplete: -> _updateNameAutocomplete: ->
onChanged = => @onNameFieldChanged() onChanged = => @onNameFieldChanged()
@@ -6,6 +6,7 @@
### ###
BaseController = require './base_controller' BaseController = require './base_controller'
{RequiredMods} = require '../constants'
######################################################################################################################## ########################################################################################################################
@@ -32,7 +33,13 @@ module.exports = class RecipeBookController extends BaseController
super super
refresh: -> refresh: ->
if @model.enabled then @$enabled.attr('checked', 'checked') else @$enabled.removeAttr('checked') if @model.modName in RequiredMods
@$enabled.attr 'checked', 'checked'
@$enabled.attr 'disabled', 'disabled'
else
@$enabled.removeAttr 'disabled'
if @model.enabled then @$enabled.attr('checked', 'checked') else @$enabled.removeAttr('checked')
@$name.html "#{@model.modName} (#{@model.modVersion})" @$name.html "#{@model.modName} (#{@model.modVersion})"
@$description.html "#{@model.description}" @$description.html "#{@model.description}"
+3 -1
View File
@@ -26,13 +26,15 @@ module.exports = class CraftingTable extends BaseModel
# Public Methods ############################################################################### # Public Methods ###############################################################################
craft: -> craft: ->
if not @name?.length if not @catalog.hasRecipe @name
@plan = null @plan = null
return return
toolPhrase = if @includingTools then ' includingTools' else '' toolPhrase = if @includingTools then ' includingTools' else ''
logger.verbose "calculating build plan for #{@quantity} #{@name}#{toolPhrase} with inventory: #{@have}" logger.verbose "calculating build plan for #{@quantity} #{@name}#{toolPhrase} with inventory: #{@have}"
@catalog.enableBooksForRecipe @name
plan = new CraftingPlan @catalog, @includingTools plan = new CraftingPlan @catalog, @includingTools
plan.includingTools = @includingTools plan.includingTools = @includingTools
plan.craft @name, @quantity, @have plan.craft @name, @quantity, @have
+2 -1
View File
@@ -6,6 +6,7 @@
### ###
BaseModel = require './base_model' BaseModel = require './base_model'
{RequiredMods} = require '../constants'
######################################################################################################################## ########################################################################################################################
@@ -17,7 +18,7 @@ module.exports = class RecipeBook extends BaseModel
attributes.description ?= '' attributes.description ?= ''
attributes.recipes ?= [] attributes.recipes ?= []
attributes.enabled ?= true attributes.enabled ?= attributes.modName in RequiredMods
super attributes, options super attributes, options
# Public Methods ############################################################################### # Public Methods ###############################################################################
+24 -3
View File
@@ -8,6 +8,7 @@
BaseModel = require './base_model' BaseModel = require './base_model'
{Event} = require '../constants' {Event} = require '../constants'
RecipeBookParser = require './recipe_book_parser' RecipeBookParser = require './recipe_book_parser'
{RequiredMods} = require '../constants'
######################################################################################################################## ########################################################################################################################
@@ -21,6 +22,12 @@ module.exports = class RecipeCatalog extends BaseModel
# Public Methods ############################################################################### # Public Methods ###############################################################################
enableBooksForRecipe: (name)->
for book in @books
continue if book.enabled
if book.hasRecipe name
book.enabled = true
gatherNames: -> gatherNames: ->
nameData = {} nameData = {}
for book in @books for book in @books
@@ -59,9 +66,7 @@ module.exports = class RecipeCatalog extends BaseModel
loadBookData: (data)-> loadBookData: (data)->
book = @_parser.parse data book = @_parser.parse data
@books.push book @books.push book
@books.sort (a, b)-> @_sortBooks()
return 0 if a.modName is b.modName
return if a.modName < b.modName then -1 else +1
book.on Event.change, => @trigger Event.change, this book.on Event.change, => @trigger Event.change, this
return book return book
@@ -96,3 +101,19 @@ module.exports = class RecipeCatalog extends BaseModel
toString: -> toString: ->
return "RecipeCatalog (#{@cid}) {books:#{@books.length} items}" return "RecipeCatalog (#{@cid}) {books:#{@books.length} items}"
_sortBooks:->
@books.sort (a, b)->
if a.modName is b.modName then return 0
aRequired = a.modName in RequiredMods
bRequired = b.modName in RequiredMods
if aRequired and bRequired
return if a.modName < b.modName then -1 else +1
else if aRequired
return -1
else if bRequired
return +1
else
return if a.modName < b.modName then -1 else +1