Allow "have" inventory to include non-craftables
This commit is contained in:
@@ -209,7 +209,7 @@
|
|||||||
"tools": "Macerator"
|
"tools": "Macerator"
|
||||||
}, {
|
}, {
|
||||||
"output": "Coal Ball",
|
"output": "Coal Ball",
|
||||||
"input": [[8, "Coal Dust"], "1 Flint"],
|
"input": [[8, "Coal Dust"], "Flint"],
|
||||||
"pattern": "000 010 000",
|
"pattern": "000 010 000",
|
||||||
"tools": "Crafting Table"
|
"tools": "Crafting Table"
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
@@ -21,10 +21,11 @@ module.exports = class InventoryController extends BaseController
|
|||||||
if not options.model? then throw new Error 'options.model is required'
|
if not options.model? then throw new Error 'options.model is required'
|
||||||
if not options.modPack? then throw new Error 'options.modPack is required'
|
if not options.modPack? then throw new Error 'options.modPack is required'
|
||||||
|
|
||||||
options.icon ?= '/images/chest_front.png'
|
options.icon ?= '/images/chest_front.png'
|
||||||
options.editable ?= true
|
options.editable ?= true
|
||||||
options.imageLoader ?= new ImageLoader defaultUrl:'/images/unknown.png'
|
options.imageLoader ?= new ImageLoader defaultUrl:'/images/unknown.png'
|
||||||
options.title ?= 'Inventory'
|
options.gatherNames ?= -> @modPack.gatherNames()
|
||||||
|
options.title ?= 'Inventory'
|
||||||
|
|
||||||
options.templateName = 'inventory'
|
options.templateName = 'inventory'
|
||||||
super options
|
super options
|
||||||
@@ -33,6 +34,7 @@ module.exports = class InventoryController extends BaseController
|
|||||||
@icon = options.icon
|
@icon = options.icon
|
||||||
@imageLoader = options.imageLoader
|
@imageLoader = options.imageLoader
|
||||||
@modPack = options.modPack
|
@modPack = options.modPack
|
||||||
|
@gatherNames = options.gatherNames
|
||||||
@title = options.title
|
@title = options.title
|
||||||
|
|
||||||
@_stackControllers = []
|
@_stackControllers = []
|
||||||
@@ -42,14 +44,15 @@ module.exports = class InventoryController extends BaseController
|
|||||||
# Event Methods ################################################################################
|
# Event Methods ################################################################################
|
||||||
|
|
||||||
onAddButtonClicked: ->
|
onAddButtonClicked: ->
|
||||||
item = @modPack.findItemByName @$nameField.val()
|
name = @$nameField.val()
|
||||||
return unless item?
|
return unless @modPack.isValidName name
|
||||||
|
|
||||||
@model.add item.slug, parseInt(@$quantityField.val())
|
@model.add _.slugify(name), parseInt(@$quantityField.val())
|
||||||
@$nameField.val ''
|
@$nameField.val ''
|
||||||
@$quantityField.val '1'
|
@$quantityField.val '1'
|
||||||
|
|
||||||
@$scrollbox.scrollTop @$scrollbox.prop 'scrollHeight'
|
@$scrollbox.scrollTop @$scrollbox.prop 'scrollHeight'
|
||||||
|
@$nameField.autocomplete 'close'
|
||||||
|
|
||||||
onClearButtonClicked: ->
|
onClearButtonClicked: ->
|
||||||
@model.clear()
|
@model.clear()
|
||||||
@@ -163,7 +166,7 @@ module.exports = class InventoryController extends BaseController
|
|||||||
onSelected = => @onItemSelected()
|
onSelected = => @onItemSelected()
|
||||||
|
|
||||||
@$nameField.autocomplete
|
@$nameField.autocomplete
|
||||||
source: @modPack.gatherRecipeNames()
|
source: @gatherNames()
|
||||||
delay: 0
|
delay: 0
|
||||||
minLength: 0
|
minLength: 0
|
||||||
change: onChanged
|
change: onChanged
|
||||||
|
|||||||
@@ -25,27 +25,28 @@ module.exports = class ItemPageController extends BaseController
|
|||||||
# BaseController Overrides #####################################################################
|
# BaseController Overrides #####################################################################
|
||||||
|
|
||||||
onDidRender: ->
|
onDidRender: ->
|
||||||
|
@wantController = @addChild InventoryController, '.want',
|
||||||
|
editable: true
|
||||||
|
icon: '/images/fishing_rod.png'
|
||||||
|
imageLoader: @imageLoader
|
||||||
|
model: @model.plan.want
|
||||||
|
modPack: @model.modPack
|
||||||
|
title: 'Items you want'
|
||||||
|
|
||||||
@haveController = @addChild InventoryController, '.have',
|
@haveController = @addChild InventoryController, '.have',
|
||||||
editable: true,
|
editable: true,
|
||||||
imageLoader: @imageLoader
|
imageLoader: @imageLoader
|
||||||
model: @model.plan.have,
|
model: @model.plan.have
|
||||||
modPack: @model.modPack,
|
modPack: @model.modPack
|
||||||
|
gatherNames: -> @modPack.gatherNames includeGatherable:true
|
||||||
title: 'Items you have'
|
title: 'Items you have'
|
||||||
|
|
||||||
@wantController = @addChild InventoryController, '.want',
|
|
||||||
editable: true
|
|
||||||
icon: '/images/fishing_rod.png',
|
|
||||||
imageLoader: @imageLoader
|
|
||||||
model: @model.plan.want,
|
|
||||||
modPack: @model.modPack,
|
|
||||||
title: 'Items you want'
|
|
||||||
|
|
||||||
@needController = @addChild InventoryController, '.need',
|
@needController = @addChild InventoryController, '.need',
|
||||||
editable: false
|
editable: false
|
||||||
icon: '/images/boots.png',
|
icon: '/images/boots.png'
|
||||||
imageLoader: @imageLoader
|
imageLoader: @imageLoader
|
||||||
model: @model.plan.need,
|
model: @model.plan.need
|
||||||
modPack: @model.modPack,
|
modPack: @model.modPack
|
||||||
title: "Items you'll need"
|
title: "Items you'll need"
|
||||||
|
|
||||||
@craftingTableController = @addChild CraftingTableController, '.view__crafting_table',
|
@craftingTableController = @addChild CraftingTableController, '.view__crafting_table',
|
||||||
|
|||||||
@@ -76,13 +76,14 @@ module.exports = class ModPack extends BaseModel
|
|||||||
result.itemUrl = Url.item result
|
result.itemUrl = Url.item result
|
||||||
return result
|
return result
|
||||||
|
|
||||||
gatherRecipeNames: (options={})->
|
gatherNames: (options={})->
|
||||||
|
options.includeGatherable ?= false
|
||||||
options.includeDisabled ?= false
|
options.includeDisabled ?= false
|
||||||
|
|
||||||
nameData = {}
|
nameData = {}
|
||||||
for modVersion in @modVersions
|
for modVersion in @modVersions
|
||||||
continue unless modVersion.enabled or options.includeDisabled
|
continue unless modVersion.enabled or options.includeDisabled
|
||||||
modVersion.gatherRecipeNames nameData
|
modVersion.gatherNames nameData, options
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
names = _.keys(nameData).sort()
|
names = _.keys(nameData).sort()
|
||||||
@@ -102,6 +103,17 @@ module.exports = class ModPack extends BaseModel
|
|||||||
isLoading: ->
|
isLoading: ->
|
||||||
return @loading.inspect().state isnt 'pending'
|
return @loading.inspect().state isnt 'pending'
|
||||||
|
|
||||||
|
isValidName: (name, options={})->
|
||||||
|
options.includeDisabled ?= false
|
||||||
|
|
||||||
|
slug = _.slugify name
|
||||||
|
for modVersion in @modVersions
|
||||||
|
continue unless modVersion.enabled or options.includeDisabled
|
||||||
|
name = modVersion.findName slug
|
||||||
|
return true if name
|
||||||
|
|
||||||
|
return false
|
||||||
|
|
||||||
loadModVersion: (url)->
|
loadModVersion: (url)->
|
||||||
promise = w.promise (resolve, reject)=>
|
promise = w.promise (resolve, reject)=>
|
||||||
@trigger Event.load.started, this, url
|
@trigger Event.load.started, this, url
|
||||||
|
|||||||
@@ -53,12 +53,20 @@ module.exports = class ModVersion extends BaseModel
|
|||||||
findName: (slug)->
|
findName: (slug)->
|
||||||
return @names[slug]
|
return @names[slug]
|
||||||
|
|
||||||
gatherRecipeNames: (result={})->
|
gatherNames: (result={}, options={})->
|
||||||
|
options.includeGatherable ?= false
|
||||||
|
|
||||||
for slug, item of @items
|
for slug, item of @items
|
||||||
continue if result[item.slug]
|
continue if result[item.slug]
|
||||||
continue unless item.isCraftable
|
if item.isGatherable
|
||||||
|
continue unless options.includeGatherable
|
||||||
result[item.slug] = value:item.name, label:"#{item.name} (from #{@name} #{@version})"
|
result[item.slug] = value:item.name, label:"#{item.name} (from #{@name} #{@version})"
|
||||||
|
|
||||||
|
if options.includeGatherable
|
||||||
|
for slug, name of @names
|
||||||
|
continue if result[slug]
|
||||||
|
result[slug] = value:name, label:"#{name} (from #{@name} #{@version})"
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
hasRecipe: (name)->
|
hasRecipe: (name)->
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
//-
|
//-
|
||||||
|
|
||||||
.view__item_page
|
.view__item_page
|
||||||
.view__inventory.have
|
|
||||||
.view__inventory.want
|
.view__inventory.want
|
||||||
|
.view__inventory.have
|
||||||
.view__inventory.need
|
.view__inventory.need
|
||||||
|
|
||||||
.view__crafting_table
|
.view__crafting_table
|
||||||
|
|||||||
Reference in New Issue
Block a user