diff --git a/d2common/d2data/d2compression/huffman.go b/d2common/d2data/d2compression/huffman.go index 1bbad1a2..ebd12a8c 100644 --- a/d2common/d2data/d2compression/huffman.go +++ b/d2common/d2data/d2compression/huffman.go @@ -246,7 +246,7 @@ func adjustTree(newNode *linkedNode) { var prev *linkedNode // Go backwards thru the list looking for the insertion point insertpoint = current - for true { + for { prev = insertpoint.Prev if prev == nil { break @@ -347,23 +347,19 @@ func HuffmanDecompress(data []byte) []byte { outputstream := d2common.CreateStreamWriter() bitstream := d2common.CreateBitStream(data[1:]) var decoded int - for true { +Loop: + for { node := decode(bitstream, head) decoded = node.DecompressedValue switch decoded { case 256: - break + break Loop case 257: newvalue := bitstream.ReadBits(8) outputstream.PushByte(byte(newvalue)) tail = insertNode(tail, newvalue) - break default: outputstream.PushByte(byte(decoded)) - break - } - if decoded == 256 { - break } } diff --git a/d2common/d2data/d2compression/wav.go b/d2common/d2data/d2compression/wav.go index 2b5474f4..8d21f8d8 100644 --- a/d2common/d2data/d2compression/wav.go +++ b/d2common/d2data/d2compression/wav.go @@ -57,7 +57,6 @@ func WavDecompress(data []byte, channelCount int) []byte { Array1[channel]-- } output.PushInt16(int16(Array2[channel])) - break case 1: Array1[channel] += 8 if Array1[channel] > 0x58 { @@ -66,9 +65,7 @@ func WavDecompress(data []byte, channelCount int) []byte { if channelCount == 2 { channel = 1 - channel } - break case 2: - break default: Array1[channel] -= 8 if Array1[channel] < 0 { @@ -77,7 +74,6 @@ func WavDecompress(data []byte, channelCount int) []byte { if channelCount == 2 { channel = 1 - channel } - break } } else { temp1 := sLookup[Array1[channel]] diff --git a/d2common/d2data/d2datadict/charstats.go b/d2common/d2data/d2datadict/charstats.go index 19a7b9dc..ab256648 100644 --- a/d2common/d2data/d2datadict/charstats.go +++ b/d2common/d2data/d2datadict/charstats.go @@ -92,7 +92,7 @@ func LoadCharStats(file []byte) { d := d2common.LoadDataDictionary(string(file)) CharStats = make(map[d2enum.Hero]*CharStatsRecord, len(d.Data)) - for idx, _ := range d.Data { + for idx := range d.Data { record := &CharStatsRecord{ Class: charStringMap[d.GetString("class", idx)], diff --git a/d2common/d2data/d2datadict/difficultylevels.go b/d2common/d2data/d2datadict/difficultylevels.go index c6c2ee74..3b3cec1d 100644 --- a/d2common/d2data/d2datadict/difficultylevels.go +++ b/d2common/d2data/d2datadict/difficultylevels.go @@ -95,7 +95,7 @@ func LoadDifficultyLevels(file []byte) { DifficultyLevels = make(map[string]*DifficultyLevelRecord, numRows) - for idx, _ := range dict.Data { + for idx := range dict.Data { record := &DifficultyLevelRecord{ Name: dict.GetString("Name", idx), ResistancePenalty: dict.GetNumber("ResistPenalty", idx), diff --git a/d2common/d2data/d2datadict/experience.go b/d2common/d2data/d2datadict/experience.go index 85d13946..e34e5ff7 100644 --- a/d2common/d2data/d2datadict/experience.go +++ b/d2common/d2data/d2datadict/experience.go @@ -77,7 +77,7 @@ func LoadExperienceBreakpoints(file []byte) { // we skip the second row because that describes max level of char classes ExperienceBreakpoints = make([]*ExperienceBreakpointsRecord, len(d.Data)-1) - for idx, _ := range d.Data { + for idx := range d.Data { if idx == 0 { // max levels are a special case maxLevels = map[d2enum.Hero]int{ diff --git a/d2common/d2data/d2datadict/gems.go b/d2common/d2data/d2datadict/gems.go index 532c7a4a..b887b14d 100644 --- a/d2common/d2data/d2datadict/gems.go +++ b/d2common/d2data/d2datadict/gems.go @@ -1,8 +1,9 @@ package d2datadict import ( - "github.com/OpenDiablo2/OpenDiablo2/d2common" "log" + + "github.com/OpenDiablo2/OpenDiablo2/d2common" ) type GemsRecord struct { @@ -52,7 +53,7 @@ type GemsRecord struct { func LoadGems(file []byte) { d := d2common.LoadDataDictionary(string(file)) var Gems []*GemsRecord - for idx, _ := range d.Data { + for idx := range d.Data { if d.GetString("name", idx) != "Expansion" { /* "Expansion" is the only field in line 36 of /data/global/excel/gems.txt and is only used to visually diff --git a/d2common/d2data/d2datadict/hireling.go b/d2common/d2data/d2datadict/hireling.go index 2f3d8955..34a6ee89 100644 --- a/d2common/d2data/d2datadict/hireling.go +++ b/d2common/d2data/d2datadict/hireling.go @@ -1,8 +1,9 @@ package d2datadict import ( - "github.com/OpenDiablo2/OpenDiablo2/d2common" "log" + + "github.com/OpenDiablo2/OpenDiablo2/d2common" ) type HirelingRecord struct { @@ -83,7 +84,7 @@ type HirelingRecord struct { func LoadHireling(file []byte) { d := d2common.LoadDataDictionary(string(file)) var Hirelings []*HirelingRecord - for idx, _ := range d.Data { + for idx := range d.Data { hireling := &HirelingRecord{ Hireling: d.GetString("Hireling", idx), SubType: d.GetString("SubType", idx), diff --git a/d2common/d2data/d2datadict/item_affix.go b/d2common/d2data/d2datadict/item_affix.go index e4d9c248..567396fb 100644 --- a/d2common/d2data/d2datadict/item_affix.go +++ b/d2common/d2data/d2datadict/item_affix.go @@ -22,13 +22,13 @@ var subType d2enum.ItemAffixSubType func LoadMagicPrefix(file []byte) { superType = d2enum.ItemAffixPrefix subType = d2enum.ItemAffixMagic - loadDictionary(file, MagicPrefixDictionary, superType, subType) + MagicPrefixDictionary, MagicPrefixRecords = loadDictionary(file, superType, subType) } func LoadMagicSuffix(file []byte) { superType = d2enum.ItemAffixSuffix subType = d2enum.ItemAffixMagic - loadDictionary(file, MagicSuffixDictionary, superType, subType) + MagicSuffixDictionary, MagicSuffixRecords = loadDictionary(file, superType, subType) } func getAffixString(t1 d2enum.ItemAffixSuperType, t2 d2enum.ItemAffixSubType) string { @@ -52,16 +52,14 @@ func getAffixString(t1 d2enum.ItemAffixSuperType, t2 d2enum.ItemAffixSubType) st func loadDictionary( file []byte, - dict *d2common.DataDictionary, superType d2enum.ItemAffixSuperType, subType d2enum.ItemAffixSubType, -) { - dict = d2common.LoadDataDictionary(string(file)) - records := make([]*ItemAffixCommonRecord, 0) - - createItemAffixRecords(dict, records, superType, subType) +) (*d2common.DataDictionary, []*ItemAffixCommonRecord) { + dict := d2common.LoadDataDictionary(string(file)) + records := createItemAffixRecords(dict, superType, subType) name := getAffixString(superType, subType) log.Printf("Loaded %d %s records", len(dict.Data), name) + return dict, records } // --- column names from d2exp.mpq:/data/globa/excel/MagicPrefix.txt @@ -109,11 +107,11 @@ func loadDictionary( func createItemAffixRecords( d *d2common.DataDictionary, - r []*ItemAffixCommonRecord, superType d2enum.ItemAffixSuperType, subType d2enum.ItemAffixSubType, -) { - for index, _ := range d.Data { +) []*ItemAffixCommonRecord { + records := make([]*ItemAffixCommonRecord, 0) + for index := range d.Data { affix := &ItemAffixCommonRecord{ Name: d.GetString("Name", index), @@ -179,8 +177,9 @@ func createItemAffixRecords( group := ItemAffixGroups[affix.GroupID] group.AddMember(affix) - r = append(r, affix) + records = append(records, affix) } + return records } var ItemAffixGroups map[int]*ItemAffixCommonGroup diff --git a/d2common/d2data/d2datadict/itemstatcost.go b/d2common/d2data/d2datadict/itemstatcost.go index ac21a373..2315ec7a 100644 --- a/d2common/d2data/d2datadict/itemstatcost.go +++ b/d2common/d2data/d2datadict/itemstatcost.go @@ -1,9 +1,10 @@ package d2datadict import ( + "log" + "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" - "log" ) // refer to https://d2mods.info/forum/kb/viewarticle?a=448 @@ -245,7 +246,7 @@ func LoadItemStatCosts(file []byte) { numRecords := len(d.Data) ItemStatCosts = make(map[string]*ItemStatCostRecord, numRecords) - for idx, _ := range d.Data { + for idx := range d.Data { record := &ItemStatCostRecord{ Name: d.GetString("Stat", idx), Index: d.GetNumber("ID", idx), diff --git a/d2common/d2data/d2datadict/level_maze.go b/d2common/d2data/d2datadict/level_maze.go index 53103a79..189af255 100644 --- a/d2common/d2data/d2datadict/level_maze.go +++ b/d2common/d2data/d2datadict/level_maze.go @@ -40,7 +40,7 @@ func LoadLevelMazeDetails(file []byte) { dict := d2common.LoadDataDictionary(string(file)) numRecords := len(dict.Data) LevelMazeDetails = make(map[int]*LevelMazeDetailsRecord, numRecords) - for idx, _ := range dict.Data { + for idx := range dict.Data { record := &LevelMazeDetailsRecord{ Name: dict.GetString("Name", idx), LevelId: dict.GetNumber("Level", idx), diff --git a/d2common/d2data/d2datadict/level_presets.go b/d2common/d2data/d2datadict/level_presets.go index 9077df64..1c186fac 100644 --- a/d2common/d2data/d2datadict/level_presets.go +++ b/d2common/d2data/d2datadict/level_presets.go @@ -4,7 +4,7 @@ import ( "log" "strings" - dh "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common" ) type LevelPresetRecord struct { @@ -39,21 +39,21 @@ func createLevelPresetRecord(props []string) LevelPresetRecord { } result := LevelPresetRecord{ Name: props[inc()], - DefinitionId: dh.StringToInt(props[inc()]), - LevelId: dh.StringToInt(props[inc()]), - Populate: dh.StringToUint8(props[inc()]) == 1, - Logicals: dh.StringToUint8(props[inc()]) == 1, - Outdoors: dh.StringToUint8(props[inc()]) == 1, - Animate: dh.StringToUint8(props[inc()]) == 1, - KillEdge: dh.StringToUint8(props[inc()]) == 1, - FillBlanks: dh.StringToUint8(props[inc()]) == 1, - SizeX: dh.StringToInt(props[inc()]), - SizeY: dh.StringToInt(props[inc()]), - AutoMap: dh.StringToUint8(props[inc()]) == 1, - Scan: dh.StringToUint8(props[inc()]) == 1, - Pops: dh.StringToInt(props[inc()]), - PopPad: dh.StringToInt(props[inc()]), - FileCount: dh.StringToInt(props[inc()]), + DefinitionId: d2common.StringToInt(props[inc()]), + LevelId: d2common.StringToInt(props[inc()]), + Populate: d2common.StringToUint8(props[inc()]) == 1, + Logicals: d2common.StringToUint8(props[inc()]) == 1, + Outdoors: d2common.StringToUint8(props[inc()]) == 1, + Animate: d2common.StringToUint8(props[inc()]) == 1, + KillEdge: d2common.StringToUint8(props[inc()]) == 1, + FillBlanks: d2common.StringToUint8(props[inc()]) == 1, + SizeX: d2common.StringToInt(props[inc()]), + SizeY: d2common.StringToInt(props[inc()]), + AutoMap: d2common.StringToUint8(props[inc()]) == 1, + Scan: d2common.StringToUint8(props[inc()]) == 1, + Pops: d2common.StringToInt(props[inc()]), + PopPad: d2common.StringToInt(props[inc()]), + FileCount: d2common.StringToInt(props[inc()]), Files: [6]string{ props[inc()], props[inc()], @@ -62,9 +62,9 @@ func createLevelPresetRecord(props []string) LevelPresetRecord { props[inc()], props[inc()], }, - Dt1Mask: dh.StringToUint(props[inc()]), - Beta: dh.StringToUint8(props[inc()]) == 1, - Expansion: dh.StringToUint8(props[inc()]) == 1, + Dt1Mask: d2common.StringToUint(props[inc()]), + Beta: d2common.StringToUint8(props[inc()]) == 1, + Expansion: d2common.StringToUint8(props[inc()]) == 1, } return result } diff --git a/d2common/d2data/d2datadict/level_sub.go b/d2common/d2data/d2datadict/level_sub.go index ffbaae2e..e8e524b4 100644 --- a/d2common/d2data/d2datadict/level_sub.go +++ b/d2common/d2data/d2datadict/level_sub.go @@ -68,7 +68,7 @@ func LoadLevelSubstitutions(file []byte) { numRecords := len(dict.Data) LevelSubstitutions = make(map[int]*LevelSubstitutionRecord, numRecords) - for idx, _ := range dict.Data { + for idx := range dict.Data { record := &LevelSubstitutionRecord{ Name: dict.GetString("Name", idx), diff --git a/d2common/d2data/d2datadict/level_types.go b/d2common/d2data/d2datadict/level_types.go index 2ed92de8..b7a576b8 100644 --- a/d2common/d2data/d2datadict/level_types.go +++ b/d2common/d2data/d2datadict/level_types.go @@ -4,7 +4,7 @@ import ( "log" "strings" - dh "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common" ) type LevelTypeRecord struct { @@ -36,7 +36,7 @@ func LoadLevelTypes(file []byte) { continue } LevelTypes[j].Name = parts[inc()] - LevelTypes[j].Id = dh.StringToInt(parts[inc()]) + LevelTypes[j].Id = d2common.StringToInt(parts[inc()]) for fileIdx := range LevelTypes[i].Files { LevelTypes[j].Files[fileIdx] = parts[inc()] if LevelTypes[j].Files[fileIdx] == "0" { @@ -45,7 +45,7 @@ func LoadLevelTypes(file []byte) { } LevelTypes[j].Beta = parts[inc()] != "1" - LevelTypes[j].Act = dh.StringToInt(parts[inc()]) + LevelTypes[j].Act = d2common.StringToInt(parts[inc()]) LevelTypes[j].Expansion = parts[inc()] != "1" } log.Printf("Loaded %d LevelType records", len(LevelTypes)) diff --git a/d2common/d2data/d2datadict/levels.go b/d2common/d2data/d2datadict/levels.go index 5a255d63..bb11679d 100644 --- a/d2common/d2data/d2datadict/levels.go +++ b/d2common/d2data/d2datadict/levels.go @@ -382,7 +382,7 @@ func LoadLevelDetails(file []byte) { numRecords := len(dict.Data) LevelDetails = make(map[int]*LevelDetailsRecord, numRecords) - for idx, _ := range dict.Data { + for idx := range dict.Data { record := &LevelDetailsRecord{ Name: dict.GetString("Name ", idx), Id: dict.GetNumber("Id", idx), diff --git a/d2common/d2data/d2datadict/map_helper.go b/d2common/d2data/d2datadict/map_helper.go index 54711c2a..86040e99 100644 --- a/d2common/d2data/d2datadict/map_helper.go +++ b/d2common/d2data/d2datadict/map_helper.go @@ -3,7 +3,7 @@ package d2datadict import ( "strings" - dh "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common" ) func MapHeaders(line string) map[string]int { @@ -18,7 +18,7 @@ func MapHeaders(line string) map[string]int { func MapLoadInt(r *[]string, mapping *map[string]int, field string) int { index, ok := (*mapping)[field] if ok { - return dh.StringToInt(dh.EmptyToZero(dh.AsterToEmpty((*r)[index]))) + return d2common.StringToInt(d2common.EmptyToZero(d2common.AsterToEmpty((*r)[index]))) } return 0 } @@ -26,7 +26,7 @@ func MapLoadInt(r *[]string, mapping *map[string]int, field string) int { func MapLoadString(r *[]string, mapping *map[string]int, field string) string { index, ok := (*mapping)[field] if ok { - return dh.AsterToEmpty((*r)[index]) + return d2common.AsterToEmpty((*r)[index]) } return "" } @@ -38,7 +38,7 @@ func MapLoadBool(r *[]string, mapping *map[string]int, field string) bool { func MapLoadUint8(r *[]string, mapping *map[string]int, field string) uint8 { index, ok := (*mapping)[field] if ok { - return dh.StringToUint8(dh.EmptyToZero(dh.AsterToEmpty((*r)[index]))) + return d2common.StringToUint8(d2common.EmptyToZero(d2common.AsterToEmpty((*r)[index]))) } return 0 } diff --git a/d2common/d2data/d2datadict/missiles.go b/d2common/d2data/d2datadict/missiles.go index 4037c3e7..9e48651b 100644 --- a/d2common/d2data/d2datadict/missiles.go +++ b/d2common/d2data/d2datadict/missiles.go @@ -5,7 +5,6 @@ import ( "strings" "github.com/OpenDiablo2/OpenDiablo2/d2common" - dh "github.com/OpenDiablo2/OpenDiablo2/d2common" ) type MissileCalcParam struct { @@ -197,16 +196,16 @@ func createMissileRecord(line string) MissileRecord { return i } // note: in this file, empties are equivalent to zero, so all numerical conversions should - // be wrapped in an dh.EmptyToZero transform + // be wrapped in an d2common.EmptyToZero transform result := MissileRecord{ Name: r[inc()], - Id: dh.StringToInt(dh.EmptyToZero(r[inc()])), + Id: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), - ClientMovementFunc: dh.StringToInt(dh.EmptyToZero(dh.AsterToEmpty(r[inc()]))), - ClientCollisionFunc: dh.StringToInt(dh.EmptyToZero(dh.AsterToEmpty(r[inc()]))), - ServerMovementFunc: dh.StringToInt(dh.EmptyToZero(dh.AsterToEmpty(r[inc()]))), - ServerCollisionFunc: dh.StringToInt(dh.EmptyToZero(dh.AsterToEmpty(r[inc()]))), - ServerDamageFunc: dh.StringToInt(dh.EmptyToZero(dh.AsterToEmpty(r[inc()]))), + ClientMovementFunc: d2common.StringToInt(d2common.EmptyToZero(d2common.AsterToEmpty(r[inc()]))), + ClientCollisionFunc: d2common.StringToInt(d2common.EmptyToZero(d2common.AsterToEmpty(r[inc()]))), + ServerMovementFunc: d2common.StringToInt(d2common.EmptyToZero(d2common.AsterToEmpty(r[inc()]))), + ServerCollisionFunc: d2common.StringToInt(d2common.EmptyToZero(d2common.AsterToEmpty(r[inc()]))), + ServerDamageFunc: d2common.StringToInt(d2common.EmptyToZero(d2common.AsterToEmpty(r[inc()]))), ServerMovementCalc: loadMissileCalc(&r, inc, 5), ClientMovementCalc: loadMissileCalc(&r, inc, 5), @@ -214,12 +213,12 @@ func createMissileRecord(line string) MissileRecord { ClientCollisionCalc: loadMissileCalc(&r, inc, 3), ServerDamageCalc: loadMissileCalc(&r, inc, 2), - Velocity: dh.StringToInt(dh.EmptyToZero(r[inc()])), - MaxVelocity: dh.StringToInt(dh.EmptyToZero(r[inc()])), - LevelVelocityBonus: dh.StringToInt(dh.EmptyToZero(r[inc()])), - Accel: dh.StringToInt(dh.EmptyToZero(r[inc()])), - Range: dh.StringToInt(dh.EmptyToZero(r[inc()])), - LevelRangeBonus: dh.StringToInt(dh.EmptyToZero(r[inc()])), + Velocity: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + MaxVelocity: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + LevelVelocityBonus: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + Accel: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + Range: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + LevelRangeBonus: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), Light: loadMissileLight(&r, inc), @@ -227,54 +226,54 @@ func createMissileRecord(line string) MissileRecord { Collision: loadMissileCollision(&r, inc), - XOffset: dh.StringToInt(dh.EmptyToZero(r[inc()])), - YOffset: dh.StringToInt(dh.EmptyToZero(r[inc()])), - ZOffset: dh.StringToInt(dh.EmptyToZero(r[inc()])), - Size: dh.StringToInt(dh.EmptyToZero(r[inc()])), + XOffset: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + YOffset: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + ZOffset: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + Size: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), - DestroyedByTP: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - DestroyedByTPFrame: dh.StringToInt(dh.EmptyToZero(r[inc()])), - CanDestroy: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, + DestroyedByTP: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + DestroyedByTPFrame: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + CanDestroy: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, - UseAttackRating: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - AlwaysExplode: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, + UseAttackRating: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + AlwaysExplode: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, - ClientExplosion: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - TownSafe: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - IgnoreBossModifiers: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - IgnoreMultishot: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - HolyFilterType: dh.StringToInt(dh.EmptyToZero(r[inc()])), - CanBeSlowed: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - TriggersHitEvents: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - TriggersGetHit: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - SoftHit: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - KnockbackPercent: dh.StringToInt(dh.EmptyToZero(r[inc()])), + ClientExplosion: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + TownSafe: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + IgnoreBossModifiers: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + IgnoreMultishot: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + HolyFilterType: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + CanBeSlowed: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + TriggersHitEvents: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + TriggersGetHit: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + SoftHit: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + KnockbackPercent: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), - TransparencyMode: dh.StringToInt(dh.EmptyToZero(r[inc()])), + TransparencyMode: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), - UseQuantity: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - AffectedByPierce: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - SpecialSetup: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, + UseQuantity: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + AffectedByPierce: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + SpecialSetup: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, - MissileSkill: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, + MissileSkill: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, SkillName: r[inc()], - ResultFlags: dh.StringToInt(dh.EmptyToZero(r[inc()])), - HitFlags: dh.StringToInt(dh.EmptyToZero(r[inc()])), + ResultFlags: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + HitFlags: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), - HitShift: dh.StringToInt(dh.EmptyToZero(r[inc()])), - ApplyMastery: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - SourceDamage: dh.StringToInt(dh.EmptyToZero(r[inc()])), - HalfDamageForTwoHander: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - SourceMissDamage: dh.StringToInt(dh.EmptyToZero(r[inc()])), + HitShift: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + ApplyMastery: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + SourceDamage: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + HalfDamageForTwoHander: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + SourceMissDamage: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), Damage: loadMissileDamage(&r, inc), ElementalDamage: loadMissileElementalDamage(&r, inc), - HitClass: dh.StringToInt(dh.EmptyToZero(r[inc()])), - NumDirections: dh.StringToInt(dh.EmptyToZero(r[inc()])), - LocalBlood: dh.StringToInt(dh.EmptyToZero(r[inc()])), - DamageReductionRate: dh.StringToInt(dh.EmptyToZero(r[inc()])), + HitClass: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + NumDirections: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + LocalBlood: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + DamageReductionRate: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), TravelSound: r[inc()], HitSound: r[inc()], @@ -307,7 +306,7 @@ func LoadMissiles(file []byte) { func loadMissileCalcParam(r *[]string, inc func() int) MissileCalcParam { result := MissileCalcParam{ - Param: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), + Param: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), Desc: (*r)[inc()], } return result @@ -327,64 +326,64 @@ func loadMissileCalc(r *[]string, inc func() int, params int) MissileCalc { func loadMissileLight(r *[]string, inc func() int) MissileLight { result := MissileLight{ - Diameter: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - Flicker: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - Red: dh.StringToUint8(dh.EmptyToZero((*r)[inc()])), - Green: dh.StringToUint8(dh.EmptyToZero((*r)[inc()])), - Blue: dh.StringToUint8(dh.EmptyToZero((*r)[inc()])), + Diameter: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + Flicker: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + Red: d2common.StringToUint8(d2common.EmptyToZero((*r)[inc()])), + Green: d2common.StringToUint8(d2common.EmptyToZero((*r)[inc()])), + Blue: d2common.StringToUint8(d2common.EmptyToZero((*r)[inc()])), } return result } func loadMissileAnimation(r *[]string, inc func() int) MissileAnimation { result := MissileAnimation{ - StepsBeforeVisible: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - StepsBeforeActive: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - LoopAnimation: dh.StringToInt(dh.EmptyToZero((*r)[inc()])) == 1, + StepsBeforeVisible: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + StepsBeforeActive: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + LoopAnimation: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])) == 1, CelFileName: (*r)[inc()], - AnimationRate: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - AnimationLength: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - AnimationSpeed: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - StartingFrame: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - HasSubLoop: dh.StringToInt(dh.EmptyToZero((*r)[inc()])) == 1, - SubStartingFrame: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - SubEndingFrame: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), + AnimationRate: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + AnimationLength: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + AnimationSpeed: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + StartingFrame: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + HasSubLoop: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])) == 1, + SubStartingFrame: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + SubEndingFrame: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), } return result } func loadMissileCollision(r *[]string, inc func() int) MissileCollision { result := MissileCollision{ - CollisionType: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - DestroyedUponCollision: dh.StringToInt(dh.EmptyToZero((*r)[inc()])) == 1, - FriendlyFire: dh.StringToInt(dh.EmptyToZero((*r)[inc()])) == 1, - LastCollide: dh.StringToInt(dh.EmptyToZero((*r)[inc()])) == 1, - Collision: dh.StringToInt(dh.EmptyToZero((*r)[inc()])) == 1, - ClientCollision: dh.StringToInt(dh.EmptyToZero((*r)[inc()])) == 1, - ClientSend: dh.StringToInt(dh.EmptyToZero((*r)[inc()])) == 1, - UseCollisionTimer: dh.StringToInt(dh.EmptyToZero((*r)[inc()])) == 1, - TimerFrames: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), + CollisionType: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + DestroyedUponCollision: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])) == 1, + FriendlyFire: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])) == 1, + LastCollide: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])) == 1, + Collision: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])) == 1, + ClientCollision: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])) == 1, + ClientSend: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])) == 1, + UseCollisionTimer: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])) == 1, + TimerFrames: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), } return result } func loadMissileDamage(r *[]string, inc func() int) MissileDamage { result := MissileDamage{ - MinDamage: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), + MinDamage: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), MinLevelDamage: [5]int{ - dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - dh.StringToInt(dh.EmptyToZero((*r)[inc()])), + d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), }, - MaxDamage: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), + MaxDamage: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), MaxLevelDamage: [5]int{ - dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - dh.StringToInt(dh.EmptyToZero((*r)[inc()])), + d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), }, DamageSynergyPerCalc: d2common.CalcString((*r)[inc()]), } @@ -395,11 +394,11 @@ func loadMissileElementalDamage(r *[]string, inc func() int) MissileElementalDam result := MissileElementalDamage{ ElementType: (*r)[inc()], Damage: loadMissileDamage(r, inc), - Duration: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), + Duration: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), LevelDuration: [3]int{ - dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - dh.StringToInt(dh.EmptyToZero((*r)[inc()])), + d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), }, } return result diff --git a/d2common/d2data/d2datadict/monstats.go b/d2common/d2data/d2datadict/monstats.go index fffca4b0..6de5604e 100644 --- a/d2common/d2data/d2datadict/monstats.go +++ b/d2common/d2data/d2datadict/monstats.go @@ -1,8 +1,9 @@ package d2datadict import ( - "github.com/OpenDiablo2/OpenDiablo2/d2common" "log" + + "github.com/OpenDiablo2/OpenDiablo2/d2common" ) // https://d2mods.info/forum/kb/viewarticle?a=360 @@ -796,7 +797,7 @@ func LoadMonStats(file []byte) { dict := d2common.LoadDataDictionary(string(file)) numRecords := len(dict.Data) MonStats = make(map[string]*MonStatsRecord, numRecords) - for idx, _ := range dict.Data { + for idx := range dict.Data { record := &MonStatsRecord{ Key: dict.GetString("Id", idx), Id: dict.GetString("hcIdx", idx), diff --git a/d2common/d2data/d2datadict/objects.go b/d2common/d2data/d2datadict/objects.go index 3e30e9ba..122ecc0a 100644 --- a/d2common/d2data/d2datadict/objects.go +++ b/d2common/d2data/d2datadict/objects.go @@ -4,7 +4,7 @@ import ( "log" "strings" - dh "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common" ) // An ObjectRecord represents the settings for one type of object from objects.txt @@ -129,206 +129,206 @@ func createObjectRecord(props []string) ObjectRecord { result := ObjectRecord{ Name: props[inc()], Description: props[inc()], - Id: dh.StringToInt(props[inc()]), + Id: d2common.StringToInt(props[inc()]), Token: props[inc()], - SpawnMax: dh.StringToInt(props[inc()]), + SpawnMax: d2common.StringToInt(props[inc()]), Selectable: [8]bool{ - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, }, - TrapProbability: dh.StringToInt(props[inc()]), + TrapProbability: d2common.StringToInt(props[inc()]), - SizeX: dh.StringToInt(props[inc()]), - SizeY: dh.StringToInt(props[inc()]), + SizeX: d2common.StringToInt(props[inc()]), + SizeY: d2common.StringToInt(props[inc()]), - NTgtFX: dh.StringToInt(props[inc()]), - NTgtFY: dh.StringToInt(props[inc()]), - NTgtBX: dh.StringToInt(props[inc()]), - NTgtBY: dh.StringToInt(props[inc()]), + NTgtFX: d2common.StringToInt(props[inc()]), + NTgtFY: d2common.StringToInt(props[inc()]), + NTgtBX: d2common.StringToInt(props[inc()]), + NTgtBY: d2common.StringToInt(props[inc()]), FrameCount: [8]int{ - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), }, FrameDelta: [8]int{ - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), }, CycleAnimation: [8]bool{ - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, }, LightDiameter: [8]int{ - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), }, BlocksLight: [8]bool{ - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, }, HasCollision: [8]bool{ - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, }, - IsAttackable: dh.StringToUint8(props[inc()]) == 1, + IsAttackable: d2common.StringToUint8(props[inc()]) == 1, StartFrame: [8]int{ - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), }, - EnvEffect: dh.StringToUint8(props[inc()]) == 1, - IsDoor: dh.StringToUint8(props[inc()]) == 1, - BlockVisibility: dh.StringToUint8(props[inc()]) == 1, - Orientation: dh.StringToInt(props[inc()]), - Trans: dh.StringToInt(props[inc()]), + EnvEffect: d2common.StringToUint8(props[inc()]) == 1, + IsDoor: d2common.StringToUint8(props[inc()]) == 1, + BlockVisibility: d2common.StringToUint8(props[inc()]) == 1, + Orientation: d2common.StringToInt(props[inc()]), + Trans: d2common.StringToInt(props[inc()]), OrderFlag: [8]int{ - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), }, - PreOperate: dh.StringToUint8(props[inc()]) == 1, + PreOperate: d2common.StringToUint8(props[inc()]) == 1, HasAnimationMode: [8]bool{ - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, }, - XOffset: dh.StringToInt(props[inc()]), - YOffset: dh.StringToInt(props[inc()]), - Draw: dh.StringToUint8(props[inc()]) == 1, + XOffset: d2common.StringToInt(props[inc()]), + YOffset: d2common.StringToInt(props[inc()]), + Draw: d2common.StringToUint8(props[inc()]) == 1, - LightRed: dh.StringToUint8(props[inc()]), - LightGreen: dh.StringToUint8(props[inc()]), - LightBlue: dh.StringToUint8(props[inc()]), + LightRed: d2common.StringToUint8(props[inc()]), + LightGreen: d2common.StringToUint8(props[inc()]), + LightBlue: d2common.StringToUint8(props[inc()]), - SelHD: dh.StringToUint8(props[inc()]) == 1, - SelTR: dh.StringToUint8(props[inc()]) == 1, - SelLG: dh.StringToUint8(props[inc()]) == 1, - SelRA: dh.StringToUint8(props[inc()]) == 1, - SelLA: dh.StringToUint8(props[inc()]) == 1, - SelRH: dh.StringToUint8(props[inc()]) == 1, - SelLH: dh.StringToUint8(props[inc()]) == 1, - SelSH: dh.StringToUint8(props[inc()]) == 1, + SelHD: d2common.StringToUint8(props[inc()]) == 1, + SelTR: d2common.StringToUint8(props[inc()]) == 1, + SelLG: d2common.StringToUint8(props[inc()]) == 1, + SelRA: d2common.StringToUint8(props[inc()]) == 1, + SelLA: d2common.StringToUint8(props[inc()]) == 1, + SelRH: d2common.StringToUint8(props[inc()]) == 1, + SelLH: d2common.StringToUint8(props[inc()]) == 1, + SelSH: d2common.StringToUint8(props[inc()]) == 1, SelS: [8]bool{ - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, - dh.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, + d2common.StringToUint8(props[inc()]) == 1, }, - TotalPieces: dh.StringToInt(props[inc()]), - SubClass: dh.StringToInt(props[inc()]), + TotalPieces: d2common.StringToInt(props[inc()]), + SubClass: d2common.StringToInt(props[inc()]), - XSpace: dh.StringToInt(props[inc()]), - YSpace: dh.StringToInt(props[inc()]), + XSpace: d2common.StringToInt(props[inc()]), + YSpace: d2common.StringToInt(props[inc()]), - NameOffset: dh.StringToInt(props[inc()]), + NameOffset: d2common.StringToInt(props[inc()]), - MonsterOk: dh.StringToUint8(props[inc()]) == 1, - OperateRange: dh.StringToInt(props[inc()]), - ShrineFunction: dh.StringToInt(props[inc()]), - Restore: dh.StringToUint8(props[inc()]) == 1, + MonsterOk: d2common.StringToUint8(props[inc()]) == 1, + OperateRange: d2common.StringToInt(props[inc()]), + ShrineFunction: d2common.StringToInt(props[inc()]), + Restore: d2common.StringToUint8(props[inc()]) == 1, Parm: [8]int{ - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), - dh.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), + d2common.StringToInt(props[inc()]), }, - Act: dh.StringToInt(props[inc()]), - Lockable: dh.StringToUint8(props[inc()]) == 1, - Gore: dh.StringToUint8(props[inc()]) == 1, - Sync: dh.StringToUint8(props[inc()]) == 1, - Flicker: dh.StringToUint8(props[inc()]) == 1, - Damage: dh.StringToInt(props[inc()]), - Beta: dh.StringToUint8(props[inc()]) == 1, - Overlay: dh.StringToUint8(props[inc()]) == 1, - CollisionSubst: dh.StringToUint8(props[inc()]) == 1, + Act: d2common.StringToInt(props[inc()]), + Lockable: d2common.StringToUint8(props[inc()]) == 1, + Gore: d2common.StringToUint8(props[inc()]) == 1, + Sync: d2common.StringToUint8(props[inc()]) == 1, + Flicker: d2common.StringToUint8(props[inc()]) == 1, + Damage: d2common.StringToInt(props[inc()]), + Beta: d2common.StringToUint8(props[inc()]) == 1, + Overlay: d2common.StringToUint8(props[inc()]) == 1, + CollisionSubst: d2common.StringToUint8(props[inc()]) == 1, - Left: dh.StringToInt(props[inc()]), - Top: dh.StringToInt(props[inc()]), - Width: dh.StringToInt(props[inc()]), - Height: dh.StringToInt(props[inc()]), + Left: d2common.StringToInt(props[inc()]), + Top: d2common.StringToInt(props[inc()]), + Width: d2common.StringToInt(props[inc()]), + Height: d2common.StringToInt(props[inc()]), - OperateFn: dh.StringToInt(props[inc()]), - PopulateFn: dh.StringToInt(props[inc()]), - InitFn: dh.StringToInt(props[inc()]), - ClientFn: dh.StringToInt(props[inc()]), + OperateFn: d2common.StringToInt(props[inc()]), + PopulateFn: d2common.StringToInt(props[inc()]), + InitFn: d2common.StringToInt(props[inc()]), + ClientFn: d2common.StringToInt(props[inc()]), - RestoreVirgins: dh.StringToUint8(props[inc()]) == 1, - BlockMissile: dh.StringToUint8(props[inc()]) == 1, - DrawUnder: dh.StringToUint8(props[inc()]) == 1, - OpenWarp: dh.StringToUint8(props[inc()]) == 1, + RestoreVirgins: d2common.StringToUint8(props[inc()]) == 1, + BlockMissile: d2common.StringToUint8(props[inc()]) == 1, + DrawUnder: d2common.StringToUint8(props[inc()]) == 1, + OpenWarp: d2common.StringToUint8(props[inc()]) == 1, - AutoMap: dh.StringToInt(props[inc()]), + AutoMap: d2common.StringToInt(props[inc()]), } return result } diff --git a/d2common/d2data/d2datadict/sounds.go b/d2common/d2data/d2datadict/sounds.go index 61e4a8e0..3c565c6c 100644 --- a/d2common/d2data/d2datadict/sounds.go +++ b/d2common/d2data/d2datadict/sounds.go @@ -4,7 +4,7 @@ import ( "log" "strings" - dh "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common" ) // SoundEntry represents a sound entry @@ -46,30 +46,30 @@ func createSoundEntry(soundLine string) SoundEntry { } result := SoundEntry{ Handle: props[inc()], - Index: dh.StringToInt(props[inc()]), + Index: d2common.StringToInt(props[inc()]), FileName: props[inc()], - Volume: dh.StringToUint8(props[inc()]), - GroupSize: dh.StringToUint8(props[inc()]), - Loop: dh.StringToUint8(props[inc()]) == 1, - FadeIn: dh.StringToUint8(props[inc()]), - FadeOut: dh.StringToUint8(props[inc()]), - DeferInst: dh.StringToUint8(props[inc()]), - StopInst: dh.StringToUint8(props[inc()]), - Duration: dh.StringToUint8(props[inc()]), - Compound: dh.StringToInt8(props[inc()]), - Reverb: dh.StringToUint8(props[inc()]) == 1, - Falloff: dh.StringToUint8(props[inc()]), - Cache: dh.StringToUint8(props[inc()]), - AsyncOnly: dh.StringToUint8(props[inc()]) == 1, - Priority: dh.StringToUint8(props[inc()]), - Stream: dh.StringToUint8(props[inc()]), - Stereo: dh.StringToUint8(props[inc()]), - Tracking: dh.StringToUint8(props[inc()]), - Solo: dh.StringToUint8(props[inc()]), - MusicVol: dh.StringToUint8(props[inc()]), - Block1: dh.StringToInt(props[inc()]), - Block2: dh.StringToInt(props[inc()]), - Block3: dh.StringToInt(props[inc()]), + Volume: d2common.StringToUint8(props[inc()]), + GroupSize: d2common.StringToUint8(props[inc()]), + Loop: d2common.StringToUint8(props[inc()]) == 1, + FadeIn: d2common.StringToUint8(props[inc()]), + FadeOut: d2common.StringToUint8(props[inc()]), + DeferInst: d2common.StringToUint8(props[inc()]), + StopInst: d2common.StringToUint8(props[inc()]), + Duration: d2common.StringToUint8(props[inc()]), + Compound: d2common.StringToInt8(props[inc()]), + Reverb: d2common.StringToUint8(props[inc()]) == 1, + Falloff: d2common.StringToUint8(props[inc()]), + Cache: d2common.StringToUint8(props[inc()]), + AsyncOnly: d2common.StringToUint8(props[inc()]) == 1, + Priority: d2common.StringToUint8(props[inc()]), + Stream: d2common.StringToUint8(props[inc()]), + Stereo: d2common.StringToUint8(props[inc()]), + Tracking: d2common.StringToUint8(props[inc()]), + Solo: d2common.StringToUint8(props[inc()]), + MusicVol: d2common.StringToUint8(props[inc()]), + Block1: d2common.StringToInt(props[inc()]), + Block2: d2common.StringToInt(props[inc()]), + Block3: d2common.StringToInt(props[inc()]), } return result } diff --git a/d2common/d2data/d2datadict/unique_items.go b/d2common/d2data/d2datadict/unique_items.go index bb73b75a..89583f44 100644 --- a/d2common/d2data/d2datadict/unique_items.go +++ b/d2common/d2data/d2datadict/unique_items.go @@ -5,8 +5,6 @@ import ( "strings" "github.com/OpenDiablo2/OpenDiablo2/d2common" - - dh "github.com/OpenDiablo2/OpenDiablo2/d2common" ) type UniqueItemRecord struct { @@ -58,22 +56,22 @@ func createUniqueItemRecord(r []string) UniqueItemRecord { } result := UniqueItemRecord{ Name: r[inc()], - Version: dh.StringToInt(dh.EmptyToZero(r[inc()])), - Enabled: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, + Version: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + Enabled: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, - Ladder: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - Rarity: dh.StringToInt(dh.EmptyToZero(r[inc()])), - NoLimit: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, + Ladder: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + Rarity: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + NoLimit: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, - Level: dh.StringToInt(dh.EmptyToZero(r[inc()])), - RequiredLevel: dh.StringToInt(dh.EmptyToZero(r[inc()])), + Level: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + RequiredLevel: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), Code: r[inc()], TypeDescription: r[inc()], UberDescription: r[inc()], - SingleCopy: dh.StringToInt(dh.EmptyToZero(r[inc()])) == 1, - CostMultiplier: dh.StringToInt(dh.EmptyToZero(r[inc()])), - CostAdd: dh.StringToInt(dh.EmptyToZero(r[inc()])), + SingleCopy: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + CostMultiplier: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + CostAdd: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), CharacterGfxTransform: r[inc()], InventoryGfxTransform: r[inc()], @@ -81,7 +79,7 @@ func createUniqueItemRecord(r []string) UniqueItemRecord { InventoryFile: r[inc()], DropSound: r[inc()], - DropSfxFrame: dh.StringToInt(dh.EmptyToZero(r[inc()])), + DropSfxFrame: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), UseSound: r[inc()], Properties: [12]UniqueItemProperty{ @@ -108,8 +106,8 @@ func createUniqueItemProperty(r *[]string, inc func() int) UniqueItemProperty { result := UniqueItemProperty{ Property: (*r)[inc()], Parameter: d2common.CalcString((*r)[inc()]), - Min: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), - Max: dh.StringToInt(dh.EmptyToZero((*r)[inc()])), + Min: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + Max: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), } return result } diff --git a/d2common/d2fileformats/d2cof/cof.go b/d2common/d2fileformats/d2cof/cof.go index 05e3c5b3..48a42c7c 100644 --- a/d2common/d2fileformats/d2cof/cof.go +++ b/d2common/d2fileformats/d2cof/cof.go @@ -29,7 +29,7 @@ func LoadCOF(fileData []byte) (*COF, error) { result.Speed = int(streamReader.GetByte()) streamReader.SkipBytes(3) result.CofLayers = make([]CofLayer, result.NumberOfLayers) - result.CompositeLayers = make(map[d2enum.CompositeType]int, 0) + result.CompositeLayers = make(map[d2enum.CompositeType]int) for i := 0; i < result.NumberOfLayers; i++ { layer := CofLayer{} layer.Type = d2enum.CompositeType(streamReader.GetByte()) diff --git a/d2common/d2fileformats/d2dt1/dt1.go b/d2common/d2fileformats/d2dt1/dt1.go index 197b9653..82bc487d 100644 --- a/d2common/d2fileformats/d2dt1/dt1.go +++ b/d2common/d2fileformats/d2dt1/dt1.go @@ -25,7 +25,7 @@ func LoadDT1(fileData []byte) (*DT1, error) { ver1 := br.GetInt32() ver2 := br.GetInt32() if ver1 != 7 || ver2 != 6 { - return nil, fmt.Errorf("Expected to have a version of 7.6, but got %d.%d instead", ver1, ver2) + return nil, fmt.Errorf("expected to have a version of 7.6, but got %d.%d instead", ver1, ver2) } br.SkipBytes(260) numberOfTiles := br.GetInt32() diff --git a/d2core/d2config/config.go b/d2core/d2config/config.go index dc9b4fa4..aefdfa80 100644 --- a/d2core/d2config/config.go +++ b/d2core/d2config/config.go @@ -78,12 +78,10 @@ func getLocalConfigPath() string { func load(configPath string) error { configFile, err := os.Open(configPath) - defer configFile.Close() - if err != nil { return err } - + defer configFile.Close() data, err := ioutil.ReadAll(configFile) if err != nil { return err @@ -103,10 +101,10 @@ func save(configPath string) error { } configFile, err := os.Create(configPath) - defer configFile.Close() if err != nil { return err } + defer configFile.Close() data, err := json.MarshalIndent(singleton, "", " ") if err != nil { diff --git a/d2core/d2gui/button.go b/d2core/d2gui/button.go index a824ee27..f617cf1a 100644 --- a/d2core/d2gui/button.go +++ b/d2core/d2gui/button.go @@ -87,7 +87,6 @@ func createButton(text string, buttonStyle ButtonStyle) (*Button, error) { case buttonStatePressed, buttonStatePressedToggled: textOffsetX = -2 textOffsetY = 2 - break } surface.PushTranslation(textX+textOffsetX, textY+textOffsetY) diff --git a/d2core/d2gui/layout.go b/d2core/d2gui/layout.go index 0eb2bda5..1a4be60d 100644 --- a/d2core/d2gui/layout.go +++ b/d2core/d2gui/layout.go @@ -205,15 +205,12 @@ func (l *Layout) getContentSize() (int, int) { case PositionTypeVertical: width = d2common.MaxInt(width, w) height += h - break case PositionTypeHorizontal: width += w height = d2common.MaxInt(height, h) - break case PositionTypeAbsolute: width = d2common.MaxInt(width, x+w) height = d2common.MaxInt(height, y+h) - break } } @@ -304,10 +301,8 @@ func (l *Layout) adjustEntryPlacement() { switch l.positionType { case PositionTypeVertical: expanderHeight = (height - contentHeight) / expanderCount - break case PositionTypeHorizontal: expanderWidth = (width - contentWidth) / expanderCount - break } expanderWidth = d2common.MaxInt(0, expanderWidth) @@ -333,33 +328,24 @@ func (l *Layout) adjustEntryPlacement() { switch l.horizontalAlign { case HorizontalAlignLeft: entry.x = 0 - break case HorizontalAlignCenter: entry.x = width/2 - entry.width/2 - break case HorizontalAlignRight: entry.x = width - entry.width - break } - break case PositionTypeHorizontal: entry.x = offsetX offsetX += entry.width switch l.verticalAlign { case VerticalAlignTop: entry.y = 0 - break case VerticalAlignMiddle: entry.y = height/2 - entry.height/2 - break case VerticalAlignBottom: entry.y = height - entry.height - break } - break case PositionTypeAbsolute: entry.x, entry.y = entry.widget.getPosition() - break } } } diff --git a/d2core/d2map/d2maprenderer/renderer.go b/d2core/d2map/d2maprenderer/renderer.go index 16b9e625..6a4f0cf1 100644 --- a/d2core/d2map/d2maprenderer/renderer.go +++ b/d2core/d2map/d2maprenderer/renderer.go @@ -330,22 +330,17 @@ func loadPaletteForAct(levelType d2enum.RegionIdType) (*d2dat.DATPalette, error) d2enum.RegionAct1Monestary, d2enum.RegionAct1Courtyard, d2enum.RegionAct1Barracks, d2enum.RegionAct1Jail, d2enum.RegionAct1Cathedral, d2enum.RegionAct1Catacombs, d2enum.RegionAct1Tristram: palettePath = d2resource.PaletteAct1 - break case d2enum.RegionAct2Town, d2enum.RegionAct2Sewer, d2enum.RegionAct2Harem, d2enum.RegionAct2Basement, d2enum.RegionAct2Desert, d2enum.RegionAct2Tomb, d2enum.RegionAct2Lair, d2enum.RegionAct2Arcane: palettePath = d2resource.PaletteAct2 - break case d2enum.RegionAct3Town, d2enum.RegionAct3Jungle, d2enum.RegionAct3Kurast, d2enum.RegionAct3Spider, d2enum.RegionAct3Dungeon, d2enum.RegionAct3Sewer: palettePath = d2resource.PaletteAct3 - break case d2enum.RegionAct4Town, d2enum.RegionAct4Mesa, d2enum.RegionAct4Lava, d2enum.RegionAct5Lava: palettePath = d2resource.PaletteAct4 - break case d2enum.RegonAct5Town, d2enum.RegionAct5Siege, d2enum.RegionAct5Barricade, d2enum.RegionAct5Temple, d2enum.RegionAct5IceCaves, d2enum.RegionAct5Baal: palettePath = d2resource.PaletteAct5 - break default: return nil, errors.New("failed to find palette for region") } diff --git a/d2core/d2render/ebiten/ebiten_renderer.go b/d2core/d2render/ebiten/ebiten_renderer.go index 3143492c..1d6d76c2 100644 --- a/d2core/d2render/ebiten/ebiten_renderer.go +++ b/d2core/d2render/ebiten/ebiten_renderer.go @@ -31,9 +31,9 @@ func CreateRenderer() (*Renderer, error) { config := d2config.Get() - ebiten.SetCursorVisible(false) + ebiten.SetCursorMode(ebiten.CursorModeHidden) ebiten.SetFullscreen(config.FullScreen) - ebiten.SetRunnableInBackground(config.RunInBackground) + ebiten.SetRunnableOnUnfocused(config.RunInBackground) ebiten.SetVsyncEnabled(config.VsyncEnabled) ebiten.SetMaxTPS(config.TicksPerSecond) diff --git a/d2core/d2term/terminal.go b/d2core/d2term/terminal.go index 8e301a68..36322f6e 100644 --- a/d2core/d2term/terminal.go +++ b/d2core/d2term/terminal.go @@ -429,7 +429,6 @@ func (t *terminal) bindAction(name, description string, action interface{}) erro case reflect.Uint: case reflect.Float64: case reflect.Bool: - break default: return errors.New("action has unsupported arguments") } diff --git a/d2game/d2gamescreen/character_select.go b/d2game/d2gamescreen/character_select.go index 71090028..ed8b6871 100644 --- a/d2game/d2gamescreen/character_select.go +++ b/d2game/d2gamescreen/character_select.go @@ -16,7 +16,6 @@ import ( "github.com/hajimehoshi/ebiten" "github.com/OpenDiablo2/OpenDiablo2/d2common" - dh "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset" @@ -68,17 +67,17 @@ func (v *CharacterSelect) OnLoad() error { v.background, _ = d2ui.LoadSprite(animation) v.background.SetPosition(0, 0) - v.newCharButton = d2ui.CreateButton(d2ui.ButtonTypeTall, d2common.CombineStrings(dh.SplitIntoLinesWithMaxWidth("CREATE NEW CHARACTER", 15))) + v.newCharButton = d2ui.CreateButton(d2ui.ButtonTypeTall, d2common.CombineStrings(d2common.SplitIntoLinesWithMaxWidth("CREATE NEW CHARACTER", 15))) v.newCharButton.SetPosition(33, 468) v.newCharButton.OnActivated(func() { v.onNewCharButtonClicked() }) d2ui.AddWidget(&v.newCharButton) - v.convertCharButton = d2ui.CreateButton(d2ui.ButtonTypeTall, d2common.CombineStrings(dh.SplitIntoLinesWithMaxWidth("CONVERT TO EXPANSION", 15))) + v.convertCharButton = d2ui.CreateButton(d2ui.ButtonTypeTall, d2common.CombineStrings(d2common.SplitIntoLinesWithMaxWidth("CONVERT TO EXPANSION", 15))) v.convertCharButton.SetPosition(233, 468) v.convertCharButton.SetEnabled(false) d2ui.AddWidget(&v.convertCharButton) - v.deleteCharButton = d2ui.CreateButton(d2ui.ButtonTypeTall, d2common.CombineStrings(dh.SplitIntoLinesWithMaxWidth("DELETE CHARACTER", 15))) + v.deleteCharButton = d2ui.CreateButton(d2ui.ButtonTypeTall, d2common.CombineStrings(d2common.SplitIntoLinesWithMaxWidth("DELETE CHARACTER", 15))) v.deleteCharButton.OnActivated(func() { v.onDeleteCharButtonClicked() }) v.deleteCharButton.SetPosition(433, 468) d2ui.AddWidget(&v.deleteCharButton) @@ -110,7 +109,7 @@ func (v *CharacterSelect) OnLoad() error { v.d2HeroTitle.Alignment = d2ui.LabelAlignCenter v.deleteCharConfirmLabel = d2ui.CreateLabel(d2resource.Font16, d2resource.PaletteUnits) - lines := dh.SplitIntoLinesWithMaxWidth("Are you sure that you want to delete this character? Take note: this will delete all versions of this Character.", 29) + lines := d2common.SplitIntoLinesWithMaxWidth("Are you sure that you want to delete this character? Take note: this will delete all versions of this Character.", 29) v.deleteCharConfirmLabel.SetText(strings.Join(lines, "\n")) v.deleteCharConfirmLabel.Alignment = d2ui.LabelAlignCenter v.deleteCharConfirmLabel.SetPosition(400, 185) diff --git a/d2game/d2gamescreen/credits.go b/d2game/d2gamescreen/credits.go index 8c3cd40a..f8aa6007 100644 --- a/d2game/d2gamescreen/credits.go +++ b/d2game/d2gamescreen/credits.go @@ -8,7 +8,7 @@ import ( "path" "strings" - dh "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset" @@ -78,7 +78,7 @@ func (v *Credits) OnLoad() error { if err != nil { return err } - creditData, _ := dh.Utf16BytesToString(fileData[2:]) + creditData, _ := d2common.Utf16BytesToString(fileData[2:]) v.creditsText = strings.Split(creditData, "\r\n") for i := range v.creditsText { v.creditsText[i] = strings.Trim(v.creditsText[i], " ") diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index bc9b4ae7..9c4514ec 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -357,7 +357,6 @@ func (v *MainMenu) Advance(tickTime float64) error { } else { v.leftButtonHeld = false } - break } return nil diff --git a/d2game/d2gamescreen/select_hero_class.go b/d2game/d2gamescreen/select_hero_class.go index 01cd9ef6..1af2b014 100644 --- a/d2game/d2gamescreen/select_hero_class.go +++ b/d2game/d2gamescreen/select_hero_class.go @@ -10,7 +10,6 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2networking/d2client/d2clientconnectiontype" "github.com/OpenDiablo2/OpenDiablo2/d2common" - dh "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource" @@ -619,7 +618,7 @@ func (v *SelectHeroClass) updateHeroText() { func (v *SelectHeroClass) setDescLabels(descKey string) { heroDesc := d2common.TranslateString(descKey) - parts := dh.SplitIntoLinesWithMaxWidth(heroDesc, 37) + parts := d2common.SplitIntoLinesWithMaxWidth(heroDesc, 37) if len(parts) > 1 { v.heroDesc1Label.SetText(parts[0]) } else { diff --git a/d2networking/d2client/d2remoteclient/remote_client_connection.go b/d2networking/d2client/d2remoteclient/remote_client_connection.go index 3e220b15..253db2bf 100644 --- a/d2networking/d2client/d2remoteclient/remote_client_connection.go +++ b/d2networking/d2client/d2remoteclient/remote_client_connection.go @@ -46,7 +46,7 @@ func Create() *RemoteClientConnection { } func (l *RemoteClientConnection) Open(connectionString string, saveFilePath string) error { - if strings.Index(connectionString, ":") == -1 { + if !strings.Contains(connectionString, ":") { connectionString += ":6669" } diff --git a/d2networking/d2client/game_client.go b/d2networking/d2client/game_client.go index 09665fe0..08cf8bdc 100644 --- a/d2networking/d2client/game_client.go +++ b/d2networking/d2client/game_client.go @@ -32,7 +32,7 @@ type GameClient struct { func Create(connectionType d2clientconnectiontype.ClientConnectionType) (*GameClient, error) { result := &GameClient{ MapEngine: d2mapengine.CreateMapEngine(), // TODO: Mapgen - Needs levels.txt stuff - Players: make(map[string]*d2mapentity.Player, 0), + Players: make(map[string]*d2mapentity.Player), connectionType: connectionType, } @@ -71,20 +71,17 @@ func (g *GameClient) OnPacketReceived(packet d2netpacket.NetPacket) error { d2mapgen.GenerateAct1Overworld(g.MapEngine) } g.RegenMap = true - break case d2netpackettype.UpdateServerInfo: serverInfo := packet.PacketData.(d2netpacket.UpdateServerInfoPacket) g.MapEngine.SetSeed(serverInfo.Seed) g.PlayerId = serverInfo.PlayerId g.Seed = serverInfo.Seed log.Printf("Player id set to %s", serverInfo.PlayerId) - break case d2netpackettype.AddPlayer: player := packet.PacketData.(d2netpacket.AddPlayerPacket) newPlayer := d2mapentity.CreatePlayer(player.Id, player.Name, player.X, player.Y, 0, player.HeroType, player.Equipment) g.Players[newPlayer.Id] = newPlayer g.MapEngine.AddEntity(newPlayer) - break case d2netpackettype.MovePlayer: movePlayer := packet.PacketData.(d2netpacket.MovePlayerPacket) player := g.Players[movePlayer.PlayerId] @@ -104,7 +101,6 @@ func (g *GameClient) OnPacketReceived(packet d2netpacket.NetPacket) error { } }) } - break default: log.Fatalf("Invalid packet type: %d", packet.PacketType) } diff --git a/d2networking/d2server/game_server.go b/d2networking/d2server/game_server.go index 3c3f50ff..b6590cf3 100644 --- a/d2networking/d2server/game_server.go +++ b/d2networking/d2server/game_server.go @@ -190,7 +190,6 @@ func OnPacketReceived(client ClientConnection, packet d2netpacket.NetPacket) err for _, player := range singletonServer.clientConnections { player.SendPacketToClient(packet) } - break } return nil } diff --git a/main.go b/main.go index 02606a72..acb7bea7 100644 --- a/main.go +++ b/main.go @@ -306,11 +306,9 @@ func renderCapture(target d2render.Surface) error { } log.Printf("saved frame to %s", singleton.capturePath) - break case captureStateGif: screenshot := target.Screenshot() singleton.captureFrames = append(singleton.captureFrames, screenshot) - break case captureStateNone: if len(singleton.captureFrames) > 0 { defer cleanupCapture()