mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-06-12 02:30:43 +00:00
lint and minor refactor of d2common (#690)
- moved contents of `d2common/math.go` into `d2math/math.go` - removed lint errors from files in d2common
This commit is contained in:
parent
319e1f0245
commit
8e41133f39
|
@ -6,6 +6,7 @@ import (
|
||||||
"container/ring"
|
"container/ring"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||||
"image"
|
"image"
|
||||||
"image/gif"
|
"image/gif"
|
||||||
"image/png"
|
"image/png"
|
||||||
|
@ -547,7 +548,7 @@ func (a *App) convertFramesToGif() error {
|
||||||
framesPal[j] = framePal.(*image.Paletted)
|
framesPal[j] = framePal.(*image.Paletted)
|
||||||
frameDelays[j] = 5
|
frameDelays[j] = 5
|
||||||
}
|
}
|
||||||
}(i, d2common.MinInt(i+framesPerCPU, framesTotal))
|
}(i, d2math.MinInt(i+framesPerCPU, framesTotal))
|
||||||
}
|
}
|
||||||
|
|
||||||
waitGroup.Wait()
|
waitGroup.Wait()
|
||||||
|
|
|
@ -5,4 +5,5 @@ package d2common
|
||||||
// source, for instance a missile might have a movement speed of lvl*2
|
// source, for instance a missile might have a movement speed of lvl*2
|
||||||
type CalcString string
|
type CalcString string
|
||||||
|
|
||||||
// todo: the logic for parsing these should exist here
|
// Issue #689
|
||||||
|
// info about calcstrings can be found here: https://d2mods.info/forum/kb/viewarticle?a=371
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package d2dcc
|
package d2dcc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
||||||
|
@ -57,10 +58,10 @@ func CreateDCCDirection(bm *d2common.BitMuncher,
|
||||||
// Load the frame headers
|
// Load the frame headers
|
||||||
for frameIdx := 0; frameIdx < file.FramesPerDirection; frameIdx++ {
|
for frameIdx := 0; frameIdx < file.FramesPerDirection; frameIdx++ {
|
||||||
result.Frames[frameIdx] = CreateDCCDirectionFrame(bm, result)
|
result.Frames[frameIdx] = CreateDCCDirectionFrame(bm, result)
|
||||||
minx = int(d2common.MinInt32(int32(result.Frames[frameIdx].Box.Left), int32(minx)))
|
minx = int(d2math.MinInt32(int32(result.Frames[frameIdx].Box.Left), int32(minx)))
|
||||||
miny = int(d2common.MinInt32(int32(result.Frames[frameIdx].Box.Top), int32(miny)))
|
miny = int(d2math.MinInt32(int32(result.Frames[frameIdx].Box.Top), int32(miny)))
|
||||||
maxx = int(d2common.MaxInt32(int32(result.Frames[frameIdx].Box.Right()), int32(maxx)))
|
maxx = int(d2math.MaxInt32(int32(result.Frames[frameIdx].Box.Right()), int32(maxx)))
|
||||||
maxy = int(d2common.MaxInt32(int32(result.Frames[frameIdx].Box.Bottom()), int32(maxy)))
|
maxy = int(d2math.MaxInt32(int32(result.Frames[frameIdx].Box.Bottom()), int32(maxy)))
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Box = d2common.Rectangle{Left: minx, Top: miny, Width: maxx - minx, Height: maxy - miny}
|
result.Box = d2common.Rectangle{Left: minx, Top: miny, Width: maxx - minx, Height: maxy - miny}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ func LoadDS1(fileData []byte) (*DS1, error) {
|
||||||
ds1.Height = br.GetInt32() + 1
|
ds1.Height = br.GetInt32() + 1
|
||||||
|
|
||||||
if ds1.Version >= 8 { //nolint:gomnd // Version number
|
if ds1.Version >= 8 { //nolint:gomnd // Version number
|
||||||
ds1.Act = d2common.MinInt32(maxActNumber, br.GetInt32()+1)
|
ds1.Act = d2math.MinInt32(maxActNumber, br.GetInt32()+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ds1.Version >= 10 { //nolint:gomnd // Version number
|
if ds1.Version >= 10 { //nolint:gomnd // Version number
|
||||||
|
|
|
@ -6,12 +6,12 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/JoshVarga/blast"
|
"github.com/JoshVarga/blast"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2compression"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2compression"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ func (v *Stream) readInternalSingleUnit(buffer []byte, offset, count uint32) uin
|
||||||
v.loadSingleUnit()
|
v.loadSingleUnit()
|
||||||
}
|
}
|
||||||
|
|
||||||
bytesToCopy := d2common.Min(uint32(len(v.CurrentData))-v.CurrentPosition, count)
|
bytesToCopy := d2math.Min(uint32(len(v.CurrentData))-v.CurrentPosition, count)
|
||||||
|
|
||||||
copy(buffer[offset:offset+bytesToCopy], v.CurrentData[v.CurrentPosition:v.CurrentPosition+bytesToCopy])
|
copy(buffer[offset:offset+bytesToCopy], v.CurrentData[v.CurrentPosition:v.CurrentPosition+bytesToCopy])
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ func (v *Stream) readInternal(buffer []byte, offset, count uint32) uint32 {
|
||||||
v.bufferData()
|
v.bufferData()
|
||||||
|
|
||||||
localPosition := v.CurrentPosition % v.BlockSize
|
localPosition := v.CurrentPosition % v.BlockSize
|
||||||
bytesToCopy := d2common.MinInt32(int32(len(v.CurrentData))-int32(localPosition), int32(count))
|
bytesToCopy := d2math.MinInt32(int32(len(v.CurrentData))-int32(localPosition), int32(count))
|
||||||
|
|
||||||
if bytesToCopy <= 0 {
|
if bytesToCopy <= 0 {
|
||||||
return 0
|
return 0
|
||||||
|
@ -153,7 +153,7 @@ func (v *Stream) bufferData() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedLength := d2common.Min(v.BlockTableEntry.UncompressedFileSize-(requiredBlock*v.BlockSize), v.BlockSize)
|
expectedLength := d2math.Min(v.BlockTableEntry.UncompressedFileSize-(requiredBlock*v.BlockSize), v.BlockSize)
|
||||||
v.CurrentData = v.loadBlock(requiredBlock, expectedLength)
|
v.CurrentData = v.loadBlock(requiredBlock, expectedLength)
|
||||||
v.CurrentBlockIndex = requiredBlock
|
v.CurrentBlockIndex = requiredBlock
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package d2math
|
package d2math
|
||||||
|
|
||||||
|
import "math"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Epsilon is used as the threshold for 'almost equal' operations.
|
// Epsilon is used as the threshold for 'almost equal' operations.
|
||||||
Epsilon float64 = 0.0001
|
Epsilon float64 = 0.0001
|
||||||
|
@ -88,3 +90,80 @@ func WrapInt(x, max int) int {
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MinInt returns the minimum of the given values
|
||||||
|
func MinInt(a, b int) int {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaxInt returns the maximum of the given values
|
||||||
|
func MaxInt(a, b int) int {
|
||||||
|
if a > b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// Min returns the lower of two values
|
||||||
|
func Min(a, b uint32) uint32 {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// Max returns the higher of two values
|
||||||
|
func Max(a, b uint32) uint32 {
|
||||||
|
if a > b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaxInt32 returns the higher of two values
|
||||||
|
func MaxInt32(a, b int32) int32 {
|
||||||
|
if a > b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// AbsInt32 returns the absolute of the given int32
|
||||||
|
func AbsInt32(a int32) int32 {
|
||||||
|
if a < 0 {
|
||||||
|
return -a
|
||||||
|
}
|
||||||
|
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
// MinInt32 returns the higher of two values
|
||||||
|
func MinInt32(a, b int32) int32 {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// BytesToInt32 converts 4 bytes to int32
|
||||||
|
|
||||||
|
// IsoToScreen converts isometric coordinates to screenspace coordinates
|
||||||
|
|
||||||
|
// ScreenToIso converts screenspace coordinates to isometric coordinates
|
||||||
|
|
||||||
|
// GetRadiansBetween returns the radians between two points. 0rad is facing to the right.
|
||||||
|
func GetRadiansBetween(p1X, p1Y, p2X, p2Y float64) float64 {
|
||||||
|
deltaY := p2Y - p1Y
|
||||||
|
deltaX := p2X - p1X
|
||||||
|
|
||||||
|
return math.Atan2(deltaY, deltaX)
|
||||||
|
}
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
package d2common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MinInt returns the minimum of the given values
|
|
||||||
func MinInt(a, b int) int {
|
|
||||||
if a < b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// MaxInt returns the maximum of the given values
|
|
||||||
func MaxInt(a, b int) int {
|
|
||||||
if a > b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// Min returns the lower of two values
|
|
||||||
func Min(a, b uint32) uint32 {
|
|
||||||
if a < b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// Max returns the higher of two values
|
|
||||||
func Max(a, b uint32) uint32 {
|
|
||||||
if a > b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// MaxInt32 returns the higher of two values
|
|
||||||
func MaxInt32(a, b int32) int32 {
|
|
||||||
if a > b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// AbsInt32 returns the absolute of the given int32
|
|
||||||
func AbsInt32(a int32) int32 {
|
|
||||||
if a < 0 {
|
|
||||||
return -a
|
|
||||||
}
|
|
||||||
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
// MinInt32 returns the higher of two values
|
|
||||||
func MinInt32(a, b int32) int32 {
|
|
||||||
if a < b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// BytesToInt32 converts 4 bytes to int32
|
|
||||||
|
|
||||||
// IsoToScreen converts isometric coordinates to screenspace coordinates
|
|
||||||
|
|
||||||
// ScreenToIso converts screenspace coordinates to isometric coordinates
|
|
||||||
|
|
||||||
// GetRadiansBetween returns the radians between two points. 0rad is facing to the right.
|
|
||||||
func GetRadiansBetween(p1X, p1Y, p2X, p2Y float64) float64 {
|
|
||||||
deltaY := p2Y - p1Y
|
|
||||||
deltaX := p2X - p1X
|
|
||||||
|
|
||||||
return math.Atan2(deltaY, deltaX)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AlmostEqual returns true if two values are within threshold from each other
|
|
||||||
func AlmostEqual(a, b, threshold float64) bool {
|
|
||||||
return math.Abs(a-b) <= threshold
|
|
||||||
}
|
|
|
@ -14,7 +14,7 @@ type textDictionaryHashEntry struct {
|
||||||
NameLength uint16
|
NameLength uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
var lookupTable map[string]string
|
var lookupTable map[string]string //nolint:gochecknoglobals // currently global by design
|
||||||
|
|
||||||
const (
|
const (
|
||||||
crcByteCount = 2
|
crcByteCount = 2
|
||||||
|
|
|
@ -2,6 +2,7 @@ package d2asset
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"math"
|
"math"
|
||||||
|
@ -10,7 +11,6 @@ import (
|
||||||
|
|
||||||
d2iface "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
d2iface "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dcc"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dcc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -207,8 +207,8 @@ func (a *animation) GetFrameBounds() (maxWidth, maxHeight int) {
|
||||||
|
|
||||||
direction := a.directions[a.directionIndex]
|
direction := a.directions[a.directionIndex]
|
||||||
for _, frame := range direction.frames {
|
for _, frame := range direction.frames {
|
||||||
maxWidth = d2common.MaxInt(maxWidth, frame.width)
|
maxWidth = d2math.MaxInt(maxWidth, frame.width)
|
||||||
maxHeight = d2common.MaxInt(maxHeight, frame.height)
|
maxHeight = d2math.MaxInt(maxHeight, frame.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
return maxWidth, maxHeight
|
return maxWidth, maxHeight
|
||||||
|
|
|
@ -2,11 +2,11 @@ package d2asset
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dcc"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dcc"
|
||||||
d2iface "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
d2iface "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||||
)
|
)
|
||||||
|
@ -90,10 +90,10 @@ func (a *DCCAnimation) decodeDirection(directionIndex int) error {
|
||||||
maxX, maxY := math.MinInt32, math.MinInt32
|
maxX, maxY := math.MinInt32, math.MinInt32
|
||||||
|
|
||||||
for _, dccFrame := range direction.Frames {
|
for _, dccFrame := range direction.Frames {
|
||||||
minX = d2common.MinInt(minX, dccFrame.Box.Left)
|
minX = d2math.MinInt(minX, dccFrame.Box.Left)
|
||||||
minY = d2common.MinInt(minY, dccFrame.Box.Top)
|
minY = d2math.MinInt(minY, dccFrame.Box.Top)
|
||||||
maxX = d2common.MaxInt(maxX, dccFrame.Box.Right())
|
maxX = d2math.MaxInt(maxX, dccFrame.Box.Right())
|
||||||
maxY = d2common.MaxInt(maxY, dccFrame.Box.Bottom())
|
maxY = d2math.MaxInt(maxY, dccFrame.Box.Bottom())
|
||||||
}
|
}
|
||||||
|
|
||||||
frameWidth := maxX - minX
|
frameWidth := maxX - minX
|
||||||
|
|
|
@ -3,10 +3,10 @@ package d2asset
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||||
"image/color"
|
"image/color"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -80,17 +80,17 @@ func (f *Font) GetTextMetrics(text string) (width, height int) {
|
||||||
|
|
||||||
for _, c := range text {
|
for _, c := range text {
|
||||||
if c == '\n' {
|
if c == '\n' {
|
||||||
totalWidth = d2common.MaxInt(totalWidth, lineWidth)
|
totalWidth = d2math.MaxInt(totalWidth, lineWidth)
|
||||||
totalHeight += lineHeight
|
totalHeight += lineHeight
|
||||||
lineWidth = 0
|
lineWidth = 0
|
||||||
lineHeight = 0
|
lineHeight = 0
|
||||||
} else if glyph, ok := f.glyphs[c]; ok {
|
} else if glyph, ok := f.glyphs[c]; ok {
|
||||||
lineWidth += glyph.width
|
lineWidth += glyph.width
|
||||||
lineHeight = d2common.MaxInt(lineHeight, glyph.height)
|
lineHeight = d2math.MaxInt(lineHeight, glyph.height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
totalWidth = d2common.MaxInt(totalWidth, lineWidth)
|
totalWidth = d2math.MaxInt(totalWidth, lineWidth)
|
||||||
totalHeight += lineHeight
|
totalHeight += lineHeight
|
||||||
|
|
||||||
return totalWidth, totalHeight
|
return totalWidth, totalHeight
|
||||||
|
@ -122,7 +122,7 @@ func (f *Font) RenderText(text string, target d2interface.Surface) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
lineHeight = d2common.MaxInt(lineHeight, glyph.height)
|
lineHeight = d2math.MaxInt(lineHeight, glyph.height)
|
||||||
lineLength++
|
lineLength++
|
||||||
|
|
||||||
target.PushTranslation(glyph.width, 0)
|
target.PushTranslation(glyph.width, 0)
|
||||||
|
|
|
@ -2,11 +2,11 @@ package d2gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ func renderSegmented(animation d2interface.Animation, segmentsX, segmentsY, fram
|
||||||
}
|
}
|
||||||
|
|
||||||
width, height := animation.GetCurrentFrameSize()
|
width, height := animation.GetCurrentFrameSize()
|
||||||
maxHeight = d2common.MaxInt(maxHeight, height)
|
maxHeight = d2math.MaxInt(maxHeight, height)
|
||||||
currentX += width
|
currentX += width
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package d2gui
|
||||||
import (
|
import (
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||||
)
|
)
|
||||||
|
|
||||||
type layoutEntry struct {
|
type layoutEntry struct {
|
||||||
|
@ -258,14 +259,14 @@ func (l *Layout) getContentSize() (width, height int) {
|
||||||
|
|
||||||
switch l.positionType {
|
switch l.positionType {
|
||||||
case PositionTypeVertical:
|
case PositionTypeVertical:
|
||||||
width = d2common.MaxInt(width, w)
|
width = d2math.MaxInt(width, w)
|
||||||
height += h
|
height += h
|
||||||
case PositionTypeHorizontal:
|
case PositionTypeHorizontal:
|
||||||
width += w
|
width += w
|
||||||
height = d2common.MaxInt(height, h)
|
height = d2math.MaxInt(height, h)
|
||||||
case PositionTypeAbsolute:
|
case PositionTypeAbsolute:
|
||||||
width = d2common.MaxInt(width, x+w)
|
width = d2math.MaxInt(width, x+w)
|
||||||
height = d2common.MaxInt(height, y+h)
|
height = d2math.MaxInt(height, y+h)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +275,7 @@ func (l *Layout) getContentSize() (width, height int) {
|
||||||
|
|
||||||
func (l *Layout) getSize() (width, height int) {
|
func (l *Layout) getSize() (width, height int) {
|
||||||
width, height = l.getContentSize()
|
width, height = l.getContentSize()
|
||||||
return d2common.MaxInt(width, l.width), d2common.MaxInt(height, l.height)
|
return d2math.MaxInt(width, l.width), d2math.MaxInt(height, l.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Layout) onMouseButtonDown(event d2interface.MouseEvent) bool {
|
func (l *Layout) onMouseButtonDown(event d2interface.MouseEvent) bool {
|
||||||
|
@ -348,8 +349,8 @@ func (l *Layout) AdjustEntryPlacement() {
|
||||||
expanderWidth = (width - contentWidth) / expanderCount
|
expanderWidth = (width - contentWidth) / expanderCount
|
||||||
}
|
}
|
||||||
|
|
||||||
expanderWidth = d2common.MaxInt(0, expanderWidth)
|
expanderWidth = d2math.MaxInt(0, expanderWidth)
|
||||||
expanderHeight = d2common.MaxInt(0, expanderHeight)
|
expanderHeight = d2math.MaxInt(0, expanderHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
var offsetX, offsetY int
|
var offsetX, offsetY int
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package d2maprenderer
|
package d2maprenderer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2ds1"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2ds1"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dt1"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dt1"
|
||||||
|
@ -77,11 +77,11 @@ func (mr *MapRenderer) generateFloorCache(tile *d2ds1.FloorShadowRecord) {
|
||||||
tileYMinimum := int32(0)
|
tileYMinimum := int32(0)
|
||||||
|
|
||||||
for _, block := range tileData[i].Blocks {
|
for _, block := range tileData[i].Blocks {
|
||||||
tileYMinimum = d2common.MinInt32(tileYMinimum, int32(block.Y))
|
tileYMinimum = d2math.MinInt32(tileYMinimum, int32(block.Y))
|
||||||
}
|
}
|
||||||
|
|
||||||
tileYOffset := d2common.AbsInt32(tileYMinimum)
|
tileYOffset := d2math.AbsInt32(tileYMinimum)
|
||||||
tileHeight := d2common.AbsInt32(tileData[i].Height)
|
tileHeight := d2math.AbsInt32(tileData[i].Height)
|
||||||
image, _ := mr.renderer.NewSurface(int(tileData[i].Width), int(tileHeight), d2enum.FilterNearest)
|
image, _ := mr.renderer.NewSurface(int(tileData[i].Width), int(tileHeight), d2enum.FilterNearest)
|
||||||
indexData := make([]byte, tileData[i].Width*tileHeight)
|
indexData := make([]byte, tileData[i].Width*tileHeight)
|
||||||
d2dt1.DecodeTileGfxData(tileData[i].Blocks, &indexData, tileYOffset, tileData[i].Width)
|
d2dt1.DecodeTileGfxData(tileData[i].Blocks, &indexData, tileYOffset, tileData[i].Width)
|
||||||
|
@ -111,8 +111,8 @@ func (mr *MapRenderer) generateShadowCache(tile *d2ds1.FloorShadowRecord) {
|
||||||
tileMaxY := int32(0)
|
tileMaxY := int32(0)
|
||||||
|
|
||||||
for _, block := range tileData.Blocks {
|
for _, block := range tileData.Blocks {
|
||||||
tileMinY = d2common.MinInt32(tileMinY, int32(block.Y))
|
tileMinY = d2math.MinInt32(tileMinY, int32(block.Y))
|
||||||
tileMaxY = d2common.MaxInt32(tileMaxY, int32(block.Y+32))
|
tileMaxY = d2math.MaxInt32(tileMaxY, int32(block.Y+32))
|
||||||
}
|
}
|
||||||
|
|
||||||
tileYOffset := -tileMinY
|
tileYOffset := -tileMinY
|
||||||
|
@ -160,11 +160,11 @@ func (mr *MapRenderer) generateWallCache(tile *d2ds1.WallRecord) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, block := range target.Blocks {
|
for _, block := range target.Blocks {
|
||||||
tileMinY = d2common.MinInt32(tileMinY, int32(block.Y))
|
tileMinY = d2math.MinInt32(tileMinY, int32(block.Y))
|
||||||
tileMaxY = d2common.MaxInt32(tileMaxY, int32(block.Y+32))
|
tileMaxY = d2math.MaxInt32(tileMaxY, int32(block.Y+32))
|
||||||
}
|
}
|
||||||
|
|
||||||
realHeight := d2common.MaxInt32(d2common.AbsInt32(tileData.Height), tileMaxY-tileMinY)
|
realHeight := d2math.MaxInt32(d2math.AbsInt32(tileData.Height), tileMaxY-tileMinY)
|
||||||
tileYOffset := -tileMinY
|
tileYOffset := -tileMinY
|
||||||
|
|
||||||
if tile.Type == 15 {
|
if tile.Type == 15 {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package d2term
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||||
"image/color"
|
"image/color"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
|
@ -11,7 +12,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||||
)
|
)
|
||||||
|
@ -114,9 +114,9 @@ func (t *terminal) OnKeyDown(event d2interface.KeyEvent) bool {
|
||||||
case d2enum.KeyEnd:
|
case d2enum.KeyEnd:
|
||||||
t.outputIndex = 0
|
t.outputIndex = 0
|
||||||
case d2enum.KeyHome:
|
case d2enum.KeyHome:
|
||||||
t.outputIndex = d2common.MaxInt(0, len(t.outputHistory)-t.lineCount)
|
t.outputIndex = d2math.MaxInt(0, len(t.outputHistory)-t.lineCount)
|
||||||
case d2enum.KeyPageUp:
|
case d2enum.KeyPageUp:
|
||||||
maxOutputIndex := d2common.MaxInt(0, len(t.outputHistory)-t.lineCount)
|
maxOutputIndex := d2math.MaxInt(0, len(t.outputHistory)-t.lineCount)
|
||||||
if t.outputIndex += t.lineCount; t.outputIndex >= maxOutputIndex {
|
if t.outputIndex += t.lineCount; t.outputIndex >= maxOutputIndex {
|
||||||
t.outputIndex = maxOutputIndex
|
t.outputIndex = maxOutputIndex
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ func (t *terminal) handleControlKey(eventKey d2enum.Key, keyMod d2enum.KeyMod) {
|
||||||
switch eventKey {
|
switch eventKey {
|
||||||
case d2enum.KeyUp:
|
case d2enum.KeyUp:
|
||||||
if keyMod == d2enum.KeyModControl {
|
if keyMod == d2enum.KeyModControl {
|
||||||
t.lineCount = d2common.MaxInt(0, t.lineCount-1)
|
t.lineCount = d2math.MaxInt(0, t.lineCount-1)
|
||||||
} else if len(t.commandHistory) > 0 {
|
} else if len(t.commandHistory) > 0 {
|
||||||
t.command = t.commandHistory[t.commandIndex]
|
t.command = t.commandHistory[t.commandIndex]
|
||||||
if t.commandIndex == 0 {
|
if t.commandIndex == 0 {
|
||||||
|
@ -179,7 +179,7 @@ func (t *terminal) handleControlKey(eventKey d2enum.Key, keyMod d2enum.KeyMod) {
|
||||||
}
|
}
|
||||||
case d2enum.KeyDown:
|
case d2enum.KeyDown:
|
||||||
if keyMod == d2enum.KeyModControl {
|
if keyMod == d2enum.KeyModControl {
|
||||||
t.lineCount = d2common.MinInt(t.lineCount+1, termRowCountMax)
|
t.lineCount = d2math.MinInt(t.lineCount+1, termRowCountMax)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,12 @@ package d2ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sprite is a positioned visual object.
|
// Sprite is a positioned visual object.
|
||||||
|
@ -67,7 +66,7 @@ func (s *Sprite) RenderSegmented(target d2interface.Surface, segmentsX, segments
|
||||||
}
|
}
|
||||||
|
|
||||||
frameWidth, frameHeight := s.GetCurrentFrameSize()
|
frameWidth, frameHeight := s.GetCurrentFrameSize()
|
||||||
maxFrameHeight = d2common.MaxInt(maxFrameHeight, frameHeight)
|
maxFrameHeight = d2math.MaxInt(maxFrameHeight, frameHeight)
|
||||||
currentX += frameWidth
|
currentX += frameWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,10 @@ package d2client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
|
||||||
|
@ -240,7 +240,7 @@ func (g *GameClient) handleCastSkillPacket(packet d2netpacket.NetPacket) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
rads := d2common.GetRadiansBetween(
|
rads := d2math.GetRadiansBetween(
|
||||||
player.Position.X(),
|
player.Position.X(),
|
||||||
player.Position.Y(),
|
player.Position.Y(),
|
||||||
playerCast.TargetX*numSubtilesPerTile,
|
playerCast.TargetX*numSubtilesPerTile,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user