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"]
}, {
"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"]
}, {
"output": [[1, "Basic Processor Assembly"]],
+4
View File
@@ -35,6 +35,10 @@ exports.Opacity = Opacity = {}
Opacity.hidden = 1e-6
Opacity.shown = 1
exports.RequiredMods = [
'Minecraft'
]
exports.UrlParam = UrlParam = {}
UrlParam.quantity = 'count'
UrlParam.recipe = 'recipeName'
@@ -110,10 +110,12 @@ module.exports = class CraftingTableController extends BaseController
_craft: ->
if @model.catalog.hasRecipe @model.name
router.navigate "/item/#{encodeURIComponent(@model.name)}"
@model.craft()
else
router.navigate "/item"
@model.craft()
@refresh()
_updateNameAutocomplete: ->
onChanged = => @onNameFieldChanged()
@@ -6,6 +6,7 @@
###
BaseController = require './base_controller'
{RequiredMods} = require '../constants'
########################################################################################################################
@@ -32,7 +33,13 @@ module.exports = class RecipeBookController extends BaseController
super
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})"
@$description.html "#{@model.description}"
+3 -1
View File
@@ -26,13 +26,15 @@ module.exports = class CraftingTable extends BaseModel
# Public Methods ###############################################################################
craft: ->
if not @name?.length
if not @catalog.hasRecipe @name
@plan = null
return
toolPhrase = if @includingTools then ' includingTools' else ''
logger.verbose "calculating build plan for #{@quantity} #{@name}#{toolPhrase} with inventory: #{@have}"
@catalog.enableBooksForRecipe @name
plan = new CraftingPlan @catalog, @includingTools
plan.includingTools = @includingTools
plan.craft @name, @quantity, @have
+2 -1
View File
@@ -6,6 +6,7 @@
###
BaseModel = require './base_model'
{RequiredMods} = require '../constants'
########################################################################################################################
@@ -17,7 +18,7 @@ module.exports = class RecipeBook extends BaseModel
attributes.description ?= ''
attributes.recipes ?= []
attributes.enabled ?= true
attributes.enabled ?= attributes.modName in RequiredMods
super attributes, options
# Public Methods ###############################################################################
+24 -3
View File
@@ -8,6 +8,7 @@
BaseModel = require './base_model'
{Event} = require '../constants'
RecipeBookParser = require './recipe_book_parser'
{RequiredMods} = require '../constants'
########################################################################################################################
@@ -21,6 +22,12 @@ module.exports = class RecipeCatalog extends BaseModel
# Public Methods ###############################################################################
enableBooksForRecipe: (name)->
for book in @books
continue if book.enabled
if book.hasRecipe name
book.enabled = true
gatherNames: ->
nameData = {}
for book in @books
@@ -59,9 +66,7 @@ module.exports = class RecipeCatalog extends BaseModel
loadBookData: (data)->
book = @_parser.parse data
@books.push book
@books.sort (a, b)->
return 0 if a.modName is b.modName
return if a.modName < b.modName then -1 else +1
@_sortBooks()
book.on Event.change, => @trigger Event.change, this
return book
@@ -96,3 +101,19 @@ module.exports = class RecipeCatalog extends BaseModel
toString: ->
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