From 909a0a99391c18e1415203ebfa0fc131ea0d58b9 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Tue, 2 Feb 2021 12:00:31 +0100 Subject: [PATCH] lintfix: gomnd --- d2common/d2datautils/bitstream.go | 2 + d2common/d2datautils/stream_writer_test.go | 4 +- d2common/d2fileformats/d2dcc/dcc_direction.go | 24 ++- .../d2dcc/dcc_direction_frame.go | 9 ++ d2common/d2fileformats/d2ds1/ds1.go | 1 + d2common/d2util/stringutils.go | 1 + d2core/d2audio/sound_environment.go | 2 +- d2core/d2gui/box.go | 3 + d2core/d2gui/common.go | 1 + d2core/d2gui/layout.go | 2 + d2core/d2gui/layout_scrollbar.go | 3 + d2core/d2item/diablo2item/item_property.go | 6 +- d2core/d2map/d2mapengine/engine.go | 2 + d2core/d2map/d2mapentity/player.go | 1 + d2core/d2map/d2mapstamp/stamp.go | 2 + d2core/d2render/ebiten/ebiten_surface.go | 1 + d2core/d2term/terminal.go | 3 +- d2core/d2ui/button.go | 1 + d2core/d2ui/label.go | 1 + d2core/d2ui/textbox.go | 1 + d2game/d2gamescreen/character_select.go | 22 ++- d2game/d2player/inventory_grid.go | 2 + d2game/d2player/mini_panel.go | 2 + d2game/d2player/party_panel.go | 144 +++++++++--------- d2game/d2player/quest_log.go | 4 +- 25 files changed, 151 insertions(+), 93 deletions(-) diff --git a/d2common/d2datautils/bitstream.go b/d2common/d2datautils/bitstream.go index 9e706d78..79bfdedf 100644 --- a/d2common/d2datautils/bitstream.go +++ b/d2common/d2datautils/bitstream.go @@ -39,6 +39,7 @@ func (v *BitStream) ReadBits(bitCount int) int { return -1 } + // nolint:gomnd // byte expresion result := v.current & (0xffff >> uint(maxBits-bitCount)) v.WasteBits(bitCount) @@ -51,6 +52,7 @@ func (v *BitStream) PeekByte() int { return -1 } + // nolint:gomnd // byte return v.current & 0xff } diff --git a/d2common/d2datautils/stream_writer_test.go b/d2common/d2datautils/stream_writer_test.go index 126425b4..025d185a 100644 --- a/d2common/d2datautils/stream_writer_test.go +++ b/d2common/d2datautils/stream_writer_test.go @@ -8,9 +8,7 @@ func TestStreamWriterByte(t *testing.T) { sr := CreateStreamWriter() data := []byte{0x12, 0x34, 0x56, 0x78} - for _, d := range data { - sr.PushByte(d) - } + sr.PushBytes(data...) output := sr.GetBytes() for i, d := range data { diff --git a/d2common/d2fileformats/d2dcc/dcc_direction.go b/d2common/d2fileformats/d2dcc/dcc_direction.go index bdd245cd..81a3b45b 100644 --- a/d2common/d2fileformats/d2dcc/dcc_direction.go +++ b/d2common/d2fileformats/d2dcc/dcc_direction.go @@ -9,6 +9,13 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2common/d2math" ) +const ( + baseMinx = 100000 + baseMiny = 100000 + baseMaxx = -100000 + baseMaxy = -100000 +) + const cellsPerRow = 4 // DCCDirection represents a DCCDirection file. @@ -37,7 +44,9 @@ type DCCDirection struct { } // CreateDCCDirection creates an instance of a DCCDirection. +// nolint:funlen // no need to reduce func CreateDCCDirection(bm *d2datautils.BitMuncher, file *DCC) *DCCDirection { + // nolint:gomnd // constant var crazyBitTable = []byte{0, 1, 2, 4, 6, 8, 10, 12, 14, 16, 20, 24, 26, 28, 30, 32} result := &DCCDirection{ @@ -53,10 +62,10 @@ func CreateDCCDirection(bm *d2datautils.BitMuncher, file *DCC) *DCCDirection { Frames: make([]*DCCDirectionFrame, file.FramesPerDirection), } - minx := 100000 - miny := 100000 - maxx := -100000 - maxy := -100000 + minx := baseMinx + miny := baseMiny + maxx := baseMaxx + maxy := baseMaxy // Load the frame headers for frameIdx := 0; frameIdx < file.FramesPerDirection; frameIdx++ { @@ -73,12 +82,14 @@ func CreateDCCDirection(bm *d2datautils.BitMuncher, file *DCC) *DCCDirection { log.Panic("Optional bits in DCC data is not currently supported.") } + // nolint:gomnd // byte operation if (result.CompressionFlags & 0x2) > 0 { result.EqualCellsBitstreamSize = int(bm.GetBits(20)) //nolint:gomnd // binary data } result.PixelMaskBitstreamSize = int(bm.GetBits(20)) //nolint:gomnd // binary data + // nolint:gomnd // byte operation if (result.CompressionFlags & 0x1) > 0 { result.EncodingTypeBitsreamSize = int(bm.GetBits(20)) //nolint:gomnd // binary data result.RawPixelCodesBitstreamSize = int(bm.GetBits(20)) //nolint:gomnd // binary data @@ -412,9 +423,12 @@ func (v *DCCDirection) calculateCells() { for i := 0; i < v.HorizontalCellCount-1; i++ { cellWidths[i] = 4 } + + // nolint:gomnd // constant cellWidths[v.HorizontalCellCount-1] = v.Box.Width - (4 * (v.HorizontalCellCount - 1)) } // Calculate the cell heights + // nolint:gomnd // constant cellHeights := make([]int, v.VerticalCellCount) if v.VerticalCellCount == 1 { cellHeights[0] = v.Box.Height @@ -422,6 +436,8 @@ func (v *DCCDirection) calculateCells() { for i := 0; i < v.VerticalCellCount-1; i++ { cellHeights[i] = 4 } + + // nolint:gomnd // constant cellHeights[v.VerticalCellCount-1] = v.Box.Height - (4 * (v.VerticalCellCount - 1)) } // Set the cell widths and heights in the cell buffer diff --git a/d2common/d2fileformats/d2dcc/dcc_direction_frame.go b/d2common/d2fileformats/d2dcc/dcc_direction_frame.go index 65b5f654..553f87be 100644 --- a/d2common/d2fileformats/d2dcc/dcc_direction_frame.go +++ b/d2common/d2fileformats/d2dcc/dcc_direction_frame.go @@ -55,6 +55,7 @@ func CreateDCCDirectionFrame(bits *d2datautils.BitMuncher, direction *DCCDirecti } func (v *DCCDirectionFrame) recalculateCells(direction *DCCDirection) { + // nolint:gomnd // constant var w = 4 - ((v.Box.Left - direction.Box.Left) % 4) // Width of the first column (in pixels) if (v.Width - w) <= 1 { @@ -62,6 +63,8 @@ func (v *DCCDirectionFrame) recalculateCells(direction *DCCDirection) { } else { tmp := v.Width - w - 1 v.HorizontalCellCount = 2 + (tmp / 4) //nolint:gomnd // magic math + + // nolint:gomnd // constant if (tmp % 4) == 0 { v.HorizontalCellCount-- } @@ -75,6 +78,8 @@ func (v *DCCDirectionFrame) recalculateCells(direction *DCCDirection) { } else { tmp := v.Height - h - 1 v.VerticalCellCount = 2 + (tmp / 4) //nolint:gomnd // data decode + + // nolint:gomnd // constant if (tmp % 4) == 0 { v.VerticalCellCount-- } @@ -88,6 +93,8 @@ func (v *DCCDirectionFrame) recalculateCells(direction *DCCDirection) { for i := 1; i < (v.HorizontalCellCount - 1); i++ { cellWidths[i] = 4 } + + // nolint:gomnd // constants cellWidths[v.HorizontalCellCount-1] = v.Width - w - (4 * (v.HorizontalCellCount - 2)) } @@ -99,6 +106,8 @@ func (v *DCCDirectionFrame) recalculateCells(direction *DCCDirection) { for i := 1; i < (v.VerticalCellCount - 1); i++ { cellHeights[i] = 4 } + + // nolint:gomnd // constants cellHeights[v.VerticalCellCount-1] = v.Height - h - (4 * (v.VerticalCellCount - 2)) } diff --git a/d2common/d2fileformats/d2ds1/ds1.go b/d2common/d2fileformats/d2ds1/ds1.go index e1154070..a27b8e7e 100644 --- a/d2common/d2fileformats/d2ds1/ds1.go +++ b/d2common/d2fileformats/d2ds1/ds1.go @@ -301,6 +301,7 @@ func (ds1 *DS1) setupStreamLayerTypes() []d2enum.LayerStreamType { d2enum.LayerStreamShadow, } } else { + // nolint:gomnd // constant layerStream = make([]d2enum.LayerStreamType, (ds1.NumberOfWalls*2)+ds1.NumberOfFloors+ds1.NumberOfShadowLayers+ds1.NumberOfSubstitutionLayers) diff --git a/d2common/d2util/stringutils.go b/d2common/d2util/stringutils.go index c9c859cb..d24347d5 100644 --- a/d2common/d2util/stringutils.go +++ b/d2common/d2util/stringutils.go @@ -93,6 +93,7 @@ func Utf16BytesToString(b []byte) (string, error) { lb := len(b) for i := 0; i < lb; i += 2 { + // nolint:gomnd // byte operation u16s[0] = uint16(b[i]) + (uint16(b[i+1]) << 8) r := utf16.Decode(u16s) n := utf8.EncodeRune(b8buf, r[0]) diff --git a/d2core/d2audio/sound_environment.go b/d2core/d2audio/sound_environment.go index d029824c..50f528fc 100644 --- a/d2core/d2audio/sound_environment.go +++ b/d2core/d2audio/sound_environment.go @@ -61,7 +61,7 @@ func (s *SoundEnvironment) Advance(elapsed float64) { snd := s.engine.PlaySoundID(s.environment.DayEvent) if snd != nil { - // nolint:gosec // client-side, no big deal if rand number isn't securely generated + // nolint:gosec,gomnd // client-side, no big deal if rand number isn't securely generated pan := (rand.Float64() * 2) - 1 snd.SetPan(pan) } diff --git a/d2core/d2gui/box.go b/d2core/d2gui/box.go index 63f42394..fb701c0e 100644 --- a/d2core/d2gui/box.go +++ b/d2core/d2gui/box.go @@ -414,6 +414,8 @@ func (box *Box) setupOptions(sectionHeight int) error { } cornerRight.SetPosition(box.x+box.width-boxSpriteWidth, offsetY) + + // nolint:gomnd // constant box.setupTopBorder(box.height - (4 * boxSpriteHeight) + boxSpriteHeight - boxBorderSpriteTopBorderSectionOffset) box.sprites = append(box.sprites, cornerLeft, cornerRight) } @@ -470,6 +472,7 @@ func (box *Box) Load() error { contentLayoutW, contentLayoutH := box.contentLayout.GetSize() contentLayoutX, contentLayoutY := box.contentLayout.GetPosition() box.contentLayout.SetPosition(contentLayoutX+box.paddingX, contentLayoutY+box.paddingY) + // nolint:gomnd // constant box.contentLayout.SetSize(contentLayoutW-(2*box.paddingX), contentLayoutH-(2*box.paddingY)) box.layout.AddLayoutFromSource(box.contentLayout) diff --git a/d2core/d2gui/common.go b/d2core/d2gui/common.go index 02dd2094..1d7b9792 100644 --- a/d2core/d2gui/common.go +++ b/d2core/d2gui/common.go @@ -33,5 +33,6 @@ func renderSegmented(animation d2interface.Animation, segmentsX, segmentsY, fram } func half(n int) int { + // nolint:gomnd // half is half return n / 2 } diff --git a/d2core/d2gui/layout.go b/d2core/d2gui/layout.go index 44c7f7a0..b6c487b5 100644 --- a/d2core/d2gui/layout.go +++ b/d2core/d2gui/layout.go @@ -509,7 +509,9 @@ func (l *Layout) createButton(renderer d2interface.Renderer, text string, switch buttonState(i) { case buttonStatePressed, buttonStatePressedToggled: + // nolint:gomnd // constant offset textOffsetX = -2 + // nolint:gomnd // constant offset textOffsetY = 2 } diff --git a/d2core/d2gui/layout_scrollbar.go b/d2core/d2gui/layout_scrollbar.go index 38bf2551..c667f070 100644 --- a/d2core/d2gui/layout_scrollbar.go +++ b/d2core/d2gui/layout_scrollbar.go @@ -67,6 +67,7 @@ const ( func NewLayoutScrollbar(parentLayout, targetLayout *Layout) *LayoutScrollbar { parentW, parentH := parentLayout.GetSize() _, targetH := targetLayout.GetSize() + // nolint:gomnd // constant gutterHeight := parentH - (2 * textSliderPartHeight) viewportPercentage := oneHundredPercent - (float32(targetH-parentH) / float32(targetH)) sliderHeight := int(float32(gutterHeight) * viewportPercentage) @@ -139,8 +140,10 @@ func (scrollbar *LayoutScrollbar) Load(ui *d2ui.UIManager) error { arrowDownSprite.SetPosition(arrowDownX, arrowDownY+textSliderPartHeight) scrollbar.arrowDownSprite = arrowDownSprite + // nolint:gomnd // constant gutterParts := int(math.Ceil(float64(scrollbar.gutterHeight+(2*textSliderPartHeight)) / float64(textSliderPartHeight))) sliderParts := int(math.Ceil(float64(scrollbar.sliderHeight) / float64(textSliderPartHeight))) + // nolint:gomnd // constant gutterX, gutterY := arrowUpX, arrowUpY+(2*textSliderPartHeight)-1 i := 0 diff --git a/d2core/d2item/diablo2item/item_property.go b/d2core/d2item/diablo2item/item_property.go index 86af8cd8..c7cf8147 100644 --- a/d2core/d2item/diablo2item/item_property.go +++ b/d2core/d2item/diablo2item/item_property.go @@ -7,6 +7,10 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2core/d2stats" ) +const ( + invalidHeroIndex = -1.0 +) + const ( noValue = iota oneValue @@ -272,8 +276,6 @@ func (p *Property) fnProcs(iscRecord *d2records.ItemStatCostRecord) d2stats.Stat func (p *Property) fnRandomSkill(iscRecord *d2records.ItemStatCostRecord) d2stats.Stat { var skillLevel, skillID float64 - invalidHeroIndex := -1.0 - switch len(p.inputParams) { case noValue, oneValue, twoValue: return nil diff --git a/d2core/d2map/d2mapengine/engine.go b/d2core/d2map/d2mapengine/engine.go index 0fc2b0fb..981cbd4c 100644 --- a/d2core/d2map/d2mapengine/engine.go +++ b/d2core/d2map/d2mapengine/engine.go @@ -270,6 +270,7 @@ func (m *MapEngine) GetStartPosition() (x, y float64) { tile := m.tiles[tileX+(tileY*m.size.Width)].Components for idx := range tile.Walls { if tile.Walls[idx].Type.Special() && tile.Walls[idx].Style == 30 { + // nolint:gomnd // constant return float64(tileX) + 0.5, float64(tileY) + 0.5 } } @@ -281,6 +282,7 @@ func (m *MapEngine) GetStartPosition() (x, y float64) { // GetCenterPosition returns the center point of the map. func (m *MapEngine) GetCenterPosition() (x, y float64) { + // nolint:gomnd // half of size return float64(m.size.Width) / 2.0, float64(m.size.Height) / 2.0 } diff --git a/d2core/d2map/d2mapentity/player.go b/d2core/d2map/d2mapentity/player.go index 4000350a..19a9ee85 100644 --- a/d2core/d2map/d2mapentity/player.go +++ b/d2core/d2map/d2mapentity/player.go @@ -260,6 +260,7 @@ func (p *Player) GetVelocity() d2vector.Vector { func (p *Player) GetSize() (width, height int) { width, height = p.composite.GetSize() // https://github.com/OpenDiablo2/OpenDiablo2/issues/820 + // nolint:gomnd // returns 1.5 of height height = (height * 2) - (height / 2) return width, height diff --git a/d2core/d2map/d2mapstamp/stamp.go b/d2core/d2map/d2mapstamp/stamp.go index 7438b396..31e16c07 100644 --- a/d2core/d2map/d2mapstamp/stamp.go +++ b/d2core/d2map/d2mapstamp/stamp.go @@ -83,6 +83,7 @@ func (mr *Stamp) Entities(tileOffsetX, tileOffsetY int) []d2interface.MapEntity // (See monpreset and monplace txts for reference) if monstat != nil { // Temorary use of Lookup. + // nolint:gomnd // constant modifier npcX, npcY := (tileOffsetX*5)+object.X, (tileOffsetY*5)+object.Y npc, err := mr.entity.NewNPC(npcX, npcY, monstat, 0) @@ -105,6 +106,7 @@ func (mr *Stamp) Entities(tileOffsetX, tileOffsetY int) []d2interface.MapEntity objectRecord := mr.factory.asset.Records.Object.Details[lookup.ObjectsTxtId] if objectRecord != nil { + // nolint:gomnd // constant entity, err := mr.entity.NewObject((tileOffsetX*5)+object.X, (tileOffsetY*5)+object.Y, objectRecord, d2resource.PaletteUnits) diff --git a/d2core/d2render/ebiten/ebiten_surface.go b/d2core/d2render/ebiten/ebiten_surface.go index 6060d9a7..1478e82a 100644 --- a/d2core/d2render/ebiten/ebiten_surface.go +++ b/d2core/d2render/ebiten/ebiten_surface.go @@ -303,6 +303,7 @@ func (s *ebitenSurface) colorToColorM(clr color.Color) ebiten.ColorM { return emptyColorM } + // nolint:gomnd // byte values key := colorMCacheKey(cr | (cg << 8) | (cb << 16) | (ca << 24)) e, ok := s.colorMCache[key] diff --git a/d2core/d2term/terminal.go b/d2core/d2term/terminal.go index 465905a0..146f3105 100644 --- a/d2core/d2term/terminal.go +++ b/d2core/d2term/terminal.go @@ -265,7 +265,7 @@ func (t *Terminal) Render(surface d2interface.Surface) error { outputHeight := t.lineCount * charHeight totalHeight := outputHeight + charHeight - offset := -int((1.0 - easeInOut(t.visAnim)) * float64(totalHeight)) + offset := -int((1 - easeInOut(t.visAnim)) * float64(totalHeight)) surface.PushTranslation(0, offset) surface.DrawRect(totalWidth, outputHeight, t.bgColor) @@ -412,6 +412,7 @@ func easeInOut(t float64) float64 { t -= 2 + // nolint:gomnd // constant return -0.5 * (t*t*t*t - 2) } diff --git a/d2core/d2ui/button.go b/d2core/d2ui/button.go index f3614941..48583a74 100644 --- a/d2core/d2ui/button.go +++ b/d2core/d2ui/button.go @@ -1151,5 +1151,6 @@ func (v *Button) SetTooltip(t *Tooltip) { } func half(n int) int { + // nolint:gomnd // half is half return n / 2 } diff --git a/d2core/d2ui/label.go b/d2core/d2ui/label.go index 4a09a322..9026697a 100644 --- a/d2core/d2ui/label.go +++ b/d2core/d2ui/label.go @@ -166,6 +166,7 @@ func (v *Label) getAlignOffset(textWidth int) int { case HorizontalAlignLeft: return 0 case HorizontalAlignCenter: + // nolint:gomnd // center of label = 1/2 of it return -textWidth / 2 case HorizontalAlignRight: return -textWidth diff --git a/d2core/d2ui/textbox.go b/d2core/d2ui/textbox.go index 20ab092b..3dc9fb19 100644 --- a/d2core/d2ui/textbox.go +++ b/d2core/d2ui/textbox.go @@ -72,6 +72,7 @@ func (v *TextBox) Render(target d2interface.Surface) { v.bgSprite.Render(target) v.textLabel.Render(target) + // nolint:gomnd // byte expressions if (time.Now().UnixNano()/1e6)&(1<<8) > 0 { v.lineBar.Render(target) } diff --git a/d2game/d2gamescreen/character_select.go b/d2game/d2gamescreen/character_select.go index feecc61a..78638b1b 100644 --- a/d2game/d2gamescreen/character_select.go +++ b/d2game/d2gamescreen/character_select.go @@ -19,6 +19,10 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2networking/d2client/d2clientconnectiontype" ) +const ( + indexPerLine = 2 +) + // CreateCharacterSelect creates the character select screen and returns a pointer to it func CreateCharacterSelect( navigator d2interface.Navigator, @@ -181,7 +185,8 @@ func (v *CharacterSelect) OnLoad(loading d2screen.LoadingState) { loading.Progress(fiftyPercent) for i := 0; i < 8; i++ { - offsetX, offsetY := rootLabelOffsetX, rootLabelOffsetY+((i/2)*95) + // nolint:gomnd // consant + offsetX, offsetY := rootLabelOffsetX, rootLabelOffsetY+((i/indexPerLine)*95) if i&1 > 0 { offsetX = 385 @@ -312,7 +317,7 @@ func (v *CharacterSelect) updateCharacterBoxes() { expText := v.asset.TranslateString("#803") for i := 0; i < 8; i++ { - idx := i + (v.charScrollbar.GetCurrentOffset() * 2) + idx := i + (v.charScrollbar.GetCurrentOffset() * indexPerLine) if idx >= len(v.gameStates) { v.characterNameLabel[i].SetText("") @@ -360,14 +365,14 @@ func (v *CharacterSelect) Render(screen d2interface.Surface) { v.background.RenderSegmented(screen, 4, 3, 0) v.d2HeroTitle.Render(screen) - actualSelectionIndex := v.selectedCharacter - (v.charScrollbar.GetCurrentOffset() * 2) + actualSelectionIndex := v.selectedCharacter - (v.charScrollbar.GetCurrentOffset() * indexPerLine) if v.selectedCharacter > -1 && actualSelectionIndex >= 0 && actualSelectionIndex < 8 { v.selectionBox.RenderSegmented(screen, 2, 1, 0) } for i := 0; i < 8; i++ { - idx := i + (v.charScrollbar.GetCurrentOffset() * 2) + idx := i + (v.charScrollbar.GetCurrentOffset() * indexPerLine) if idx >= len(v.gameStates) { continue } @@ -399,10 +404,11 @@ func (v *CharacterSelect) moveSelectionBox() { bw := 272 bh := 92 - selectedIndex := v.selectedCharacter - (v.charScrollbar.GetCurrentOffset() * 2) + + selectedIndex := v.selectedCharacter - (v.charScrollbar.GetCurrentOffset() * indexPerLine) selBoxX := selectionBoxOffsetX + ((selectedIndex & 1) * bw) - selBoxY := selectionBoxOffsetY + (bh * (selectedIndex / 2)) + selBoxY := selectionBoxOffsetY + (bh * (selectedIndex / indexPerLine)) v.selectionBox.SetPosition(selBoxX, selBoxY) v.d2HeroTitle.SetText(v.gameStates[v.selectedCharacter].HeroName) } @@ -440,8 +446,8 @@ func (v *CharacterSelect) OnMouseButtonDown(event d2interface.MouseEvent) bool { } // Make sure selection takes the scrollbar into account to make proper selection. - if (v.charScrollbar.GetCurrentOffset()*2)+selectedIndex < len(v.gameStates) { - selectedIndex = (v.charScrollbar.GetCurrentOffset() * 2) + selectedIndex + if (v.charScrollbar.GetCurrentOffset()*indexPerLine)+selectedIndex < len(v.gameStates) { + selectedIndex = (v.charScrollbar.GetCurrentOffset() * indexPerLine) + selectedIndex } // if the selection box didn't move, check if it was a double click, otherwise set selectedCharacter to diff --git a/d2game/d2player/inventory_grid.go b/d2game/d2player/inventory_grid.go index 981d9761..9c791bd2 100644 --- a/d2game/d2player/inventory_grid.go +++ b/d2game/d2player/inventory_grid.go @@ -273,7 +273,9 @@ func (g *ItemGrid) renderEquippedItems(target d2interface.Surface) { itemSprite := g.sprites[eq.item.GetItemCode()] itemWidth, itemHeight := itemSprite.GetCurrentFrameSize() + // nolint:gomnd // 1/2 ov width x := eq.x + ((eq.width - itemWidth) / 2) + // nolint:gomnd // 1/2 ov height y := eq.y - ((eq.height - itemHeight) / 2) g.renderItem(eq.item, target, x, y) diff --git a/d2game/d2player/mini_panel.go b/d2game/d2player/mini_panel.go index 0332f3aa..00a45d44 100644 --- a/d2game/d2player/mini_panel.go +++ b/d2game/d2player/mini_panel.go @@ -167,6 +167,8 @@ func (m *miniPanel) createButtons(actions *miniPanelActions) { actions.partyToggle, m.asset.TranslateString("minipanelparty"), } + + // nolint:gomnd // party buton is 3 in order btn := m.createButton(partyContent, x+(3*buttonWidth), y, buttonHeight) m.panelGroup.AddWidget(btn) idxOffset++ diff --git a/d2game/d2player/party_panel.go b/d2game/d2player/party_panel.go index e4cf383a..88b273ce 100644 --- a/d2game/d2player/party_panel.go +++ b/d2game/d2player/party_panel.go @@ -60,6 +60,78 @@ const ( indexOffset = 52 ) +// NewPartyPanel creates a new party panel +func NewPartyPanel(asset *d2asset.AssetManager, + ui *d2ui.UIManager, + heroName string, + l d2util.LogLevel, + me *d2mapentity.Player, + heroState *d2hero.HeroStatsState, + players map[string]*d2mapentity.Player) *PartyPanel { + log.Print("OpenDiablo2 - Party Panel - development") + + originX := 0 + originY := 0 + + pp := &PartyPanel{ + asset: asset, + uiManager: ui, + originX: originX, + originY: originY, + heroState: heroState, + heroName: heroName, + labels: &StatsPanelLabels{}, + barX: barX, + barY: baseBarY, + players: players, + me: me, + } + + var partyIndexes [d2enum.MaxPlayersInGame]*partyIndex + + var indexes [d2enum.MaxPlayersInGame]*d2ui.WidgetGroup + + for i := 0; i < d2enum.MaxPlayersInGame; i++ { + partyIndexes[i] = pp.newPartyIndex() + indexes[i] = pp.uiManager.NewWidgetGroup(d2ui.RenderPriorityHeroStatsPanel) + } + + pp.partyIndexes = partyIndexes + + pp.Logger = d2util.NewLogger() + pp.Logger.SetLevel(l) + pp.Logger.SetPrefix(logPrefix) + + return pp +} + +// PartyPanel represents the party panel +type PartyPanel struct { + asset *d2asset.AssetManager + uiManager *d2ui.UIManager + panel *d2ui.Sprite + bar *d2ui.Sprite + heroState *d2hero.HeroStatsState + heroName string + labels *StatsPanelLabels + onCloseCb func() + panelGroup *d2ui.WidgetGroup + + partyIndexes [d2enum.MaxPlayersInGame]*partyIndex + indexes [d2enum.MaxPlayersInGame]*d2ui.WidgetGroup + + players map[string]*d2mapentity.Player + me *d2mapentity.Player + + originX int + originY int + isOpen bool + barX int + barY int + + *d2util.Logger +} + // newPartyIndex creates new party index func (s *PartyPanel) newPartyIndex() *partyIndex { result := &partyIndex{ @@ -227,78 +299,6 @@ func (pi *partyIndex) CanGoHostile() bool { return pi.hero.Stats.Level >= d2enum.PlayersHostileLevel && pi.me.Stats.Level >= d2enum.PlayersHostileLevel } -// NewPartyPanel creates a new party panel -func NewPartyPanel(asset *d2asset.AssetManager, - ui *d2ui.UIManager, - heroName string, - l d2util.LogLevel, - me *d2mapentity.Player, - heroState *d2hero.HeroStatsState, - players map[string]*d2mapentity.Player) *PartyPanel { - log.Print("OpenDiablo2 - Party Panel - development") - - originX := 0 - originY := 0 - - pp := &PartyPanel{ - asset: asset, - uiManager: ui, - originX: originX, - originY: originY, - heroState: heroState, - heroName: heroName, - labels: &StatsPanelLabels{}, - barX: barX, - barY: baseBarY, - players: players, - me: me, - } - - var partyIndexes [d2enum.MaxPlayersInGame]*partyIndex - - var indexes [d2enum.MaxPlayersInGame]*d2ui.WidgetGroup - - for i := 0; i < d2enum.MaxPlayersInGame; i++ { - partyIndexes[i] = pp.newPartyIndex() - indexes[i] = pp.uiManager.NewWidgetGroup(d2ui.RenderPriorityHeroStatsPanel) - } - - pp.partyIndexes = partyIndexes - - pp.Logger = d2util.NewLogger() - pp.Logger.SetLevel(l) - pp.Logger.SetPrefix(logPrefix) - - return pp -} - -// PartyPanel represents the party panel -type PartyPanel struct { - asset *d2asset.AssetManager - uiManager *d2ui.UIManager - panel *d2ui.Sprite - bar *d2ui.Sprite - heroState *d2hero.HeroStatsState - heroName string - labels *StatsPanelLabels - onCloseCb func() - panelGroup *d2ui.WidgetGroup - - partyIndexes [d2enum.MaxPlayersInGame]*partyIndex - indexes [d2enum.MaxPlayersInGame]*d2ui.WidgetGroup - - players map[string]*d2mapentity.Player - me *d2mapentity.Player - - originX int - originY int - isOpen bool - barX int - barY int - - *d2util.Logger -} - // Load the data for the hero status panel func (s *PartyPanel) Load() { var err error diff --git a/d2game/d2player/quest_log.go b/d2game/d2player/quest_log.go index 4de2b90f..bb8214b1 100644 --- a/d2game/d2player/quest_log.go +++ b/d2game/d2player/quest_log.go @@ -53,7 +53,7 @@ const ( const questCompleteAnimationDuration = 3 -func (s *QuestLog) getPositionForSocket(number int) (x, y int) { +func getPositionForSocket(number int) (x, y int) { pos := []struct { x int y int @@ -312,7 +312,7 @@ func (s *QuestLog) loadQuestBoard(act int) (wg *d2ui.WidgetGroup, icons []*d2ui. for n := 0; n < questsInAct; n++ { cw := n - x, y := s.getPositionForSocket(n) + x, y := getPositionForSocket(n) socket, err := s.uiManager.NewSprite(d2resource.QuestLogSocket, d2resource.PaletteSky) if err != nil {