1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-12-25 19:46:50 -05:00

clean up error handling in d2game/d2player/inventory.go and d2core/d2item/diablo2item/

This commit is contained in:
M. Sz 2020-12-10 13:15:18 +01:00
parent d302263ac1
commit 509dfda5e5
3 changed files with 21 additions and 6 deletions

View File

@ -419,9 +419,17 @@ var testAssetManager *d2asset.AssetManager
var testItemFactory *ItemFactory var testItemFactory *ItemFactory
func TestSetup(t *testing.T) { func TestSetup(t *testing.T) {
var err error
testAssetManager = &d2asset.AssetManager{} testAssetManager = &d2asset.AssetManager{}
testAssetManager.Records = &d2records.RecordManager{} testAssetManager.Records = &d2records.RecordManager{}
testItemFactory, _ = NewItemFactory(testAssetManager)
testItemFactory, err = NewItemFactory(testAssetManager)
if err != nil {
t.Error(err)
return
}
testAssetManager.Records.Item.Stats = itemStatCosts testAssetManager.Records.Item.Stats = itemStatCosts
testAssetManager.Records.Character.Stats = charStats testAssetManager.Records.Character.Stats = charStats
testAssetManager.Records.Skill.Details = skillDetails testAssetManager.Records.Skill.Details = skillDetails

View File

@ -208,7 +208,12 @@ func NewGameControls(
heroStatsPanel := NewHeroStatsPanel(asset, ui, hero.Name(), hero.Class, l, hero.Stats) heroStatsPanel := NewHeroStatsPanel(asset, ui, hero.Name(), hero.Class, l, hero.Stats)
questLog := NewQuestLog(asset, ui, l, hero.Act) questLog := NewQuestLog(asset, ui, l, hero.Act)
inventory := NewInventory(asset, ui, l, hero.Gold, inventoryRecord)
inventory, err := NewInventory(asset, ui, l, hero.Gold, inventoryRecord)
if err != nil {
return nil, err
}
skilltree := newSkillTree(hero.Skills, hero.Class, asset, l, ui) skilltree := newSkillTree(hero.Skills, hero.Class, asset, l, ui)
miniPanel := newMiniPanel(asset, ui, l, isSinglePlayer) miniPanel := newMiniPanel(asset, ui, l, isSinglePlayer)

View File

@ -32,11 +32,13 @@ func NewInventory(asset *d2asset.AssetManager,
ui *d2ui.UIManager, ui *d2ui.UIManager,
l d2util.LogLevel, l d2util.LogLevel,
gold int, gold int,
record *d2records.InventoryRecord) *Inventory { record *d2records.InventoryRecord) (*Inventory, error) {
itemTooltip := ui.NewTooltip(d2resource.FontFormal11, d2resource.PaletteStatic, d2ui.TooltipXCenter, d2ui.TooltipYBottom) itemTooltip := ui.NewTooltip(d2resource.FontFormal11, d2resource.PaletteStatic, d2ui.TooltipXCenter, d2ui.TooltipYBottom)
// https://github.com/OpenDiablo2/OpenDiablo2/issues/797 itemFactory, err := diablo2item.NewItemFactory(asset)
itemFactory, _ := diablo2item.NewItemFactory(asset) if err != nil {
return nil, fmt.Errorf("during creating new item factory: %s", err)
}
inventory := &Inventory{ inventory := &Inventory{
asset: asset, asset: asset,
@ -54,7 +56,7 @@ func NewInventory(asset *d2asset.AssetManager,
inventory.Logger.SetLevel(l) inventory.Logger.SetLevel(l)
inventory.Logger.SetPrefix(logPrefix) inventory.Logger.SetPrefix(logPrefix)
return inventory return inventory, nil
} }
// Inventory represents the inventory // Inventory represents the inventory