Skip to content

Commit

Permalink
Move d2config to d2core, remove d2helper (OpenDiablo2#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
FooSoft authored Feb 2, 2020
1 parent b5c1f52 commit ea4450f
Show file tree
Hide file tree
Showing 30 changed files with 83 additions and 96 deletions.
2 changes: 1 addition & 1 deletion d2common/d2data/d2datadict/level_presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"log"
"strings"

dh "github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
dh "github.com/OpenDiablo2/OpenDiablo2/d2common"
)

type LevelPresetRecord struct {
Expand Down
2 changes: 1 addition & 1 deletion d2common/d2data/d2datadict/level_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"log"
"strings"

dh "github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
dh "github.com/OpenDiablo2/OpenDiablo2/d2common"
)

type LevelTypeRecord struct {
Expand Down
2 changes: 1 addition & 1 deletion d2common/d2data/d2datadict/map_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package d2datadict
import (
"strings"

dh "github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
dh "github.com/OpenDiablo2/OpenDiablo2/d2common"
)

func MapHeaders(line string) map[string]int {
Expand Down
3 changes: 1 addition & 2 deletions d2common/d2data/d2datadict/missiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"strings"

"github.com/OpenDiablo2/OpenDiablo2/d2common"

dh "github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
dh "github.com/OpenDiablo2/OpenDiablo2/d2common"
)

type MissileCalcParam struct {
Expand Down
2 changes: 1 addition & 1 deletion d2common/d2data/d2datadict/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"log"
"strings"

dh "github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
dh "github.com/OpenDiablo2/OpenDiablo2/d2common"
)

// An ObjectRecord represents the settings for one type of object from objects.txt
Expand Down
2 changes: 1 addition & 1 deletion d2common/d2data/d2datadict/sounds.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"log"
"strings"

dh "github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
dh "github.com/OpenDiablo2/OpenDiablo2/d2common"
)

// SoundEntry represents a sound entry
Expand Down
2 changes: 1 addition & 1 deletion d2common/d2data/d2datadict/unique_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/OpenDiablo2/OpenDiablo2/d2common"

dh "github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
dh "github.com/OpenDiablo2/OpenDiablo2/d2common"
)

type UniqueItemRecord struct {
Expand Down
9 changes: 4 additions & 5 deletions d2common/d2fileformats/d2dcc/dcc_direction.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"log"

"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
)

