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

fix lint errors in d2interface (#684)

- fixed lint errors in d2interface
- removed `archived_` from interface names, was not necessary
- removed the Bitmuncher and Bitstream interfaces, as they are too specific and unnecessary
This commit is contained in:
lord 2020-08-04 19:53:36 -07:00 committed by GitHub
parent aa4a936fde
commit fe992699b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 33 additions and 68 deletions

View File

@ -1,9 +1,5 @@
package d2common
import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
var _ d2interface.BitMuncher = &BitMuncher{} // Static check to confirm struct conforms to interface
// BitMuncher is used for parsing files that are not byte-aligned such as the DCC files.
type BitMuncher struct {
data []byte
@ -19,17 +15,17 @@ const (
)
// CreateBitMuncher Creates a BitMuncher
func CreateBitMuncher(data []byte, offset int) d2interface.BitMuncher {
func CreateBitMuncher(data []byte, offset int) *BitMuncher {
return (&BitMuncher{}).Init(data, offset)
}
// CopyBitMuncher Creates a copy of the source BitMuncher
func CopyBitMuncher(source d2interface.BitMuncher) d2interface.BitMuncher {
func CopyBitMuncher(source *BitMuncher) *BitMuncher {
return source.Copy()
}
// Init initializes the BitMuncher with data and an offset
func (v *BitMuncher) Init(data []byte, offset int) d2interface.BitMuncher {
func (v *BitMuncher) Init(data []byte, offset int) *BitMuncher {
v.data = data
v.offset = offset
v.bitsRead = 0
@ -38,7 +34,7 @@ func (v *BitMuncher) Init(data []byte, offset int) d2interface.BitMuncher {
}
// Copy returns a copy of a BitMuncher
func (v BitMuncher) Copy() d2interface.BitMuncher {
func (v BitMuncher) Copy() *BitMuncher {
v.bitsRead = 0
return &v
}

View File

@ -2,12 +2,8 @@ package d2common
import (
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
)
var _ d2interface.BitStream = &BitStream{} // Static check to confirm struct conforms to interface
const (
maxBits = 16
bitsPerByte = 8

View File

@ -3,8 +3,6 @@ package d2dcc
import (
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
)
@ -36,7 +34,8 @@ type DCCDirection struct {
}
// CreateDCCDirection creates an instance of a DCCDirection.
func CreateDCCDirection(bm d2interface.BitMuncher, file *DCC) *DCCDirection { //nolint:funlen // Can't reduce
func CreateDCCDirection(bm *d2common.BitMuncher,
file *DCC) *DCCDirection { //nolint:funlen // Can't reduce
var crazyBitTable = []byte{0, 1, 2, 4, 6, 8, 10, 12, 14, 16, 20, 24, 26, 28, 30, 32}
result := &DCCDirection{}
@ -154,7 +153,7 @@ func CreateDCCDirection(bm d2interface.BitMuncher, file *DCC) *DCCDirection { //
}
//nolint:gocognit nolint:gocyclo // Can't reduce
func (v *DCCDirection) generateFrames(pcd d2interface.BitMuncher) {
func (v *DCCDirection) generateFrames(pcd *d2common.BitMuncher) {
pbIdx := 0
for _, cell := range v.Cells {
@ -257,7 +256,7 @@ func (v *DCCDirection) generateFrames(pcd d2interface.BitMuncher) {
}
//nolint:funlen nolint:gocognit // can't reduce
func (v *DCCDirection) fillPixelBuffer(pcd, ec, pm, et, rp d2interface.BitMuncher) {
func (v *DCCDirection) fillPixelBuffer(pcd, ec, pm, et, rp *d2common.BitMuncher) {
var pixelMaskLookup = []int{0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4}
lastPixel := uint32(0)

View File

@ -3,8 +3,6 @@ package d2dcc
import (
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
)
@ -26,7 +24,7 @@ type DCCDirectionFrame struct {
}
// CreateDCCDirectionFrame Creates a DCCDirectionFrame for a DCC.
func CreateDCCDirectionFrame(bits d2interface.BitMuncher, direction *DCCDirection) *DCCDirectionFrame {
func CreateDCCDirectionFrame(bits *d2common.BitMuncher, direction *DCCDirection) *DCCDirectionFrame {
result := &DCCDirectionFrame{}
bits.GetBits(direction.Variable0Bits) // Variable0

View File

@ -2,7 +2,8 @@ package d2interface
import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
type ArchivedAnimationManager interface {
// AnimationManager loads animations
type AnimationManager interface {
Cacher
LoadAnimation(animationPath, palettePath string, drawEffect d2enum.DrawEffect) (Animation, error)
}

View File

@ -1,6 +0,0 @@
package d2interface
type ArchivedPaletteManager interface {
Cacher
LoadPalette(palettePath string) (Palette, error)
}

View File

@ -1,18 +0,0 @@
package d2interface
type BitMuncher interface {
Init(data []byte, offset int) BitMuncher
Copy() BitMuncher
Offset() int
SetOffset(int)
BitsRead() int
SetBitsRead(int)
GetBit() uint32
SkipBits(bits int)
GetByte() byte
GetInt32() int32
GetUInt32() uint32
GetBits(bits int) uint32
GetSignedBits(bits int) int
MakeSigned(value uint32, bits int) int32
}

View File

@ -1,8 +0,0 @@
package d2interface
type BitStream interface {
ReadBits(bitCount int) int
PeekByte() int
EnsureBits(bitCount int) bool
WasteBits(bitCount int)
}

View File

@ -1,8 +1,8 @@
package d2interface
// ArchivedFileManager manages file access to the archives being managed
// FileManager manages file access to the archives being managed
// by the ArchiveManager
type ArchivedFileManager interface {
type FileManager interface {
Cacher
LoadFileStream(filePath string) (ArchiveDataStream, error)
LoadFile(filePath string) ([]byte, error)

View File

@ -1,8 +1,8 @@
package d2interface
// ArchivedFontManager manages fonts that are in archives being
// FontManager manages fonts that are in archives being
// managed by the ArchiveManager
type ArchivedFontManager interface {
type FontManager interface {
Cacher
LoadFont(tablePath, spritePath, palettePath string) (Font, error)
}

View File

@ -0,0 +1,7 @@
package d2interface
// PaletteManager is responsible for loading palettes
type PaletteManager interface {
Cacher
LoadPalette(palettePath string) (Palette, error)
}

View File

@ -15,7 +15,7 @@ const (
)
// Static checks to confirm struct conforms to interface
var _ d2interface.ArchivedAnimationManager = &animationManager{}
var _ d2interface.AnimationManager = &animationManager{}
var _ d2interface.Cacher = &animationManager{}
type animationManager struct {

View File

@ -14,7 +14,7 @@ const (
)
// Static checks to confirm struct conforms to interface
var _ d2interface.ArchivedFileManager = &fileManager{}
var _ d2interface.FileManager = &fileManager{}
var _ d2interface.Cacher = &fileManager{}
type fileManager struct {
@ -24,7 +24,7 @@ type fileManager struct {
}
func createFileManager(config *d2config.Configuration,
archiveManager d2interface.ArchiveManager) d2interface.ArchivedFileManager {
archiveManager d2interface.ArchiveManager) d2interface.FileManager {
return &fileManager{
d2common.CreateCache(fileBudget),
archiveManager,

View File

@ -9,11 +9,11 @@ import (
type assetManager struct {
archiveManager d2interface.ArchiveManager
archivedFileManager d2interface.ArchivedFileManager
paletteManager d2interface.ArchivedPaletteManager
archivedFileManager d2interface.FileManager
paletteManager d2interface.PaletteManager
paletteTransformManager *paletteTransformManager
animationManager d2interface.ArchivedAnimationManager
fontManager d2interface.ArchivedFontManager
animationManager d2interface.AnimationManager
fontManager d2interface.FontManager
}
func loadDC6(dc6Path string) (*d2dc6.DC6, error) {

View File

@ -12,14 +12,14 @@ const (
)
// Static checks to confirm struct conforms to interface
var _ d2interface.ArchivedFontManager = &fontManager{}
var _ d2interface.FontManager = &fontManager{}
var _ d2interface.Cacher = &fontManager{}
type fontManager struct {
cache d2interface.Cache
}
func createFontManager() d2interface.ArchivedFontManager {
func createFontManager() d2interface.FontManager {
return &fontManager{d2common.CreateCache(fontBudget)}
}

View File

@ -7,7 +7,7 @@ import (
)
// Static checks to confirm struct conforms to interface
var _ d2interface.ArchivedPaletteManager = &paletteManager{}
var _ d2interface.PaletteManager = &paletteManager{}
var _ d2interface.Cacher = &paletteManager{}
type paletteManager struct {
@ -18,7 +18,7 @@ const (
paletteBudget = 64
)
func createPaletteManager() d2interface.ArchivedPaletteManager {
func createPaletteManager() d2interface.PaletteManager {
return &paletteManager{d2common.CreateCache(paletteBudget)}
}