Skip to content

Commit 5e1725d

Browse files
authored
385/lintissues (OpenDiablo2#391)
* camera offset for ui panels : added maprenderer viewport to be aligned left or right calling alignement on keyPress in game_controls * check if already aligned * fix bugs -forgot to assign alignement -defaultScreenRect instead of screenRect because of issue mentionned in original comment * remove config.json and replace go.mod line * removing duplicate import of d2common replacing all dh to d2common * remove useless breaks from switch statement * better range when value unused + prettying import * item_affix rewrite using return values instead of pointer references in arguments * ebiten deprecated calls * small fixes
1 parent 711cae2 commit 5e1725d

File tree

36 files changed

+364
-405
lines changed

36 files changed

+364
-405
lines changed

d2common/d2data/d2compression/huffman.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func adjustTree(newNode *linkedNode) {
246246
var prev *linkedNode
247247
// Go backwards thru the list looking for the insertion point
248248
insertpoint = current
249-
for true {
249+
for {
250250
prev = insertpoint.Prev
251251
if prev == nil {
252252
break
@@ -347,23 +347,19 @@ func HuffmanDecompress(data []byte) []byte {
347347
outputstream := d2common.CreateStreamWriter()
348348
bitstream := d2common.CreateBitStream(data[1:])
349349
var decoded int
350-
for true {
350+
Loop:
351+
for {
351352
node := decode(bitstream, head)
352353
decoded = node.DecompressedValue
353354
switch decoded {
354355
case 256:
355-
break
356+
break Loop
356357
case 257:
357358
newvalue := bitstream.ReadBits(8)
358359
outputstream.PushByte(byte(newvalue))
359360
tail = insertNode(tail, newvalue)
360-
break
361361
default:
362362
outputstream.PushByte(byte(decoded))
363-
break
364-
}
365-
if decoded == 256 {
366-
break
367363
}
368364
}
369365

d2common/d2data/d2compression/wav.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ func WavDecompress(data []byte, channelCount int) []byte {
5757
Array1[channel]--
5858
}
5959
output.PushInt16(int16(Array2[channel]))
60-
break
6160
case 1:
6261
Array1[channel] += 8
6362
if Array1[channel] > 0x58 {
@@ -66,9 +65,7 @@ func WavDecompress(data []byte, channelCount int) []byte {
6665
if channelCount == 2 {
6766
channel = 1 - channel
6867
}
69-
break
7068
case 2:
71-
break
7269
default:
7370
Array1[channel] -= 8
7471
if Array1[channel] < 0 {
@@ -77,7 +74,6 @@ func WavDecompress(data []byte, channelCount int) []byte {
7774
if channelCount == 2 {
7875
channel = 1 - channel
7976
}
80-
break
8177
}
8278
} else {
8379
temp1 := sLookup[Array1[channel]]

d2common/d2data/d2datadict/charstats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func LoadCharStats(file []byte) {
9292
d := d2common.LoadDataDictionary(string(file))
9393
CharStats = make(map[d2enum.Hero]*CharStatsRecord, len(d.Data))
9494

95-
for idx, _ := range d.Data {
95+
for idx := range d.Data {
9696
record := &CharStatsRecord{
9797
Class: charStringMap[d.GetString("class", idx)],
9898

d2common/d2data/d2datadict/difficultylevels.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func LoadDifficultyLevels(file []byte) {
9595

9696
DifficultyLevels = make(map[string]*DifficultyLevelRecord, numRows)
9797

98-
for idx, _ := range dict.Data {
98+
for idx := range dict.Data {
9999
record := &DifficultyLevelRecord{
100100
Name: dict.GetString("Name", idx),
101101
ResistancePenalty: dict.GetNumber("ResistPenalty", idx),

d2common/d2data/d2datadict/experience.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func LoadExperienceBreakpoints(file []byte) {
7777
// we skip the second row because that describes max level of char classes
7878
ExperienceBreakpoints = make([]*ExperienceBreakpointsRecord, len(d.Data)-1)
7979

80-
for idx, _ := range d.Data {
80+
for idx := range d.Data {
8181
if idx == 0 {
8282
// max levels are a special case
8383
maxLevels = map[d2enum.Hero]int{

d2common/d2data/d2datadict/gems.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package d2datadict
22

33
import (
4-
"github.com/OpenDiablo2/OpenDiablo2/d2common"
54
"log"
5+
6+
"github.com/OpenDiablo2/OpenDiablo2/d2common"
67
)
78

89
type GemsRecord struct {
@@ -52,7 +53,7 @@ type GemsRecord struct {
5253
func LoadGems(file []byte) {
5354
d := d2common.LoadDataDictionary(string(file))
5455
var Gems []*GemsRecord
55-
for idx, _ := range d.Data {
56+
for idx := range d.Data {
5657
if d.GetString("name", idx) != "Expansion" {
5758
/*
5859
"Expansion" is the only field in line 36 of /data/global/excel/gems.txt and is only used to visually

d2common/d2data/d2datadict/hireling.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package d2datadict
22

33
import (
4-
"github.com/OpenDiablo2/OpenDiablo2/d2common"
54
"log"
5+
6+
"github.com/OpenDiablo2/OpenDiablo2/d2common"
67
)
78

89
type HirelingRecord struct {
@@ -83,7 +84,7 @@ type HirelingRecord struct {
8384
func LoadHireling(file []byte) {
8485
d := d2common.LoadDataDictionary(string(file))
8586
var Hirelings []*HirelingRecord
86-
for idx, _ := range d.Data {
87+
for idx := range d.Data {
8788
hireling := &HirelingRecord{
8889
Hireling: d.GetString("Hireling", idx),
8990
SubType: d.GetString("SubType", idx),

d2common/d2data/d2datadict/item_affix.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ var subType d2enum.ItemAffixSubType
2222
func LoadMagicPrefix(file []byte) {
2323
superType = d2enum.ItemAffixPrefix
2424
subType = d2enum.ItemAffixMagic
25-
loadDictionary(file, MagicPrefixDictionary, superType, subType)
25+
MagicPrefixDictionary, MagicPrefixRecords = loadDictionary(file, superType, subType)
2626
}
2727

2828
func LoadMagicSuffix(file []byte) {
2929
superType = d2enum.ItemAffixSuffix
3030
subType = d2enum.ItemAffixMagic
31-
loadDictionary(file, MagicSuffixDictionary, superType, subType)
31+
MagicSuffixDictionary, MagicSuffixRecords = loadDictionary(file, superType, subType)
3232
}
3333

3434
func getAffixString(t1 d2enum.ItemAffixSuperType, t2 d2enum.ItemAffixSubType) string {
@@ -52,16 +52,14 @@ func getAffixString(t1 d2enum.ItemAffixSuperType, t2 d2enum.ItemAffixSubType) st
5252

5353
func loadDictionary(
5454
file []byte,
55-
dict *d2common.DataDictionary,
5655
superType d2enum.ItemAffixSuperType,
5756
subType d2enum.ItemAffixSubType,
58-
) {
59-
dict = d2common.LoadDataDictionary(string(file))
60-
records := make([]*ItemAffixCommonRecord, 0)
61-
62-
createItemAffixRecords(dict, records, superType, subType)
57+
) (*d2common.DataDictionary, []*ItemAffixCommonRecord) {
58+
dict := d2common.LoadDataDictionary(string(file))
59+
records := createItemAffixRecords(dict, superType, subType)
6360
name := getAffixString(superType, subType)
6461
log.Printf("Loaded %d %s records", len(dict.Data), name)
62+
return dict, records
6563
}
6664

6765
// --- column names from d2exp.mpq:/data/globa/excel/MagicPrefix.txt
@@ -109,11 +107,11 @@ func loadDictionary(
109107

110108
func createItemAffixRecords(
111109
d *d2common.DataDictionary,
112-
r []*ItemAffixCommonRecord,
113110
superType d2enum.ItemAffixSuperType,
114111
subType d2enum.ItemAffixSubType,
115-
) {
116-
for index, _ := range d.Data {
112+
) []*ItemAffixCommonRecord {
113+
records := make([]*ItemAffixCommonRecord, 0)
114+
for index := range d.Data {
117115

118116
affix := &ItemAffixCommonRecord{
119117
Name: d.GetString("Name", index),
@@ -179,8 +177,9 @@ func createItemAffixRecords(
179177
group := ItemAffixGroups[affix.GroupID]
180178
group.AddMember(affix)
181179

182-
r = append(r, affix)
180+
records = append(records, affix)
183181
}
182+
return records
184183
}
185184

186185
var ItemAffixGroups map[int]*ItemAffixCommonGroup

d2common/d2data/d2datadict/itemstatcost.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package d2datadict
22

33
import (
4+
"log"
5+
46
"github.com/OpenDiablo2/OpenDiablo2/d2common"
57
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
6-
"log"
78
)
89

910
// refer to https://d2mods.info/forum/kb/viewarticle?a=448
@@ -245,7 +246,7 @@ func LoadItemStatCosts(file []byte) {
245246
numRecords := len(d.Data)
246247
ItemStatCosts = make(map[string]*ItemStatCostRecord, numRecords)
247248

248-
for idx, _ := range d.Data {
249+
for idx := range d.Data {
249250
record := &ItemStatCostRecord{
250251
Name: d.GetString("Stat", idx),
251252
Index: d.GetNumber("ID", idx),

d2common/d2data/d2datadict/level_maze.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func LoadLevelMazeDetails(file []byte) {
4040
dict := d2common.LoadDataDictionary(string(file))
4141
numRecords := len(dict.Data)
4242
LevelMazeDetails = make(map[int]*LevelMazeDetailsRecord, numRecords)
43-
for idx, _ := range dict.Data {
43+
for idx := range dict.Data {
4444
record := &LevelMazeDetailsRecord{
4545
Name: dict.GetString("Name", idx),
4646
LevelId: dict.GetNumber("Level", idx),

0 commit comments

Comments
 (0)