Fix misc. bugs caused by refactoring

This commit is contained in:
Andrew Miner
2015-02-18 16:11:17 -08:00
parent e88821d449
commit aab3baec1a
16 changed files with 116 additions and 178 deletions
@@ -2442,22 +2442,6 @@ group: Minerals: Dusts
tools: Macerator tools: Macerator
item: Tiny Pile of Copper Dust item: Tiny Pile of Copper Dust
recipe:
extras: Purified Crushed Copper Ore, Stone Dust
input: Crushed Copper Ore, Water
pattern: ... .0. .1.
quantity: 2
tools: Ore Washing Plant
recipe:
extras: Lead Dust
input: Purified Crushed Lead Ore
pattern: ... .0. ...
tools: Thermal Centrifuge
recipe:
extras: Lead Dust, Stone Dust
input: Crushed Lead Ore
pattern: ... .0. ...
tools: Thermal Centrifuge
recipe: recipe:
input: Copper Plate input: Copper Plate
pattern: ... .0. ... pattern: ... .0. ...
@@ -2465,27 +2449,6 @@ group: Minerals: Dusts
tools: Macerator tools: Macerator
item: Tiny Pile of Gold Dust item: Tiny Pile of Gold Dust
recipe:
extras: Purified Crushed Gold Ore, Stone Dust
input: Crushed Gold Ore, Water
pattern: ... .0. .1.
quantity: 2
tools: Ore Washing Plant
recipe:
extras: Iron Dust
input: Purified Crushed Iron Ore
pattern: ... .0. ...
tools: Thermal Centrifuge
recipe:
extras: Iron Dust, Stone Dust
input: Crushed Iron Ore
pattern: ... .0. ...
tools: Thermal Centrifuge
recipe:
extras: 5 Coal Dust
input: Slag
pattern: ... .0. ...
tools: Thermal Centrifuge
recipe: recipe:
input: Gold Plate input: Gold Plate
pattern: ... .0. ... pattern: ... .0. ...
@@ -2493,22 +2456,6 @@ group: Minerals: Dusts
tools: Macerator tools: Macerator
item: Tiny Pile of Iron Dust item: Tiny Pile of Iron Dust
recipe:
extras: Purified Crushed Iron Ore, Stone Dust
input: Crushed Iron Ore, Water
pattern: ... .0. .1.
quantity: 2
tools: Ore Washing Plant
recipe:
extras: Tin Dust
input: Purified Crushed Tin Ore
pattern: ... .0. ...
tools: Thermal Centrifuge
recipe:
extras: Tin Dust, Stone Dust
input: Crushed Tin Ore
pattern: ... .0. ...
tools: Thermal Centrifuge
recipe: recipe:
input: Iron Plate input: Iron Plate
pattern: ... .0. ... pattern: ... .0. ...
@@ -2523,17 +2470,6 @@ group: Minerals: Dusts
tools: Macerator tools: Macerator
item: Tiny Pile of Lead Dust item: Tiny Pile of Lead Dust
recipe:
extras: Purified Crushed Uranium Ore, Stone Dust
input: Crushed Uranium Ore, Water
pattern: ... .0. .1.
quantity: 2
tools: Ore Washing Plant
recipe:
extras: Silver Dust
input: Purified Crushed Silver Ore
pattern: ... .0. ...
tools: Thermal Centrifuge
recipe: recipe:
input: Lead Plate input: Lead Plate
pattern: ... .0. ... pattern: ... .0. ...
@@ -2554,78 +2490,16 @@ group: Minerals: Dusts
tools: Macerator tools: Macerator
item: Tiny Pile of Plutonium item: Tiny Pile of Plutonium
recipe:
extras: 16 Uranium 238, 6 Iron Dust
input: Quad Fuel Rod (Depleted Uranium)
pattern: ... .0. ...
quantity: 4
tools: Thermal Centrifuge
recipe:
extras: 12 Plutonium, 6 Iron Dust
input: Quad Fuel Rod (Depleted MOX)
pattern: ... .0. ...
quantity: 4
tools: Thermal Centrifuge
recipe:
extras: 8 Uranium 238, 3 Iron Dust
input: Dual Fuel Rod (Depleted Uranium)
pattern: ... .0. ...
quantity: 2
tools: Thermal Centrifuge
recipe:
extras: 6 Plutonium, 3 Iron Ingot
input: Dual Fuel Rod (Depleted MOX)
pattern: ... .0. ...
quantity: 2
tools: Thermal Centrifuge
recipe:
extras: 4 Uranium 238, Iron Dust
input: Fuel Rod (Depleted Uranium)
pattern: ... .0. ...
tools: Thermal Centrifuge
recipe:
extras: 3 Plutonium, Iron Ingot
input: Fuel Rod (Depleted MOX)
pattern: ... .0. ...
tools: Thermal Centrifuge
recipe: recipe:
input: Plutonium input: Plutonium
pattern: ... .0. ... pattern: ... .0. ...
quantity: 9 quantity: 9
item: Tiny Pile of Silver Dust item: Tiny Pile of Silver Dust
recipe:
extras: Purified Crushed Silver Ore, Stone Dust
input: Crushed Silver Ore, Water
pattern: ... .0. .1.
quantity: 2
tools: Ore Washing Plant
item: Tiny Pile of Sulfur Dust item: Tiny Pile of Sulfur Dust
recipe:
extras: Purified Crushed Lead Ore, Stone Dust
input: Crushed Lead Ore, Water
pattern: ... .0. .1.
quantity: 3
tools: Ore Washing Plant
item: Tiny Pile of Tin Dust item: Tiny Pile of Tin Dust
recipe:
extras: Purified Crushed Tin Ore, Stone Dust
input: Crushed Tin Ore, Water
pattern: ... .0. .1.
quantity: 2
tools: Ore Washing Plant
recipe:
extras: Copper Dust
input: Purified Crushed Copper Ore
pattern: ... .0. ...
tools: Thermal Centrifuge
recipe:
extras: Copper Dust, Stone Dust
input: Crushed Copper Ore
pattern: ... .0. ...
tools: Thermal Centrifuge
recipe: recipe:
input: Tin Plate input: Tin Plate
pattern: ... .0. ... pattern: ... .0. ...
@@ -2633,17 +2507,6 @@ group: Minerals: Dusts
tools: Macerator tools: Macerator
item: Tiny Pile of Uranium 235 item: Tiny Pile of Uranium 235
recipe:
extras: 5 Uranium 238
input: Purified Crushed Uranium Ore
pattern: ... .0. ...
quantity: 2
tools: Thermal Centrifuge
recipe:
extras: 4 Uranium 238, Stone Dust
input: Crushed Uranium Ore
pattern: ... .0. ...
tools: Thermal Centrifuge
recipe: recipe:
input: Uranium 235 input: Uranium 235
pattern: ... .0. ... pattern: ... .0. ...
@@ -42,7 +42,8 @@ module.exports = class CraftingPageController extends BaseController
onWillRender: -> onWillRender: ->
@_storage.register 'crafting-plan', @model.plan, 'includingTools' @_storage.register 'crafting-plan', @model.plan, 'includingTools'
@_parser.parse @_storage.load('crafting-plan:have'), @model.plan.have @model.plan.have.clear()
@model.plan.have.parse @_storage.load('crafting-plan:have')
super super
onDidRender: -> onDidRender: ->
@@ -104,9 +105,9 @@ module.exports = class CraftingPageController extends BaseController
# Private Methods ############################################################################## # Private Methods ##############################################################################
_saveHaveInventory: -> _saveHaveInventory: ->
@_storage.store 'crafting-plan:have', @_parser.unparse @model.plan.have @_storage.store 'crafting-plan:have', @model.plan.have.unparse()
_updateLocation: -> _updateLocation: ->
text = @_parser.unparse @model.plan.want text = @model.plan.want.unparse()
url = Url.crafting inventoryText:text url = Url.crafting inventoryText:text
router.navigate url router.navigate url
@@ -43,7 +43,7 @@ module.exports = class InventoryController extends BaseController
item = @modPack.findItemByName @$nameField.val() item = @modPack.findItemByName @$nameField.val()
return unless item? return unless item?
@model.add item.qualifiedSlug, parseInt(@$quantityField.val()) @model.add item.slug, parseInt(@$quantityField.val())
@$nameField.val '' @$nameField.val ''
@$quantityField.val '1' @$quantityField.val '1'
@@ -28,7 +28,7 @@ module.exports = class ItemController extends BaseController
super super
refresh: -> refresh: ->
display = @_modPack.findItemDisplay @model.qualifiedSlug display = @_modPack.findItemDisplay @model.slug
@$icon.attr 'src', display.iconUrl @$icon.attr 'src', display.iconUrl
@$name.html display.itemName @$name.html display.itemName
@@ -52,14 +52,17 @@ module.exports = class ItemGroupController extends BaseController
# Private Methods ############################################################################## # Private Methods ##############################################################################
_createItemController: (item)-> _createItemController: (item, delay)->
controller = new ItemController model:item, modPack:@_modPack controller = new ItemController model:item, modPack:@_modPack
@_itemControllers.push controller @_itemControllers.push controller
controller.render() attachController = =>
controller.$el.hide() controller.render()
@$items.append controller.$el controller.$el.hide()
controller.$el.fadeIn duration:Duration.fast @$items.append controller.$el
controller.$el.fadeIn duration:Duration.fast
_.delay attachController, delay
_refreshItems: -> _refreshItems: ->
controllerIndex = 0 controllerIndex = 0
@@ -69,7 +72,7 @@ module.exports = class ItemGroupController extends BaseController
for item in @model for item in @model
controller = @_itemControllers[controllerIndex] controller = @_itemControllers[controllerIndex]
if not controller? if not controller?
_.delay ((i)=> return => @_createItemController i)(item), delay @_createItemController item, delay
delay += @_delayStep delay += @_delayStep
else else
controller.model = item controller.model = item
@@ -54,11 +54,11 @@ module.exports = class ItemPageController extends BaseController
super super
refresh: -> refresh: ->
$('title').html if @model.item? then "#{@model.item.name} | #{Text.title}" else Text.title $('title').html if @model.item? then "#{@model.item?.name} | #{Text.title}" else Text.title
@_resolveItemSlug() @_resolveItemSlug()
display = @_modPack.findItemDisplay @model.item?.qualifiedSlug if @model.item?
if display? display = @_modPack.findItemDisplay @model.item.slug
@$craftingPlanLink.attr href:display.craftingUrl @$craftingPlanLink.attr href:display.craftingUrl
@$craftingPlanLink.fadeIn duration:Duration.normal @$craftingPlanLink.fadeIn duration:Duration.normal
@_imageLoader.load display.iconUrl, @$titleImage @_imageLoader.load display.iconUrl, @$titleImage
@@ -43,7 +43,7 @@ module.exports = class StackController extends BaseController
super super
refresh: -> refresh: ->
display = @modPack.findItemDisplay @model.slug display = @modPack.findItemDisplay @model.itemSlug
@_imageLoader.load display.iconUrl, @$image @_imageLoader.load display.iconUrl, @$image
@$nameLink.html display.itemName @$nameLink.html display.itemName
+5 -3
View File
@@ -43,7 +43,8 @@ module.exports = class CraftingPlan extends BaseModel
craft: -> craft: ->
toolsMessage = if @includingTools then ' (including tools)' else '' toolsMessage = if @includingTools then ' (including tools)' else ''
logger.info => "crafting #{@want}#{toolsMessage} starting with #{@have}" haveMessage = if @have.isEmpty then '' else " starting with #{@have.unparse()}"
logger.info => "crafting #{@want.unparse()}#{toolsMessage}#{haveMessage}"
@clear() @clear()
@have.localize() @have.localize()
@@ -103,7 +104,7 @@ module.exports = class CraftingPlan extends BaseModel
_chooseRecipe: (item)-> _chooseRecipe: (item)->
recipes = @modPack.findRecipes item.slug recipes = @modPack.findRecipes item.slug
return null unless recipes? return null unless recipes? and recipes.length > 0
return recipes[0] return recipes[0]
_findSteps: (itemSlug)-> _findSteps: (itemSlug)->
@@ -145,8 +146,9 @@ module.exports = class CraftingPlan extends BaseModel
for i in [@steps.length-1..0] by -1 for i in [@steps.length-1..0] by -1
step = @steps[i] step = @steps[i]
recipe = step.recipe recipe = step.recipe
stepItemSlug = @_qualifyItemSlug step.recipe.itemSlug
step.multiplier = Math.ceil(@need.quantityOf(recipe.itemSlug) / recipe.output[0].quantity) step.multiplier = Math.ceil(@need.quantityOf(stepItemSlug) / recipe.output[0].quantity)
if @includingTools if @includingTools
for stack in recipe.tools for stack in recipe.tools
+5 -5
View File
@@ -144,14 +144,14 @@ module.exports = class Inventory extends BaseModel
return this return this
unparse: -> unparse: (options={})->
parts = [] parts = []
@each (stack)=> @each (stack)=>
slugText = stack.itemSlug.qualified slugText = stack.itemSlug.item
if @modPack? if @modPack?
item = @modPack.findItem stack.itemSlug.item item = @modPack.findItem ItemSlug.slugify slugText
if item? if item? and item.slug.qualified isnt stack.itemSlug.qualified
slugText = if item.slug isnt stack.itemSlug then item.slug.qualified slugText = item.slug.qualified
if stack.quantity is 1 if stack.quantity is 1
parts.push slugText parts.push slugText
+9 -7
View File
@@ -32,14 +32,16 @@ module.exports = class ItemPage extends BaseModel
return null unless @item? return null unless @item?
result = {} result = {}
@modPack.eachMod (mod)-> @modPack.eachMod (mod)=>
mod.eachRecipe (recipe)-> mod.eachRecipe (recipe)=>
if recipe.produces @item.slug if recipe.requires @item.slug
result[item.slug] = item outputItem = @modPack.findItem recipe.itemSlug
result[outputItem.slug] = outputItem
result = _.values(result).sort (a, b)-> a.compareTo b result = _.values result
return null unless result.length > 0 return null unless result.length > 0
return result
return result.sort (a, b)-> a.compareTo b
findSimilarItems: -> findSimilarItems: ->
return null unless @item?.modVersion? return null unless @item?.modVersion?
@@ -61,7 +63,7 @@ module.exports = class ItemPage extends BaseModel
@_plan.clear() @_plan.clear()
if @item? if @item?
@_plan.want.add @item.qualifiedSlug @_plan.want.add @item.slug
@_plan.craft() @_plan.craft()
if @_plan.steps.length > 0 if @_plan.steps.length > 0
+3
View File
@@ -59,6 +59,9 @@ module.exports = class ItemSlug
# Public Methods ############################################################################### # Public Methods ###############################################################################
compareTo: (that)->
return ItemSlug.compare this, that
matches: (slug, options={exact:false})-> matches: (slug, options={exact:false})->
return false unless slug?.constructor?.name is 'ItemSlug' return false unless slug?.constructor?.name is 'ItemSlug'
+4
View File
@@ -65,6 +65,10 @@ module.exports = class Mod extends BaseModel
return unless @_activeModVersion? return unless @_activeModVersion?
@_activeModVersion.eachName callback @_activeModVersion.eachName callback
eachRecipe: (callback)->
return unless @_activeModVersion?
@_activeModVersion.eachRecipe callback
findItem: (slug, options={})-> findItem: (slug, options={})->
options.includeDisabled ?= false options.includeDisabled ?= false
options.enableAsNeeded ?= false options.enableAsNeeded ?= false
+12 -8
View File
@@ -6,9 +6,10 @@ All rights reserved.
### ###
BaseModel = require './base_model' BaseModel = require './base_model'
{DefaultModVersions} = require '../constants'
{Event} = require '../constants' {Event} = require '../constants'
ModVersionParser = require './mod_version_parser' ModVersionParser = require './mod_version_parser'
{DefaultModVersions} = require '../constants' Recipe = require './recipe'
{Url} = require '../constants' {Url} = require '../constants'
######################################################################################################################## ########################################################################################################################
@@ -50,7 +51,7 @@ module.exports = class ModPack extends BaseModel
return null return null
findItemDisplay: (itemSlug)-> findItemDisplay: (itemSlug)->
if not itemSlug? then return null if not itemSlug? then throw new Error 'itemSlug is required'
result = {} result = {}
item = @findItem itemSlug, includeDisabled:true item = @findItem itemSlug, includeDisabled:true
@@ -81,15 +82,18 @@ module.exports = class ModPack extends BaseModel
return null return null
findRecipes: (itemSlug, result=[])-> findRecipes: (itemSlug, result=[])->
return null unless itemSlug?
if itemSlug.isQualified if itemSlug.isQualified
mod = @getMod itemSlug.mod mod = @getMod itemSlug.mod
if mod? if mod? then mod.findRecipes itemSlug, result
mod.findRecipes itemSlug, result
return result if result.length > 0
for mod in @_mods if result.length is 0
continue unless mod.enabled for mod in @_mods
mod.findRecipes itemSlug, result continue unless mod.enabled
mod.findRecipes itemSlug, result
result.sort (a, b)-> Recipe.compareFor a, b, itemSlug
return if result.length > 0 then result else null return if result.length > 0 then result else null
+6 -1
View File
@@ -101,7 +101,7 @@ module.exports = class ModVersion extends BaseModel
eachName: (callback)-> eachName: (callback)->
for slug in @_slugs for slug in @_slugs
callback @_names[slug.item] callback @_names[slug.item], slug
return this return this
findName: (itemSlug)-> findName: (itemSlug)->
@@ -126,6 +126,11 @@ module.exports = class ModVersion extends BaseModel
return this return this
eachRecipe: (callback)->
for itemSlugText, recipeList of @_recipes
for recipe in recipeList
callback recipe
findRecipes: (itemSlug, result=[])-> findRecipes: (itemSlug, result=[])->
recipeList = @_recipes[itemSlug.item] recipeList = @_recipes[itemSlug.item]
if recipeList? if recipeList?
+2 -2
View File
@@ -62,10 +62,10 @@ module.exports = class NameFinder
@modPack.eachMod (mod)=> @modPack.eachMod (mod)=>
return unless mod.enabled or @includeDisabledMods return unless mod.enabled or @includeDisabledMods
mod.eachName (name, slug)=> mod.eachName (name, itemSlug)=>
return if nameMap[name] return if nameMap[name]
item = mod.findItem slug item = mod.findItem itemSlug
if not @includeGatherable if not @includeGatherable
return unless item? and item.isCraftable return unless item? and item.isCraftable
+51
View File
@@ -31,8 +31,40 @@ module.exports = class Recipe extends BaseModel
options.logEvents ?= false options.logEvents ?= false
super attributes, options super attributes, options
# Class Methods ################################################################################
@compareFor: (a, b, itemSlug)->
aValue = a.itemSlug.matches itemSlug
bValue = b.itemSlug.matches itemSlug
if aValue isnt bValue
return -1 if aValue
return +1 if bValue
aValue = a.getQuantityProducedOf itemSlug
bValue = b.getQuantityProducedOf itemSlug
if aValue isnt bValue
return if aValue < bValue then -1 else +1
aValue = a.getInputCount()
bValue = b.getInputCount()
if aValue isnt bValue
return if aValue < bValue then -1 else +1
aValue = a.getOutputCount()
bValue = b.getOutputCount()
if aValue isnt bValue
return if aValue > bValue then -1 else +1
return 0
# Public Methods ############################################################################### # Public Methods ###############################################################################
getInputCount: ->
result = 0
for stack in @input
result += stack.quantity
return result
getItemSlugAt: (patternSlot)-> getItemSlugAt: (patternSlot)->
trueIndex = 0:0, 1:1, 2:2, 3:4, 4:5, 5:6, 6:8, 7:9, 8:10 trueIndex = 0:0, 1:1, 2:2, 3:4, 4:5, 5:6, 6:8, 7:9, 8:10
patternDigit = @pattern[trueIndex[patternSlot]] patternDigit = @pattern[trueIndex[patternSlot]]
@@ -44,6 +76,19 @@ module.exports = class Recipe extends BaseModel
return stack.itemSlug return stack.itemSlug
getOutputCount: ->
result = 0
for stack in @output
result += stack.quantity
return result
getQuantityProducedOf: (itemSlug)->
for stack in @output
if stack.itemSlug.matches itemSlug
return stack.quantity
return 0
produces: (itemSlug)-> produces: (itemSlug)->
for stack in @output for stack in @output
if stack.itemSlug.matches itemSlug if stack.itemSlug.matches itemSlug
@@ -51,6 +96,12 @@ module.exports = class Recipe extends BaseModel
return false return false
requires: (itemSlug)->
for stack in @input
if stack.itemSlug.matches itemSlug
return true
return false
# Object Overrides ############################################################################# # Object Overrides #############################################################################
toString: -> toString: ->