diff --git a/d2common/d2enum/item_armor_class.go b/d2common/d2enum/item_armor_class.go index 7c94735a..9490c013 100644 --- a/d2common/d2enum/item_armor_class.go +++ b/d2common/d2enum/item_armor_class.go @@ -1,7 +1,9 @@ package d2enum +// ArmorClass is a 3-character token for the armor. It's used for speed calculations. type ArmorClass string +// Armor classes const ( ArmorClassLite = "lit" ArmorClassMedium = "med" diff --git a/d2common/d2enum/skill_class.go b/d2common/d2enum/skill_class.go index 1c6208d3..76dd7f32 100644 --- a/d2common/d2enum/skill_class.go +++ b/d2common/d2enum/skill_class.go @@ -2,10 +2,11 @@ package d2enum import "log" +// SkillClass represents the skills for a character class type SkillClass int +// Skill classes const ( - // SkillClassGeneric is "" SkillClassGeneric SkillClass = iota SkillClassBarbarian SkillClassNecromancer diff --git a/d2core/d2map/d2mapgen/act1_overworld.go b/d2core/d2map/d2mapgen/act1_overworld.go index b319abaf..840cfacb 100644 --- a/d2core/d2map/d2mapgen/act1_overworld.go +++ b/d2core/d2map/d2mapgen/act1_overworld.go @@ -29,7 +29,7 @@ const ( mapWidth = 150 mapHeight = mapWidth mapMargin = 9 - autoFileIndex = d2mapstamp.AutoFileIndex + autoFileIndex = -1 ) // GenerateAct1Overworld generates the map and entities for the first town and surrounding area. diff --git a/d2core/d2map/d2mapstamp/factory.go b/d2core/d2map/d2mapstamp/factory.go index 479c6ef5..70afea00 100644 --- a/d2core/d2map/d2mapstamp/factory.go +++ b/d2core/d2map/d2mapstamp/factory.go @@ -13,10 +13,6 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset" ) -const ( - AutoFileIndex = -1 -) - // NewStampFactory creates a MapStamp factory instance func NewStampFactory(asset *d2asset.AssetManager, entity *d2mapentity.MapEntityFactory) *StampFactory { return &StampFactory{asset, entity} @@ -67,6 +63,7 @@ func (f *StampFactory) LoadStamp(levelType d2enum.RegionIdType, levelPreset, fil } } + // nolint:gosec // not a big deal for now levelIndex := int(math.Round(float64(len(levelFilesToPick)-1) * rand.Float64())) if fileIndex >= 0 && fileIndex < len(levelFilesToPick) { levelIndex = fileIndex diff --git a/d2core/d2ui/frame.go b/d2core/d2ui/frame.go index bf85d6ce..c4c5ba16 100644 --- a/d2core/d2ui/frame.go +++ b/d2core/d2ui/frame.go @@ -8,22 +8,25 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset" ) +type frameOrientation = int + +// Frame orientations +const ( + FrameLeft frameOrientation = iota + FrameRight +) + +// UIFrame is a representation of a ui panel that occupies the left or right half of the screen +// when it is visible. type UIFrame struct { asset *d2asset.AssetManager uiManager *UIManager frame *Sprite originX int originY int - frameOrientation FrameOrientation + frameOrientation frameOrientation } -type FrameOrientation = int - -const ( - FrameLeft FrameOrientation = iota - FrameRight -) - // frame indices into dc6 images for panels const ( leftFrameTopLeft = iota @@ -38,12 +41,11 @@ const ( rightFrameBottomLeft ) -type offsetCalcFn = func(u *UIFrame) (x, y int) - +// NewUIFrame creates a new Frame instance func NewUIFrame( asset *d2asset.AssetManager, uiManager *UIManager, - frameOrientation FrameOrientation, + frameOrientation frameOrientation, ) *UIFrame { var originX, originY = 0, 0 @@ -55,6 +57,7 @@ func NewUIFrame( originX = 400 originY = 0 } + frame := &UIFrame{ asset: asset, uiManager: uiManager, @@ -63,17 +66,21 @@ func NewUIFrame( originY: originY, } frame.Load() + return frame } +// Load the necessary frame resources func (u *UIFrame) Load() { sprite, err := u.uiManager.NewSprite(d2resource.Frame, d2resource.PaletteSky) if err != nil { log.Print(err) } + u.frame = sprite } +// Render the frame to the target surface func (u *UIFrame) Render(target d2interface.Surface) error { switch u.frameOrientation { case FrameLeft: @@ -81,6 +88,7 @@ func (u *UIFrame) Render(target d2interface.Surface) error { case FrameRight: return u.renderRight(target) } + return nil } @@ -200,10 +208,12 @@ func (u *UIFrame) renderRight(target d2interface.Surface) error { return nil } +// GetFrameBounds returns the maximum width and height of all frames in sprite. func (u *UIFrame) GetFrameBounds() (width, height int) { return u.frame.GetFrameBounds() } +// GetFrameCount returns the number of frames in the sprite func (u *UIFrame) GetFrameCount() int { return u.frame.GetFrameCount() } diff --git a/d2game/d2player/hero_stats_panel.go b/d2game/d2player/hero_stats_panel.go index 51ee226a..a18ef4cf 100644 --- a/d2game/d2player/hero_stats_panel.go +++ b/d2game/d2player/hero_stats_panel.go @@ -168,7 +168,7 @@ func (s *HeroStatsPanel) Close() { s.onCloseCb() } -// Set the callback run on closing the HeroStatsPanel +// SetOnCloseCb the callback run on closing the HeroStatsPanel func (s *HeroStatsPanel) SetOnCloseCb(cb func()) { s.onCloseCb = cb } diff --git a/d2game/d2player/inventory.go b/d2game/d2player/inventory.go index d2235ff9..ecea40e4 100644 --- a/d2game/d2player/inventory.go +++ b/d2game/d2player/inventory.go @@ -40,15 +40,15 @@ type Inventory struct { grid *ItemGrid hoverLabel *d2ui.Label closeButton *d2ui.Button - hoverX int - hoverY int - originX int - originY int - lastMouseX int - lastMouseY int - hovering bool - isOpen bool - onCloseCb func() + hoverX int + hoverY int + originX int + originY int + lastMouseX int + lastMouseY int + hovering bool + isOpen bool + onCloseCb func() } // NewInventory creates an inventory instance and returns a pointer to it @@ -99,9 +99,9 @@ func (g *Inventory) Close() { g.onCloseCb() } -// Set the callback run on closing the inventory +// SetOnCloseCb the callback run on closing the inventory func (g *Inventory) SetOnCloseCb(cb func()) { - g.onCloseCb = cb + g.onCloseCb = cb } // Load the resources required by the inventory