type DCCDirection struct {
Expand Down Expand Up @@ -50,10 +49,10 @@ func CreateDCCDirection(bm *d2common.BitMuncher, file DCC) DCCDirection {
// Load the frame headers
for frameIdx := 0; frameIdx < file.FramesPerDirection; frameIdx++ {
result.Frames[frameIdx] = CreateDCCDirectionFrame(bm, result)
minx = int(d2helper.MinInt32(int32(result.Frames[frameIdx].Box.Left), int32(minx)))
miny = int(d2helper.MinInt32(int32(result.Frames[frameIdx].Box.Top), int32(miny)))
maxx = int(d2helper.MaxInt32(int32(result.Frames[frameIdx].Box.Right()), int32(maxx)))
maxy = int(d2helper.MaxInt32(int32(result.Frames[frameIdx].Box.Bottom()), int32(maxy)))
minx = int(d2common.MinInt32(int32(result.Frames[frameIdx].Box.Left), int32(minx)))
miny = int(d2common.MinInt32(int32(result.Frames[frameIdx].Box.Top), int32(miny)))
maxx = int(d2common.MaxInt32(int32(result.Frames[frameIdx].Box.Right()), int32(maxx)))
maxy = int(d2common.MaxInt32(int32(result.Frames[frameIdx].Box.Bottom()), int32(maxy)))
}
result.Box = d2common.Rectangle{minx, miny, (maxx - minx), (maxy - miny)}
if result.OptionalDataBits > 0 {
Expand Down
3 changes: 1 addition & 2 deletions d2common/d2fileformats/d2ds1/ds1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
)

type DS1 struct {
Expand Down Expand Up @@ -37,7 +36,7 @@ func LoadDS1(fileData []byte) DS1 {
ds1.Width = br.GetInt32() + 1
ds1.Height = br.GetInt32() + 1
if ds1.Version >= 8 {
ds1.Act = d2helper.MinInt32(5, br.GetInt32()+1)
ds1.Act = d2common.MinInt32(5, br.GetInt32()+1)
}
if ds1.Version >= 10 {
ds1.SubstitutionType = br.GetInt32()
Expand Down
10 changes: 5 additions & 5 deletions d2common/d2fileformats/d2mpq/mpq_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"log"
"strings"

"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"

"github.com/JoshVarga/blast"

"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2compression"
)

Expand Down Expand Up @@ -104,7 +104,7 @@ func (v *Stream) readInternalSingleUnit(buffer []byte, offset, count uint32) uin
v.loadSingleUnit()
}

bytesToCopy := d2helper.Min(uint32(len(v.CurrentData))-v.CurrentPosition, count)
bytesToCopy := d2common.Min(uint32(len(v.CurrentData))-v.CurrentPosition, count)
copy(buffer[offset:offset+bytesToCopy], v.CurrentData[v.CurrentPosition:v.CurrentPosition+bytesToCopy])
v.CurrentPosition += bytesToCopy
return bytesToCopy
Expand All @@ -113,7 +113,7 @@ func (v *Stream) readInternalSingleUnit(buffer []byte, offset, count uint32) uin
func (v *Stream) readInternal(buffer []byte, offset, count uint32) uint32 {
v.bufferData()
localPosition := v.CurrentPosition % v.BlockSize
bytesToCopy := d2helper.MinInt32(int32(len(v.CurrentData))-int32(localPosition), int32(count))
bytesToCopy := d2common.MinInt32(int32(len(v.CurrentData))-int32(localPosition), int32(count))
if bytesToCopy <= 0 {
return 0
}
Expand All @@ -127,7 +127,7 @@ func (v *Stream) bufferData() {
if requiredBlock == v.CurrentBlockIndex {
return
}
expectedLength := d2helper.Min(v.BlockTableEntry.UncompressedFileSize-(requiredBlock*v.BlockSize), v.BlockSize)
expectedLength := d2common.Min(v.BlockTableEntry.UncompressedFileSize-(requiredBlock*v.BlockSize), v.BlockSize)
v.CurrentData = v.loadBlock(requiredBlock, expectedLength)
v.CurrentBlockIndex = requiredBlock
}
Expand Down
2 changes: 1 addition & 1 deletion d2common/d2helper/math.go → d2common/math.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package d2helper
package d2common

import "math"

Expand Down
4 changes: 2 additions & 2 deletions d2common/d2helper/stringutils.go → d2common/stringutils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package d2helper
package d2common

import (
"bytes"
Expand Down Expand Up @@ -141,7 +141,7 @@ func SplitIntoLinesWithMaxWidth(fullSentence string, maxChars int) []string {
}

func splitCjkIntoChunks(str string, chars int) []string {
chunks := make([]string, chars / len(str))
chunks := make([]string, chars/len(str))
i, count := 0, 0
for j, ch := range str {
if ch < unicode.MaxLatin1 {
Expand Down
2 changes: 1 addition & 1 deletion d2common/d2helper/timeutils.go → d2common/timeutils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package d2helper
package d2common

import "time"

Expand Down
14 changes: 7 additions & 7 deletions d2core/d2asset/animation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"image/color"
"math"

"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dc6"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dcc"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"

"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
Expand Down Expand Up @@ -60,10 +60,10 @@ func createAnimationFromDCC(dcc *d2dcc.DCC, palette *d2datadict.PaletteRec, tran
minX, minY := math.MaxInt32, math.MaxInt32
maxX, maxY := math.MinInt32, math.MinInt32
for _, dccFrame := range dccDirection.Frames {
minX = d2helper.MinInt(minX, dccFrame.Box.Left)
minY = d2helper.MinInt(minY, dccFrame.Box.Top)
maxX = d2helper.MaxInt(maxX, dccFrame.Box.Right())
maxY = d2helper.MaxInt(maxY, dccFrame.Box.Bottom())
minX = d2common.MinInt(minX, dccFrame.Box.Left)
minY = d2common.MinInt(minY, dccFrame.Box.Top)
maxX = d2common.MaxInt(maxX, dccFrame.Box.Right())
maxY = d2common.MaxInt(maxY, dccFrame.Box.Bottom())
}

frameWidth := maxX - minX
Expand Down Expand Up @@ -222,8 +222,8 @@ func (a *Animation) GetFrameBounds() (int, int) {

direction := a.directions[a.directionIndex]
for _, frame := range direction.frames {
maxWidth = d2helper.MaxInt(maxWidth, frame.width)
maxHeight = d2helper.MaxInt(maxHeight, frame.height)
maxWidth = d2common.MaxInt(maxWidth, frame.width)
maxHeight = d2common.MaxInt(maxHeight, frame.height)
}

return maxWidth, maxHeight
Expand Down
2 changes: 1 addition & 1 deletion d2core/d2asset/archive_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"sync"

"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2config"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2mpq"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2config"
)

type archiveEntry struct {
Expand Down
2 changes: 1 addition & 1 deletion d2core/d2asset/d2asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package d2asset
import (
"log"

"github.com/OpenDiablo2/OpenDiablo2/d2common/d2config"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2mpq"

"github.com/OpenDiablo2/OpenDiablo2/d2core/d2config"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2term"
)

Expand Down
3 changes: 2 additions & 1 deletion d2core/d2asset/file_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"strings"

"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2config"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"

"github.com/OpenDiablo2/OpenDiablo2/d2core/d2config"
)

const (
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions d2core/d2map/animated_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"math"
"math/rand"

"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
Expand Down Expand Up @@ -87,7 +87,7 @@ func (v *AnimatedEntity) getStepLength(tickTime float64) (float64, float64) {
speed := 6.0
length := tickTime * speed

angle := 359 - d2helper.GetAngleBetween(
angle := 359 - d2common.GetAngleBetween(
v.LocationX,
v.LocationY,
v.TargetX,
Expand All @@ -102,10 +102,10 @@ func (v *AnimatedEntity) getStepLength(tickTime float64) (float64, float64) {
func (v *AnimatedEntity) Step(tickTime float64) {
stepX, stepY := v.getStepLength(tickTime)

if d2helper.AlmostEqual(v.LocationX, v.TargetX, stepX) {
if d2common.AlmostEqual(v.LocationX, v.TargetX, stepX) {
v.LocationX = v.TargetX
}
if d2helper.AlmostEqual(v.LocationY, v.TargetY, stepY) {
if d2common.AlmostEqual(v.LocationY, v.TargetY, stepY) {
v.LocationY = v.TargetY
}
if v.LocationX != v.TargetX {
Expand Down Expand Up @@ -145,7 +145,7 @@ func (v *AnimatedEntity) Step(tickTime float64) {

// SetTarget sets target coordinates and changes animation based on proximity and direction
func (v *AnimatedEntity) SetTarget(tx, ty float64, action int32) {
angle := 359 - d2helper.GetAngleBetween(
angle := 359 - d2common.GetAngleBetween(
v.LocationX,
v.LocationY,
tx,
Expand Down
23 changes: 10 additions & 13 deletions d2core/d2map/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ import (
"math/rand"
"strconv"

"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"

"github.com/OpenDiablo2/OpenDiablo2/d2common"

"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"

"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2ds1"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dt1"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"

"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)

Expand Down Expand Up @@ -490,10 +487,10 @@ func (mr *MapRegion) generateFloorCache(tile *d2ds1.FloorShadowRecord, tileX, ti
}
tileYMinimum := int32(0)
for _, block := range tileData[i].Blocks {
tileYMinimum = d2helper.MinInt32(tileYMinimum, int32(block.Y))
tileYMinimum = d2common.MinInt32(tileYMinimum, int32(block.Y))
}
tileYOffset := d2helper.AbsInt32(tileYMinimum)
tileHeight := d2helper.AbsInt32(tileData[i].Height)
tileYOffset := d2common.AbsInt32(tileYMinimum)
tileHeight := d2common.AbsInt32(tileData[i].Height)
_, image := d2render.NewSurface(int(tileData[i].Width), int(tileHeight), d2render.FilterNearest)
pixels := make([]byte, 4*tileData[i].Width*tileHeight)
mr.decodeTileGfxData(tileData[i].Blocks, &pixels, tileYOffset, tileData[i].Width)
Expand All @@ -517,8 +514,8 @@ func (mr *MapRegion) generateShadowCache(tile *d2ds1.FloorShadowRecord, tileX, t
tileMinY := int32(0)
tileMaxY := int32(0)
for _, block := range tileData.Blocks {
tileMinY = d2helper.MinInt32(tileMinY, int32(block.Y))
tileMaxY = d2helper.MaxInt32(tileMaxY, int32(block.Y+32))
tileMinY = d2common.MinInt32(tileMinY, int32(block.Y))
tileMaxY = d2common.MaxInt32(tileMaxY, int32(block.Y+32))
}
tileYOffset := -tileMinY
tileHeight := int(tileMaxY - tileMinY)
Expand Down Expand Up @@ -566,11 +563,11 @@ func (mr *MapRegion) generateWallCache(tile *d2ds1.WallRecord, tileX, tileY int)
}

for _, block := range target.Blocks {
tileMinY = d2helper.MinInt32(tileMinY, int32(block.Y))
tileMaxY = d2helper.MaxInt32(tileMaxY, int32(block.Y+32))
tileMinY = d2common.MinInt32(tileMinY, int32(block.Y))
tileMaxY = d2common.MaxInt32(tileMaxY, int32(block.Y+32))
}

realHeight := d2helper.MaxInt32(d2helper.AbsInt32(tileData.Height), tileMaxY-tileMinY)
realHeight := d2common.MaxInt32(d2common.AbsInt32(tileData.Height), tileMaxY-tileMinY)
tileYOffset := -tileMinY
//tileHeight := int(tileMaxY - tileMinY)

Expand Down
7 changes: 3 additions & 4 deletions d2core/d2render/ebiten/ebiten_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"image"
"log"

"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"

"github.com/OpenDiablo2/OpenDiablo2/d2common/d2config"

"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"

"github.com/OpenDiablo2/OpenDiablo2/d2core/d2config"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)

type EbitenRenderer struct {
Expand Down
8 changes: 4 additions & 4 deletions d2core/d2term/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strconv"
"strings"

"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
Expand Down Expand Up @@ -130,7 +130,7 @@ func (t *terminal) advance(elapsed float64) error {
}

func (t *terminal) OnKeyDown(event d2input.KeyEvent) bool {
maxOutputIndex := d2helper.MaxInt(0, len(t.outputHistory)-t.lineCount)
maxOutputIndex := d2common.MaxInt(0, len(t.outputHistory)-t.lineCount)

if t.visState == termVisHiding || t.visState == termVisHidden {
if event.Key == d2input.KeyGraveAccent {
Expand Down Expand Up @@ -180,7 +180,7 @@ func (t *terminal) OnKeyDown(event d2input.KeyEvent) bool {

if event.Key == d2input.KeyUp {
if event.KeyMod == d2input.KeyModControl {
t.lineCount = d2helper.MaxInt(0, t.lineCount-1)
t.lineCount = d2common.MaxInt(0, t.lineCount-1)
} else if len(t.commandHistory) > 0 {
t.command = t.commandHistory[t.commandIndex]
if t.commandIndex == 0 {
Expand All @@ -194,7 +194,7 @@ func (t *terminal) OnKeyDown(event d2input.KeyEvent) bool {
}

if event.Key == d2input.KeyDown && event.KeyMod == d2input.KeyModControl {
t.lineCount = d2helper.MinInt(t.lineCount+1, termRowCountMax)
t.lineCount = d2common.MinInt(t.lineCount+1, termRowCountMax)
return true
}

Expand Down
Loading

0 comments on commit ea4450f

Please sign in to comment.