1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-18 02:16:23 -05:00

Merge pull request #1041 from gucio321/lintfix

lintfix: gomnd
This commit is contained in:
Tim Sarbin 2021-02-02 08:53:52 -05:00 committed by GitHub
commit a2f298a8ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 151 additions and 93 deletions

View File

@ -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
}

View File

@ -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 {

View File

@ -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

View File

@ -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))
}

View File

@ -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)

View File

@ -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])

View File

@ -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)
}

View File

@ -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)

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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)

View File

@ -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]

View File

@ -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)
}

View File

@ -1151,5 +1151,6 @@ func (v *Button) SetTooltip(t *Tooltip) {
}
func half(n int) int {
// nolint:gomnd // half is half
return n / 2
}

View File

@ -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

View File

@ -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)
}

View File

@ -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

View File

@ -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)

View File

@ -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++

View File

@ -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

View File

@ -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 {