Re-write Inventory.localize to avoid a bug
The bug was that arriving at the crafting page by following a link wouldn't show the correct URL. The crafting would still work, but the URL would be incorrect.
This commit is contained in:
@@ -76,21 +76,37 @@ module.exports = class Inventory extends BaseModel
|
||||
localize: ->
|
||||
if not @modPack? then throw new Error 'localize requires @modPack'
|
||||
|
||||
changed = false
|
||||
newSlugs = []
|
||||
newStacks = []
|
||||
for itemSlug in @_itemSlugs
|
||||
stack = @_stacks[itemSlug]
|
||||
continue unless stack?
|
||||
|
||||
qualifiedSlug = if itemSlug.isQualified then itemSlug else null
|
||||
if not qualifiedSlug?
|
||||
qualifiedSlug = @modPack.findItem(itemSlug)?.slug
|
||||
changed = qualifiedSlug?
|
||||
|
||||
if qualifiedSlug?
|
||||
delete @_stacks[itemSlug]
|
||||
newSlugs.push qualifiedSlug
|
||||
@_stacks[qualifiedSlug] = stack
|
||||
stack.itemSlug = qualifiedSlug
|
||||
newStacks.push new Stack itemSlug:qualifiedSlug, stack.quantity
|
||||
else
|
||||
newSlugs.push itemSlug
|
||||
newStacks.push stack
|
||||
|
||||
if changed
|
||||
for itemSlug, stack of @_stacks
|
||||
@stopListening stack
|
||||
|
||||
@_itemSlugs = newSlugs
|
||||
@_stacks = {}
|
||||
for stack in newStacks
|
||||
@_stacks[stack.itemSlug] = stack
|
||||
@listenTo stack, Event.change, => @trigger Event.change, this
|
||||
|
||||
@_sort()
|
||||
@trigger Event.change, this
|
||||
|
||||
pop: ->
|
||||
itemSlug = @_itemSlugs.pop()
|
||||
|
||||
Reference in New Issue
Block a user