Convert codebase to using ItemSlug

* Flesh out the formerly incomplete ItemSlug class
* Convert all uses of text item slugs to use ItemSlug
* Move the ItemSlug class under models where it properly belongs
* Avoid the use of `slug` as a local variable or item attribute
  wherever possible to avoid confusion between various kinds of slugs
* Merge the InventoryParser class into the Inventory class as it is
  unlikely to need to support multiple versions
* Simplify the ModPack/Mod/ModVersion interfaces by replacing the use
  of various "helper" methods with equivalent use of more generic
  methods
* Update the various methods of ModPack/Mod/ModVersion to be able to
  work with qualified or unqualified ItemSlugs
* Remove the unused BaseCollection class
* Add tests for ItemSlug and update all other tests to reflect
  all the other changes
This commit is contained in:
Andrew Miner
2015-02-18 10:30:53 -08:00
parent 100ce1bc70
commit e88821d449
33 changed files with 624 additions and 535 deletions
+10 -9
View File
@@ -6,6 +6,7 @@ All rights reserved.
###
Item = require '../src/scripts/models/item'
ItemSlug = require '../src/scripts/models/item_slug'
Mod = require '../src/scripts/models/mod'
ModPack = require '../src/scripts/models/mod_pack'
ModVersion = require '../src/scripts/models/mod_version'
@@ -23,7 +24,7 @@ describe 'mod_pack.coffee', ->
minecraft.addModVersion new ModVersion modSlug:minecraft.slug, version:'1.7.10'
minecraft.activeModVersion.addItem new Item name:'Wool'
minecraft.activeModVersion.addItem new Item name:'Bed', recipes:['']
minecraft.activeModVersion.registerName 'iron_chestplate', 'Iron Chestplate'
minecraft.activeModVersion.registerName ItemSlug.slugify('iron_chestplate'), 'Iron Chestplate'
buildcraft = new Mod slug:'buildcraft', name:'Buildcraft'
buildcraft.addModVersion new ModVersion modSlug:buildcraft.slug, version:'6.2.6'
@@ -46,24 +47,24 @@ describe 'mod_pack.coffee', ->
describe 'findItem', ->
it 'can find an item by partial slug', ->
item = modPack.findItem 'wool'
item.qualifiedSlug.should.equal 'minecraft__wool'
item = modPack.findItem ItemSlug.slugify 'wool'
item.slug.qualified.should.equal 'minecraft__wool'
it 'can find an item by full slug', ->
item = modPack.findItem 'minecraft__wool'
item = modPack.findItem ItemSlug.slugify 'minecraft__wool'
item.name.should.equal 'Wool'
it 'can find an ambiguous item by full slug', ->
buildcraft.activeVersion = Mod.Version.Latest
industrialCraft.activeVersion = Mod.Version.Latest
item = modPack.findItem 'industrial_craft__wrench'
item = modPack.findItem ItemSlug.slugify 'industrial_craft__wrench'
item.name.should.equal 'Wrench'
item.modVersion.mod.name.should.equal 'Industrial Craft'
it 'can find an ambiguous item by partial slug', ->
buildcraft.activeVersion = Mod.Version.Latest
industrialCraft.activeVersion = Mod.Version.Latest
item = modPack.findItem 'wrench'
item = modPack.findItem ItemSlug.slugify 'wrench'
item.name.should.equal 'Wrench'
item.modVersion.mod.name.should.equal 'Buildcraft'
@@ -80,7 +81,7 @@ describe 'mod_pack.coffee', ->
describe 'findItemDisplay', ->
it 'returns all data for a regular Minecraft item', ->
display = modPack.findItemDisplay 'bed'
display = modPack.findItemDisplay ItemSlug.slugify 'bed'
display.iconUrl.should.equal '/data/minecraft/1.7.10/images/bed.png'
display.itemUrl.should.equal '/mod/minecraft/bed'
display.itemName.should.equal 'Bed'
@@ -88,14 +89,14 @@ describe 'mod_pack.coffee', ->
it 'returns all data for an item in an enabled mod', ->
buildcraft.activeVersion = '6.2.6'
display = modPack.findItemDisplay 'stone_gear'
display = modPack.findItemDisplay ItemSlug.slugify 'stone_gear'
display.iconUrl.should.equal '/data/buildcraft/6.2.6/images/stone_gear.png'
display.itemUrl.should.equal '/mod/buildcraft/stone_gear'
display.itemName.should.equal 'Stone Gear'
display.modSlug.should.equal 'buildcraft'
it 'assumes an unfound item is from Minecraft', ->
display = modPack.findItemDisplay 'iron_chestplate'
display = modPack.findItemDisplay ItemSlug.slugify 'iron_chestplate'
display.iconUrl.should.equal '/data/minecraft/1.7.10/images/iron_chestplate.png'
display.itemUrl.should.equal '/mod/minecraft/iron_chestplate'
display.itemName.should.equal 'Iron Chestplate'