diff --git a/d2app/app.go b/d2app/app.go index b62dfc0d..ffa305b0 100644 --- a/d2app/app.go +++ b/d2app/app.go @@ -6,6 +6,8 @@ import ( "container/ring" "errors" "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2tbl" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "image" "image/gif" "image/png" @@ -21,7 +23,6 @@ import ( "golang.org/x/image/colornames" "gopkg.in/alecthomas/kingpin.v2" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2data" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" @@ -144,7 +145,7 @@ func (a *App) Run() error { func (a *App) initialize() error { a.timeScale = 1.0 - a.lastTime = d2common.Now() + a.lastTime = d2util.Now() a.lastScreenAdvance = a.lastTime a.renderer.SetWindowIcon("d2logo.png") @@ -211,7 +212,7 @@ func (a *App) loadStrings() error { return err } - d2common.LoadTextDictionary(data) + d2tbl.LoadTextDictionary(data) } return nil @@ -424,7 +425,7 @@ func (a *App) advance(elapsed, elapsedUnscaled, current float64) error { } func (a *App) update(target d2interface.Surface) error { - currentTime := d2common.Now() + currentTime := d2util.Now() elapsedTimeUnscaled := currentTime - a.lastTime elapsedTime := elapsedTimeUnscaled * a.timeScale a.lastTime = currentTime diff --git a/d2common/cache.go b/d2common/d2cache/cache.go similarity index 99% rename from d2common/cache.go rename to d2common/d2cache/cache.go index 5293cc86..0526e99b 100644 --- a/d2common/cache.go +++ b/d2common/d2cache/cache.go @@ -1,4 +1,4 @@ -package d2common +package d2cache import ( "errors" diff --git a/d2common/calcstring.go b/d2common/d2calculation/calcstring.go similarity index 94% rename from d2common/calcstring.go rename to d2common/d2calculation/calcstring.go index fa7e7a35..ff2d73b8 100644 --- a/d2common/calcstring.go +++ b/d2common/d2calculation/calcstring.go @@ -1,4 +1,4 @@ -package d2common +package d2calculation // CalcString is a type of string often used in datafiles to specify // a value that is calculated dynamically based on the stats of the relevant diff --git a/d2common/d2data/animation_data.go b/d2common/d2data/animation_data.go index 3b5c093c..c2bda415 100644 --- a/d2common/d2data/animation_data.go +++ b/d2common/d2data/animation_data.go @@ -1,10 +1,9 @@ package d2data import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils" "log" "strings" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" ) const ( @@ -30,7 +29,7 @@ var AnimationData map[string][]*AnimationDataRecord //nolint:gochecknoglobals // // LoadAnimationData loads the animation data table into the global AnimationData dictionary func LoadAnimationData(rawData []byte) { AnimationData = make(map[string][]*AnimationDataRecord) - streamReader := d2common.CreateStreamReader(rawData) + streamReader := d2datautils.CreateStreamReader(rawData) for !streamReader.EOF() { dataCount := int(streamReader.GetInt32()) diff --git a/d2common/d2data/d2compression/huffman.go b/d2common/d2data/d2compression/huffman.go index 07a7ef96..4725e660 100644 --- a/d2common/d2data/d2compression/huffman.go +++ b/d2common/d2data/d2compression/huffman.go @@ -33,7 +33,7 @@ package d2compression import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils" ) // linkedNode is a node which is both hierachcical (parent/child) and doubly linked (next/prev) @@ -199,7 +199,7 @@ func getPrimes() [][]byte { } } -func decode(input *d2common.BitStream, head *linkedNode) *linkedNode { +func decode(input *d2datautils.BitStream, head *linkedNode) *linkedNode { node := head for node.child0 != nil { @@ -386,8 +386,8 @@ func HuffmanDecompress(data []byte) []byte { tail := buildList(primes[comptype]) head := buildTree(tail) - outputstream := d2common.CreateStreamWriter() - bitstream := d2common.CreateBitStream(data[1:]) + outputstream := d2datautils.CreateStreamWriter() + bitstream := d2datautils.CreateBitStream(data[1:]) var decoded int diff --git a/d2common/d2data/d2compression/wav.go b/d2common/d2data/d2compression/wav.go index cebbf52e..32b8706d 100644 --- a/d2common/d2data/d2compression/wav.go +++ b/d2common/d2data/d2compression/wav.go @@ -1,7 +1,7 @@ package d2compression import ( - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils" ) // WavDecompress decompresses wav files @@ -32,8 +32,8 @@ func WavDecompress(data []byte, channelCount int) []byte { //nolint:funlen doesn -1, 2, -1, 4, -1, 6, -1, 8, } - input := d2common.CreateStreamReader(data) - output := d2common.CreateStreamWriter() + input := d2datautils.CreateStreamReader(data) + output := d2datautils.CreateStreamWriter() input.GetByte() diff --git a/d2common/d2data/d2datadict/automagic.go b/d2common/d2data/d2datadict/automagic.go index 3a1ea9f7..662e8415 100644 --- a/d2common/d2data/d2datadict/automagic.go +++ b/d2common/d2data/d2datadict/automagic.go @@ -3,8 +3,8 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // AutoMagicRecord describes rules for automatically generating magic properties when spawning @@ -139,7 +139,7 @@ func LoadAutoMagicRecords(file []byte) { "sor": d2enum.HeroSorceress, } - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &AutoMagicRecord{ diff --git a/d2common/d2data/d2datadict/automap.go b/d2common/d2data/d2datadict/automap.go index 212037a3..fb0ebd98 100644 --- a/d2common/d2data/d2datadict/automap.go +++ b/d2common/d2data/d2datadict/automap.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // AutoMapRecord represents one row from d2data.mpq/AutoMap.txt. @@ -64,7 +64,7 @@ func LoadAutoMaps(file []byte) { var frameFields = []string{"Cel1", "Cel2", "Cel3", "Cel4"} // Split file by newlines and tabs - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &AutoMapRecord{ LevelName: d.String("LevelName"), diff --git a/d2common/d2data/d2datadict/body_locations.go b/d2common/d2data/d2datadict/body_locations.go index c7ec00bd..b39a0a5c 100644 --- a/d2common/d2data/d2datadict/body_locations.go +++ b/d2common/d2data/d2datadict/body_locations.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // BodyLocationRecord describes a body location that items can be equipped to @@ -20,7 +20,7 @@ var BodyLocations map[string]*BodyLocationRecord func LoadBodyLocations(file []byte) { BodyLocations = make(map[string]*BodyLocationRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { location := &BodyLocationRecord{ Name: d.String("Name"), diff --git a/d2common/d2data/d2datadict/books.go b/d2common/d2data/d2datadict/books.go index 2ef3825f..b0281932 100644 --- a/d2common/d2data/d2datadict/books.go +++ b/d2common/d2data/d2datadict/books.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // BooksRecord is a representation of a row from books.txt @@ -28,7 +28,7 @@ var Books map[string]*BooksRecord //nolint:gochecknoglobals // Currently global func LoadBooks(file []byte) { Books = make(map[string]*BooksRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &BooksRecord{ Name: d.String("Name"), diff --git a/d2common/d2data/d2datadict/calculations.go b/d2common/d2data/d2datadict/calculations.go index eae105a7..50ecbe3b 100644 --- a/d2common/d2data/d2datadict/calculations.go +++ b/d2common/d2data/d2datadict/calculations.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // CalculationRecord The skillcalc.txt and misscalc.txt files are essentially lookup tables @@ -24,7 +24,7 @@ var MissileCalculations map[string]*CalculationRecord //nolint:gochecknoglobals func LoadSkillCalculations(file []byte) { SkillCalculations = make(map[string]*CalculationRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &CalculationRecord{ Code: d.String("code"), @@ -44,7 +44,7 @@ func LoadSkillCalculations(file []byte) { func LoadMissileCalculations(file []byte) { MissileCalculations = make(map[string]*CalculationRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &CalculationRecord{ Code: d.String("code"), diff --git a/d2common/d2data/d2datadict/charstats.go b/d2common/d2data/d2datadict/charstats.go index 67e8aebd..3cd9b1bc 100644 --- a/d2common/d2data/d2datadict/charstats.go +++ b/d2common/d2data/d2datadict/charstats.go @@ -3,8 +3,8 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // CharStatsRecord is a struct that represents a single row from charstats.txt @@ -97,7 +97,7 @@ func LoadCharStats(file []byte) { "ht2": d2enum.WeaponClassTwoHandToHand, } - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &CharStatsRecord{ Class: charStringMap[d.String("class")], diff --git a/d2common/d2data/d2datadict/component_codes.go b/d2common/d2data/d2datadict/component_codes.go index 75c59572..0763577d 100644 --- a/d2common/d2data/d2datadict/component_codes.go +++ b/d2common/d2data/d2datadict/component_codes.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // ComponentCodeRecord represents a single row from compcode.txt @@ -20,7 +20,7 @@ var ComponentCodes map[string]*ComponentCodeRecord //nolint:gochecknoglobals // func LoadComponentCodes(file []byte) { ComponentCodes = make(map[string]*ComponentCodeRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &ComponentCodeRecord{ Component: d.String("component"), diff --git a/d2common/d2data/d2datadict/cubemain.go b/d2common/d2data/d2datadict/cubemain.go index b28175a8..2f71063a 100644 --- a/d2common/d2data/d2datadict/cubemain.go +++ b/d2common/d2data/d2datadict/cubemain.go @@ -5,8 +5,8 @@ import ( "strconv" "strings" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // CubeRecipeRecord represents one row from CubeMain.txt. @@ -159,7 +159,7 @@ func LoadCubeRecipes(file []byte) { var inputFields = []string{"input 1", "input 2", "input 3", "input 4", "input 5", "input 6", "input 7"} - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &CubeRecipeRecord{ Description: d.String("description"), diff --git a/d2common/d2data/d2datadict/difficultylevels.go b/d2common/d2data/d2datadict/difficultylevels.go index 400651d8..7f9dd7b8 100644 --- a/d2common/d2data/d2datadict/difficultylevels.go +++ b/d2common/d2data/d2datadict/difficultylevels.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // DifficultyLevels contain the difficulty records for each difficulty @@ -96,7 +96,7 @@ type DifficultyLevelRecord struct { func LoadDifficultyLevels(file []byte) { DifficultyLevels = make(map[string]*DifficultyLevelRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &DifficultyLevelRecord{ Name: d.String("Name"), diff --git a/d2common/d2data/d2datadict/elemtype.go b/d2common/d2data/d2datadict/elemtype.go index 5f5ff197..3dc84867 100644 --- a/d2common/d2data/d2datadict/elemtype.go +++ b/d2common/d2data/d2datadict/elemtype.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // ElemTypeRecord represents a single line in ElemType.txt @@ -22,7 +22,7 @@ var ElemTypes map[string]*ElemTypeRecord //nolint:gochecknoglobals // Currently func LoadElemTypes(file []byte) { ElemTypes = make(map[string]*ElemTypeRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &ElemTypeRecord{ ElemType: d.String("Elemental Type"), diff --git a/d2common/d2data/d2datadict/events.go b/d2common/d2data/d2datadict/events.go index 75f05450..5e56b2ca 100644 --- a/d2common/d2data/d2datadict/events.go +++ b/d2common/d2data/d2datadict/events.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // EventRecord is a representation of a single row from events.txt @@ -18,7 +18,7 @@ var Events map[string]*EventRecord //nolint:gochecknoglobals // Currently global func LoadEvents(file []byte) { Events = make(map[string]*EventRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &EventRecord{ Event: d.String("event"), diff --git a/d2common/d2data/d2datadict/experience.go b/d2common/d2data/d2datadict/experience.go index 75a53a02..ace0235c 100644 --- a/d2common/d2data/d2datadict/experience.go +++ b/d2common/d2data/d2datadict/experience.go @@ -3,8 +3,8 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) /* first column of experience.txt @@ -62,7 +62,7 @@ func GetExperienceBreakpoint(heroType d2enum.Hero, level int) int { func LoadExperienceBreakpoints(file []byte) { ExperienceBreakpoints = make(map[int]*ExperienceBreakpointsRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) d.Next() // the first row describes the max level of char classes diff --git a/d2common/d2data/d2datadict/gems.go b/d2common/d2data/d2datadict/gems.go index f932545d..519149a6 100644 --- a/d2common/d2data/d2datadict/gems.go +++ b/d2common/d2data/d2datadict/gems.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // GemsRecord is a representation of a single row of gems.txt @@ -59,7 +59,7 @@ var Gems map[string]*GemsRecord //nolint:gochecknoglobals // Currently global by func LoadGems(file []byte) { Gems = make(map[string]*GemsRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { gem := &GemsRecord{ Name: d.String("name"), diff --git a/d2common/d2data/d2datadict/hireling.go b/d2common/d2data/d2datadict/hireling.go index 53141aa1..9570c543 100644 --- a/d2common/d2data/d2datadict/hireling.go +++ b/d2common/d2data/d2datadict/hireling.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // HirelingRecord is a representation of rows in hireling.txt @@ -91,7 +91,7 @@ var Hirelings []*HirelingRecord func LoadHireling(file []byte) { Hirelings = make([]*HirelingRecord, 0) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { hireling := &HirelingRecord{ Hireling: d.String("Hireling"), diff --git a/d2common/d2data/d2datadict/inventory.go b/d2common/d2data/d2datadict/inventory.go index a321c769..e22edfe3 100644 --- a/d2common/d2data/d2datadict/inventory.go +++ b/d2common/d2data/d2datadict/inventory.go @@ -3,8 +3,8 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) type box struct { @@ -38,7 +38,7 @@ var Inventory map[string]*InventoryRecord //nolint:gochecknoglobals // Currently // LoadInventory loads all of the inventory records from inventory.txt func LoadInventory(file []byte) { //nolint:funlen // doesn't make sense to split - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) Inventory = make(map[string]*InventoryRecord) for d.Next() { diff --git a/d2common/d2data/d2datadict/item_affix.go b/d2common/d2data/d2datadict/item_affix.go index a3b46ffb..1d2b1c89 100644 --- a/d2common/d2data/d2datadict/item_affix.go +++ b/d2common/d2data/d2datadict/item_affix.go @@ -4,8 +4,8 @@ import ( "fmt" "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // MagicPrefix stores all of the magic prefix records @@ -56,7 +56,7 @@ func loadDictionary( superType d2enum.ItemAffixSuperType, subType d2enum.ItemAffixSubType, ) map[string]*ItemAffixCommonRecord { - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) records := createItemAffixRecords(d, superType, subType) name := getAffixString(superType, subType) log.Printf("Loaded %d %s records", len(records), name) @@ -65,7 +65,7 @@ func loadDictionary( } func createItemAffixRecords( - d *d2common.DataDictionary, + d *d2txt.DataDictionary, superType d2enum.ItemAffixSuperType, subType d2enum.ItemAffixSubType, ) map[string]*ItemAffixCommonRecord { diff --git a/d2common/d2data/d2datadict/item_common.go b/d2common/d2data/d2datadict/item_common.go index de0ff785..ef053502 100644 --- a/d2common/d2data/d2datadict/item_common.go +++ b/d2common/d2data/d2datadict/item_common.go @@ -4,26 +4,25 @@ import ( "strconv" "strings" - "github.com/OpenDiablo2/OpenDiablo2/d2common" - + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2calculation" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" ) // ItemCommonRecord is a representation of entries from armor.txt, weapons.txt, and misc.txt type ItemCommonRecord struct { - UsageStats [3]ItemUsageStat // stat boosts applied upon usage - CureOverlayStates [2]string // name of the overlay states that are removed upon use of this item - OverlayState string // name of the overlay state to be applied upon use of this item - SpellDescriptionString string // points to a string containing the description - BetterGem string // 3 char code pointing to the gem this upgrades to (non if not applicable) - SpellDescriptionCalc d2common.CalcString // a calc string what value to display - WeaponClass string // what kind of attack does this weapon have (i.e. determines attack animations) - WeaponClass2Hand string // what kind of attack when wielded with two hands - HitClass string // determines sounds/graphic effects when attacking - SpecialFeature string // Just a comment - FlavorText string // unknown, probably just for reference - TransmogCode string // the 3 char code representing the item this becomes via transmog - NightmareUpgrade string // upgraded in higher difficulties + UsageStats [3]ItemUsageStat // stat boosts applied upon usage + CureOverlayStates [2]string // name of the overlay states that are removed upon use of this item + OverlayState string // name of the overlay state to be applied upon use of this item + SpellDescriptionString string // points to a string containing the description + BetterGem string // 3 char code pointing to the gem this upgrades to (non if not applicable) + SpellDescriptionCalc d2calculation.CalcString // a calc string what value to display + WeaponClass string // what kind of attack does this weapon have (i.e. determines attack animations) + WeaponClass2Hand string // what kind of attack when wielded with two hands + HitClass string // determines sounds/graphic effects when attacking + SpecialFeature string // Just a comment + FlavorText string // unknown, probably just for reference + TransmogCode string // the 3 char code representing the item this becomes via transmog + NightmareUpgrade string // upgraded in higher difficulties HellUpgrade string SourceArt string // unused? GameArt string // unused? @@ -141,8 +140,8 @@ type ItemCommonRecord struct { // ItemUsageStat the stat that gets applied when the item is used type ItemUsageStat struct { - Stat string // name of the stat to add to - Calc d2common.CalcString // calc string representing the amount to add + Stat string // name of the stat to add to + Calc d2calculation.CalcString // calc string representing the amount to add } // ItemVendorParams are parameters that vendors use @@ -342,7 +341,7 @@ func createCommonItemRecord(line string, mapping map[string]int, source d2enum.I SpellDescriptionType: mapLoadInt(&r, mapping, "spelldesc"), // 0 = none, 1 = use desc string, 2 = use desc string + calc value SpellDescriptionString: mapLoadString(&r, mapping, "spelldescstr"), - SpellDescriptionCalc: d2common.CalcString(mapLoadString(&r, mapping, "spelldesccalc")), + SpellDescriptionCalc: d2calculation.CalcString(mapLoadString(&r, mapping, "spelldesccalc")), BetterGem: mapLoadString(&r, mapping, "BetterGem"), @@ -392,7 +391,7 @@ func createItemUsageStats(r *[]string, mapping map[string]int) [3]ItemUsageStat result := [3]ItemUsageStat{} for i := 0; i < 3; i++ { result[i].Stat = mapLoadString(r, mapping, "stat"+strconv.Itoa(i)) - result[i].Calc = d2common.CalcString(mapLoadString(r, mapping, "calc"+strconv.Itoa(i))) + result[i].Calc = d2calculation.CalcString(mapLoadString(r, mapping, "calc"+strconv.Itoa(i))) } return result diff --git a/d2common/d2data/d2datadict/item_ratio.go b/d2common/d2data/d2datadict/item_ratio.go index a864ac15..0c47c2f9 100644 --- a/d2common/d2data/d2datadict/item_ratio.go +++ b/d2common/d2data/d2datadict/item_ratio.go @@ -4,7 +4,7 @@ import ( "log" "strconv" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // A helper type for item drop calculation @@ -42,7 +42,7 @@ var ItemRatios map[string]*ItemRatioRecord //nolint:gochecknoglobals // Currentl func LoadItemRatios(file []byte) { ItemRatios = make(map[string]*ItemRatioRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &ItemRatioRecord{ Function: d.String("Function"), diff --git a/d2common/d2data/d2datadict/item_types.go b/d2common/d2data/d2datadict/item_types.go index 8a783e87..f7c839e9 100644 --- a/d2common/d2data/d2datadict/item_types.go +++ b/d2common/d2data/d2datadict/item_types.go @@ -3,8 +3,8 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // ItemTypeRecord describes the types for items @@ -201,7 +201,7 @@ func LoadItemTypes(file []byte) { "sor": d2enum.HeroSorceress, } - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { if d.String("*eol") == "" { continue diff --git a/d2common/d2data/d2datadict/itemstatcost.go b/d2common/d2data/d2datadict/itemstatcost.go index 8e73aa2e..3d47d73c 100644 --- a/d2common/d2data/d2datadict/itemstatcost.go +++ b/d2common/d2data/d2datadict/itemstatcost.go @@ -3,8 +3,8 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // ItemStatCostRecord represents a row from itemstatcost.txt @@ -108,7 +108,7 @@ var ItemStatCosts map[string]*ItemStatCostRecord func LoadItemStatCosts(file []byte) { ItemStatCosts = make(map[string]*ItemStatCostRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &ItemStatCostRecord{ Name: d.String("Stat"), diff --git a/d2common/d2data/d2datadict/level_maze.go b/d2common/d2data/d2datadict/level_maze.go index 47efdb3b..e312a6d6 100644 --- a/d2common/d2data/d2datadict/level_maze.go +++ b/d2common/d2data/d2datadict/level_maze.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // LevelMazeDetailsRecord is a representation of a row from lvlmaze.txt @@ -43,7 +43,7 @@ var LevelMazeDetails map[int]*LevelMazeDetailsRecord //nolint:gochecknoglobals / func LoadLevelMazeDetails(file []byte) { LevelMazeDetails = make(map[int]*LevelMazeDetailsRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &LevelMazeDetailsRecord{ Name: d.String("Name"), diff --git a/d2common/d2data/d2datadict/level_presets.go b/d2common/d2data/d2datadict/level_presets.go index 46eb79d1..10eb4639 100644 --- a/d2common/d2data/d2datadict/level_presets.go +++ b/d2common/d2data/d2datadict/level_presets.go @@ -1,10 +1,9 @@ package d2datadict import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "log" "strings" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" ) // LevelPresetRecord is a representation of a row from lvlprest.txt @@ -41,21 +40,21 @@ func createLevelPresetRecord(props []string) LevelPresetRecord { } result := LevelPresetRecord{ Name: 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()]), + DefinitionID: d2util.StringToInt(props[inc()]), + LevelID: d2util.StringToInt(props[inc()]), + Populate: d2util.StringToUint8(props[inc()]) == 1, + Logicals: d2util.StringToUint8(props[inc()]) == 1, + Outdoors: d2util.StringToUint8(props[inc()]) == 1, + Animate: d2util.StringToUint8(props[inc()]) == 1, + KillEdge: d2util.StringToUint8(props[inc()]) == 1, + FillBlanks: d2util.StringToUint8(props[inc()]) == 1, + SizeX: d2util.StringToInt(props[inc()]), + SizeY: d2util.StringToInt(props[inc()]), + AutoMap: d2util.StringToUint8(props[inc()]) == 1, + Scan: d2util.StringToUint8(props[inc()]) == 1, + Pops: d2util.StringToInt(props[inc()]), + PopPad: d2util.StringToInt(props[inc()]), + FileCount: d2util.StringToInt(props[inc()]), Files: [6]string{ props[inc()], props[inc()], @@ -64,9 +63,9 @@ func createLevelPresetRecord(props []string) LevelPresetRecord { props[inc()], props[inc()], }, - Dt1Mask: d2common.StringToUint(props[inc()]), - Beta: d2common.StringToUint8(props[inc()]) == 1, - Expansion: d2common.StringToUint8(props[inc()]) == 1, + Dt1Mask: d2util.StringToUint(props[inc()]), + Beta: d2util.StringToUint8(props[inc()]) == 1, + Expansion: d2util.StringToUint8(props[inc()]) == 1, } return result diff --git a/d2common/d2data/d2datadict/level_sub.go b/d2common/d2data/d2datadict/level_sub.go index 136fed3a..a68ad4ca 100644 --- a/d2common/d2data/d2datadict/level_sub.go +++ b/d2common/d2data/d2datadict/level_sub.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // LevelSubstitutionRecord is a representation of a row from lvlsub.txt @@ -72,7 +72,7 @@ var LevelSubstitutions map[int]*LevelSubstitutionRecord func LoadLevelSubstitutions(file []byte) { LevelSubstitutions = make(map[int]*LevelSubstitutionRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &LevelSubstitutionRecord{ Name: d.String("Name"), diff --git a/d2common/d2data/d2datadict/level_types.go b/d2common/d2data/d2datadict/level_types.go index da36df85..64861ef3 100644 --- a/d2common/d2data/d2datadict/level_types.go +++ b/d2common/d2data/d2datadict/level_types.go @@ -1,10 +1,9 @@ package d2datadict import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "log" "strings" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" ) // LevelTypeRecord is a representation of a row from lvltype.txt @@ -45,7 +44,7 @@ func LoadLevelTypes(file []byte) { } LevelTypes[j].Name = parts[inc()] - LevelTypes[j].ID = d2common.StringToInt(parts[inc()]) + LevelTypes[j].ID = d2util.StringToInt(parts[inc()]) for fileIdx := range LevelTypes[i].Files { LevelTypes[j].Files[fileIdx] = parts[inc()] @@ -55,7 +54,7 @@ func LoadLevelTypes(file []byte) { } LevelTypes[j].Beta = parts[inc()] != "1" - LevelTypes[j].Act = d2common.StringToInt(parts[inc()]) + LevelTypes[j].Act = d2util.StringToInt(parts[inc()]) LevelTypes[j].Expansion = parts[inc()] != "1" } log.Printf("Loaded %d LevelType records", len(LevelTypes)) diff --git a/d2common/d2data/d2datadict/level_warp.go b/d2common/d2data/d2datadict/level_warp.go index 3ac24b46..f5e48049 100644 --- a/d2common/d2data/d2datadict/level_warp.go +++ b/d2common/d2data/d2datadict/level_warp.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // LevelWarpRecord is a representation of a row from lvlwarp.txt @@ -32,7 +32,7 @@ var LevelWarps map[int]*LevelWarpRecord func LoadLevelWarps(file []byte) { LevelWarps = make(map[int]*LevelWarpRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &LevelWarpRecord{ Name: d.String("Name"), diff --git a/d2common/d2data/d2datadict/levels.go b/d2common/d2data/d2datadict/levels.go index 099c8bce..9ed0c17d 100644 --- a/d2common/d2data/d2datadict/levels.go +++ b/d2common/d2data/d2datadict/levels.go @@ -3,8 +3,8 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // LevelDetailsRecord is a representation of a row from levels.txt @@ -383,7 +383,7 @@ func GetLevelDetails(id int) *LevelDetailsRecord { func LoadLevelDetails(file []byte) { LevelDetails = make(map[int]*LevelDetailsRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &LevelDetailsRecord{ Name: d.String("Name "), diff --git a/d2common/d2data/d2datadict/map_helper.go b/d2common/d2data/d2datadict/map_helper.go index c2018f5f..b0efa45f 100644 --- a/d2common/d2data/d2datadict/map_helper.go +++ b/d2common/d2data/d2datadict/map_helper.go @@ -1,9 +1,8 @@ package d2datadict import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "strings" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" ) func mapHeaders(line string) map[string]int { @@ -20,7 +19,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 d2common.StringToInt(d2common.EmptyToZero(d2common.AsterToEmpty((*r)[index]))) + return d2util.StringToInt(d2util.EmptyToZero(d2util.AsterToEmpty((*r)[index]))) } return 0 @@ -29,7 +28,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 d2common.AsterToEmpty((*r)[index]) + return d2util.AsterToEmpty((*r)[index]) } return "" @@ -42,7 +41,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 d2common.StringToUint8(d2common.EmptyToZero(d2common.AsterToEmpty((*r)[index]))) + return d2util.StringToUint8(d2util.EmptyToZero(d2util.AsterToEmpty((*r)[index]))) } return 0 diff --git a/d2common/d2data/d2datadict/missiles.go b/d2common/d2data/d2datadict/missiles.go index c7c8746a..ce3dab43 100644 --- a/d2common/d2data/d2datadict/missiles.go +++ b/d2common/d2data/d2datadict/missiles.go @@ -1,10 +1,11 @@ package d2datadict import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "log" "strings" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2calculation" ) // MissileCalcParam is a calculation parameter for a missile @@ -15,7 +16,7 @@ type MissileCalcParam struct { // MissileCalc is a calculation for a missile type MissileCalc struct { - Calc d2common.CalcString + Calc d2calculation.CalcString Desc string Params []MissileCalcParam } @@ -65,8 +66,8 @@ type MissileDamage struct { MaxDamage int MinLevelDamage [5]int // additional damage per missile level // [0]: lvs 2-8, [1]: lvs 9-16, [2]: lvs 17-22, [3]: lvs 23-28, [4]: lv 29+ - MaxLevelDamage [5]int // see above - DamageSynergyPerCalc d2common.CalcString // works like synergy in skills.txt, not clear + MaxLevelDamage [5]int // see above + DamageSynergyPerCalc d2calculation.CalcString // works like synergy in skills.txt, not clear } // MissileElementalDamage parameters for calculating missile elemental damage @@ -211,13 +212,13 @@ func createMissileRecord(line string) MissileRecord { // be wrapped in an d2common.EmptyToZero transform result := MissileRecord{ Name: r[inc()], - Id: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + Id: d2util.StringToInt(d2util.EmptyToZero(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()]))), + ClientMovementFunc: d2util.StringToInt(d2util.EmptyToZero(d2util.AsterToEmpty(r[inc()]))), + ClientCollisionFunc: d2util.StringToInt(d2util.EmptyToZero(d2util.AsterToEmpty(r[inc()]))), + ServerMovementFunc: d2util.StringToInt(d2util.EmptyToZero(d2util.AsterToEmpty(r[inc()]))), + ServerCollisionFunc: d2util.StringToInt(d2util.EmptyToZero(d2util.AsterToEmpty(r[inc()]))), + ServerDamageFunc: d2util.StringToInt(d2util.EmptyToZero(d2util.AsterToEmpty(r[inc()]))), ServerMovementCalc: loadMissileCalc(&r, inc, 5), ClientMovementCalc: loadMissileCalc(&r, inc, 5), @@ -225,12 +226,12 @@ func createMissileRecord(line string) MissileRecord { ClientCollisionCalc: loadMissileCalc(&r, inc, 3), ServerDamageCalc: loadMissileCalc(&r, inc, 2), - 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()])), + Velocity: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + MaxVelocity: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + LevelVelocityBonus: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + Accel: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + Range: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + LevelRangeBonus: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), Light: loadMissileLight(&r, inc), @@ -238,54 +239,54 @@ func createMissileRecord(line string) MissileRecord { Collision: loadMissileCollision(&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()])), + XOffset: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + YOffset: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + ZOffset: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + Size: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), - DestroyedByTP: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, - DestroyedByTPFrame: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), - CanDestroy: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + DestroyedByTP: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + DestroyedByTPFrame: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + CanDestroy: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, - UseAttackRating: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, - AlwaysExplode: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + UseAttackRating: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + AlwaysExplode: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, - 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()])), + ClientExplosion: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + TownSafe: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + IgnoreBossModifiers: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + IgnoreMultishot: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + HolyFilterType: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + CanBeSlowed: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + TriggersHitEvents: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + TriggersGetHit: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + SoftHit: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + KnockbackPercent: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), - TransparencyMode: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + TransparencyMode: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), - UseQuantity: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, - AffectedByPierce: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, - SpecialSetup: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + UseQuantity: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + AffectedByPierce: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + SpecialSetup: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, - MissileSkill: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + MissileSkill: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, SkillName: r[inc()], - ResultFlags: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), - HitFlags: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + ResultFlags: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + HitFlags: d2util.StringToInt(d2util.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()])), + HitShift: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + ApplyMastery: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + SourceDamage: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + HalfDamageForTwoHander: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + SourceMissDamage: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), Damage: loadMissileDamage(&r, inc), ElementalDamage: loadMissileElementalDamage(&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()])), + HitClass: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + NumDirections: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + LocalBlood: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + DamageReductionRate: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), TravelSound: r[inc()], HitSound: r[inc()], @@ -325,7 +326,7 @@ func LoadMissiles(file []byte) { func loadMissileCalcParam(r *[]string, inc func() int) MissileCalcParam { result := MissileCalcParam{ - Param: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + Param: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), Desc: (*r)[inc()], } @@ -334,7 +335,7 @@ func loadMissileCalcParam(r *[]string, inc func() int) MissileCalcParam { func loadMissileCalc(r *[]string, inc func() int, params int) MissileCalc { result := MissileCalc{ - Calc: d2common.CalcString((*r)[inc()]), + Calc: d2calculation.CalcString((*r)[inc()]), Desc: (*r)[inc()], } result.Params = make([]MissileCalcParam, params) @@ -348,11 +349,11 @@ func loadMissileCalc(r *[]string, inc func() int, params int) MissileCalc { func loadMissileLight(r *[]string, inc func() int) MissileLight { result := MissileLight{ - 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()])), + Diameter: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + Flicker: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + Red: d2util.StringToUint8(d2util.EmptyToZero((*r)[inc()])), + Green: d2util.StringToUint8(d2util.EmptyToZero((*r)[inc()])), + Blue: d2util.StringToUint8(d2util.EmptyToZero((*r)[inc()])), } return result @@ -360,17 +361,17 @@ func loadMissileLight(r *[]string, inc func() int) MissileLight { func loadMissileAnimation(r *[]string, inc func() int) MissileAnimation { result := MissileAnimation{ - StepsBeforeVisible: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), - StepsBeforeActive: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), - LoopAnimation: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])) == 1, + StepsBeforeVisible: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + StepsBeforeActive: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + LoopAnimation: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])) == 1, CelFileName: (*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()])), + AnimationRate: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + AnimationLength: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + AnimationSpeed: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + StartingFrame: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + HasSubLoop: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])) == 1, + SubStartingFrame: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + SubEndingFrame: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), } return result @@ -378,15 +379,15 @@ func loadMissileAnimation(r *[]string, inc func() int) MissileAnimation { func loadMissileCollision(r *[]string, inc func() int) MissileCollision { result := MissileCollision{ - 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()])), + CollisionType: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + DestroyedUponCollision: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])) == 1, + FriendlyFire: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])) == 1, + LastCollide: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])) == 1, + Collision: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])) == 1, + ClientCollision: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])) == 1, + ClientSend: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])) == 1, + UseCollisionTimer: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])) == 1, + TimerFrames: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), } return result @@ -394,23 +395,23 @@ func loadMissileCollision(r *[]string, inc func() int) MissileCollision { func loadMissileDamage(r *[]string, inc func() int) MissileDamage { result := MissileDamage{ - MinDamage: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + MinDamage: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), MinLevelDamage: [5]int{ - 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()])), + d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), }, - MaxDamage: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + MaxDamage: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), MaxLevelDamage: [5]int{ - 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()])), + d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), }, - DamageSynergyPerCalc: d2common.CalcString((*r)[inc()]), + DamageSynergyPerCalc: d2calculation.CalcString((*r)[inc()]), } return result @@ -420,11 +421,11 @@ func loadMissileElementalDamage(r *[]string, inc func() int) MissileElementalDam result := MissileElementalDamage{ ElementType: (*r)[inc()], Damage: loadMissileDamage(r, inc), - Duration: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + Duration: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), LevelDuration: [3]int{ - d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), - d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), - d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), }, } diff --git a/d2common/d2data/d2datadict/monmode.go b/d2common/d2data/d2datadict/monmode.go index 10c3c662..bd6163f8 100644 --- a/d2common/d2data/d2datadict/monmode.go +++ b/d2common/d2data/d2datadict/monmode.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // MonModeRecord is a representation of a single row of Monmode.txt @@ -20,7 +20,7 @@ var MonModes map[string]*MonModeRecord //nolint:gochecknoglobals // Currently gl func LoadMonModes(file []byte) { MonModes = make(map[string]*MonModeRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &MonModeRecord{ Name: d.String("name"), diff --git a/d2common/d2data/d2datadict/monpreset.go b/d2common/d2data/d2datadict/monpreset.go index c0f36b60..35634b8a 100644 --- a/d2common/d2data/d2datadict/monpreset.go +++ b/d2common/d2data/d2datadict/monpreset.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // MonPresets stores monster presets @@ -14,7 +14,7 @@ var MonPresets map[int32][]string func LoadMonPresets(file []byte) { MonPresets = make(map[int32][]string) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { act := int32(d.Number("Act")) if _, ok := MonPresets[act]; !ok { diff --git a/d2common/d2data/d2datadict/monprop.go b/d2common/d2data/d2datadict/monprop.go index 6b81204e..c14ecbb5 100644 --- a/d2common/d2data/d2datadict/monprop.go +++ b/d2common/d2data/d2datadict/monprop.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) const ( @@ -45,7 +45,7 @@ var MonProps map[string]*MonPropRecord //nolint:gochecknoglobals // Currently gl func LoadMonProps(file []byte) { MonProps = make(map[string]*MonPropRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &MonPropRecord{ ID: d.String("Id"), diff --git a/d2common/d2data/d2datadict/monstats.go b/d2common/d2data/d2datadict/monstats.go index d955a959..eec309f6 100644 --- a/d2common/d2data/d2datadict/monstats.go +++ b/d2common/d2data/d2datadict/monstats.go @@ -4,8 +4,7 @@ import ( "log" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // https://d2mods.info/forum/kb/viewarticle?a=360 @@ -687,7 +686,7 @@ var MonStats map[string]*MonStatsRecord //nolint:gochecknoglobals // Currently g func LoadMonStats(file []byte) { // nolint:funlen // Makes no sense to split MonStats = make(map[string]*MonStatsRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &MonStatsRecord{ Key: d.String("Id"), diff --git a/d2common/d2data/d2datadict/monstats2.go b/d2common/d2data/d2datadict/monstats2.go index 0799e95b..0113ecb0 100644 --- a/d2common/d2data/d2datadict/monstats2.go +++ b/d2common/d2data/d2datadict/monstats2.go @@ -3,8 +3,8 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // MonStats2Record is a representation of a row from monstats2.txt @@ -174,7 +174,7 @@ var MonStats2 map[string]*MonStats2Record func LoadMonStats2(file []byte) { MonStats2 = make(map[string]*MonStats2Record) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &MonStats2Record{ Key: d.String("Id"), diff --git a/d2common/d2data/d2datadict/monster_ai.go b/d2common/d2data/d2datadict/monster_ai.go index dd809a79..761131f9 100644 --- a/d2common/d2data/d2datadict/monster_ai.go +++ b/d2common/d2data/d2datadict/monster_ai.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // MonsterAIRecord represents a single row from monai.txt @@ -18,7 +18,7 @@ var MonsterAI map[string]*MonsterAIRecord //nolint:gochecknoglobals // Currently func LoadMonsterAI(file []byte) { MonsterAI = make(map[string]*MonsterAIRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &MonsterAIRecord{ AI: d.String("AI"), diff --git a/d2common/d2data/d2datadict/monster_equipment.go b/d2common/d2data/d2datadict/monster_equipment.go index e425cb36..3aa82994 100644 --- a/d2common/d2data/d2datadict/monster_equipment.go +++ b/d2common/d2data/d2datadict/monster_equipment.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) const ( @@ -48,7 +48,7 @@ var MonsterEquipment map[string][]*MonsterEquipmentRecord //nolint:gochecknoglob func LoadMonsterEquipment(file []byte) { MonsterEquipment = make(map[string][]*MonsterEquipmentRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &MonsterEquipmentRecord{ Name: d.String("monster"), diff --git a/d2common/d2data/d2datadict/monster_level.go b/d2common/d2data/d2datadict/monster_level.go index 17105c62..84b6c6c6 100644 --- a/d2common/d2data/d2datadict/monster_level.go +++ b/d2common/d2data/d2datadict/monster_level.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // MonsterLevelRecord represents a single row in monlvl.txt @@ -58,7 +58,7 @@ var MonsterLevels map[int]*MonsterLevelRecord //nolint:gochecknoglobals // Curre func LoadMonsterLevels(file []byte) { MonsterLevels = make(map[int]*MonsterLevelRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &MonsterLevelRecord{ Level: d.Number("Level"), diff --git a/d2common/d2data/d2datadict/monster_placement.go b/d2common/d2data/d2datadict/monster_placement.go index dc084f03..8d62960a 100644 --- a/d2common/d2data/d2datadict/monster_placement.go +++ b/d2common/d2data/d2datadict/monster_placement.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // MonsterPlacementRecord represents a line from MonPlace.txt. @@ -14,7 +14,7 @@ var MonsterPlacements []MonsterPlacementRecord //nolint:gochecknoglobals // Curr // LoadMonsterPlacements loads the MonsterPlacementRecords into MonsterPlacements. func LoadMonsterPlacements(file []byte) { - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { MonsterPlacements = append(MonsterPlacements, MonsterPlacementRecord(d.String("code"))) } diff --git a/d2common/d2data/d2datadict/monster_sequence.go b/d2common/d2data/d2datadict/monster_sequence.go index 0360ce36..d6ef1931 100644 --- a/d2common/d2data/d2datadict/monster_sequence.go +++ b/d2common/d2data/d2datadict/monster_sequence.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // MonsterSequenceRecord contains a record for a monster sequence @@ -41,7 +41,7 @@ var MonsterSequences map[string]*MonsterSequenceRecord func LoadMonsterSequences(file []byte) { MonsterSequences = make(map[string]*MonsterSequenceRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { name := d.String("sequence") diff --git a/d2common/d2data/d2datadict/monster_sound.go b/d2common/d2data/d2datadict/monster_sound.go index 61d9505f..f0b8874e 100644 --- a/d2common/d2data/d2datadict/monster_sound.go +++ b/d2common/d2data/d2datadict/monster_sound.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // Information gathered from [https://d2mods.info/forum/kb/viewarticle?a=418] @@ -112,7 +112,7 @@ var MonsterSounds map[string]*MonsterSoundRecord func LoadMonsterSounds(file []byte) { MonsterSounds = make(map[string]*MonsterSoundRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &MonsterSoundRecord{ ID: d.String("Id"), diff --git a/d2common/d2data/d2datadict/monster_unique_modifiers.go b/d2common/d2data/d2datadict/monster_unique_modifiers.go index 239bfce1..1d24c7f9 100644 --- a/d2common/d2data/d2datadict/monster_unique_modifiers.go +++ b/d2common/d2data/d2datadict/monster_unique_modifiers.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) const ( @@ -72,7 +72,7 @@ func LoadMonsterUniqueModifiers(file []byte) { MonsterUniqueModifiers = make(map[string]*MonsterUniqueModifierRecord) MonsterUniqueModifierConstants = make([]int, 0, numModifierConstants) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &MonsterUniqueModifierRecord{ Name: d.String("uniquemod"), diff --git a/d2common/d2data/d2datadict/montype.go b/d2common/d2data/d2datadict/montype.go index a8252465..cea84031 100644 --- a/d2common/d2data/d2datadict/montype.go +++ b/d2common/d2data/d2datadict/montype.go @@ -2,8 +2,8 @@ package d2datadict import ( "log" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" + + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // MonTypeRecord is a representation of a single row of MonType.txt. @@ -26,7 +26,7 @@ var MonTypes map[string]*MonTypeRecord //nolint:gochecknoglobals // Currently gl func LoadMonTypes(file []byte) { MonTypes = make(map[string]*MonTypeRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &MonTypeRecord{ Type: d.String("type"), diff --git a/d2common/d2data/d2datadict/npc.go b/d2common/d2data/d2datadict/npc.go index 267178eb..a3f34039 100644 --- a/d2common/d2data/d2datadict/npc.go +++ b/d2common/d2data/d2datadict/npc.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) const ( @@ -47,7 +47,7 @@ var NPCs map[string]*NPCRecord // nolint:gochecknoglobals // Currently global by func LoadNPCs(file []byte) { NPCs = make(map[string]*NPCRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &NPCRecord{ Name: d.String("npc"), diff --git a/d2common/d2data/d2datadict/object_group.go b/d2common/d2data/d2datadict/object_group.go index 9125bb83..a25c9c7b 100644 --- a/d2common/d2data/d2datadict/object_group.go +++ b/d2common/d2data/d2datadict/object_group.go @@ -4,8 +4,8 @@ import ( "fmt" "log" "strconv" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" + + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) const ( @@ -58,7 +58,7 @@ var ObjectGroups map[int]*ObjectGroupRecord //nolint:gochecknoglobals // Current // LoadObjectGroups loads the ObjectGroupRecords into ObjectGroups. func LoadObjectGroups(file []byte) { ObjectGroups = make(map[int]*ObjectGroupRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { groupName := d.String("GroupName") @@ -84,7 +84,7 @@ func LoadObjectGroups(file []byte) { log.Printf("Loaded %d ObjectGroup records", len(ObjectGroups)) } -func createMembers(d *d2common.DataDictionary, shrinesOrWells bool) *[objectsGroupSize]ObjectGroupMember { +func createMembers(d *d2txt.DataDictionary, shrinesOrWells bool) *[objectsGroupSize]ObjectGroupMember { var members [objectsGroupSize]ObjectGroupMember for i := 0; i < objectsGroupSize; i++ { diff --git a/d2common/d2data/d2datadict/object_types.go b/d2common/d2data/d2datadict/object_types.go index e1d5fefe..d3f3b9b4 100644 --- a/d2common/d2data/d2datadict/object_types.go +++ b/d2common/d2data/d2datadict/object_types.go @@ -4,7 +4,7 @@ import ( "log" "strings" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils" ) // ObjectTypeRecord is a representation of a row from objtype.txt @@ -19,7 +19,7 @@ var ObjectTypes []ObjectTypeRecord // LoadObjectTypes loads ObjectTypeRecords from objtype.txt func LoadObjectTypes(objectTypeData []byte) { - streamReader := d2common.CreateStreamReader(objectTypeData) + streamReader := d2datautils.CreateStreamReader(objectTypeData) count := streamReader.GetInt32() ObjectTypes = make([]ObjectTypeRecord, count) diff --git a/d2common/d2data/d2datadict/objects.go b/d2common/d2data/d2datadict/objects.go index 9ca16235..7417b86a 100644 --- a/d2common/d2data/d2datadict/objects.go +++ b/d2common/d2data/d2datadict/objects.go @@ -1,10 +1,9 @@ package d2datadict import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "log" "strings" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" ) // An ObjectRecord represents the settings for one type of object from objects.txt @@ -130,206 +129,206 @@ func createObjectRecord(props []string) ObjectRecord { result := ObjectRecord{ Name: props[inc()], Description: props[inc()], - id: d2common.StringToInt(props[inc()]), + id: d2util.StringToInt(props[inc()]), token: props[inc()], - SpawnMax: d2common.StringToInt(props[inc()]), + SpawnMax: d2util.StringToInt(props[inc()]), Selectable: [8]bool{ - 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, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, }, - TrapProbability: d2common.StringToInt(props[inc()]), + TrapProbability: d2util.StringToInt(props[inc()]), - SizeX: d2common.StringToInt(props[inc()]), - SizeY: d2common.StringToInt(props[inc()]), + SizeX: d2util.StringToInt(props[inc()]), + SizeY: d2util.StringToInt(props[inc()]), - NTgtFX: d2common.StringToInt(props[inc()]), - NTgtFY: d2common.StringToInt(props[inc()]), - NTgtBX: d2common.StringToInt(props[inc()]), - NTgtBY: d2common.StringToInt(props[inc()]), + NTgtFX: d2util.StringToInt(props[inc()]), + NTgtFY: d2util.StringToInt(props[inc()]), + NTgtBX: d2util.StringToInt(props[inc()]), + NTgtBY: d2util.StringToInt(props[inc()]), FrameCount: [8]int{ - 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()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), }, FrameDelta: [8]int{ - 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()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), }, CycleAnimation: [8]bool{ - 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, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, }, LightDiameter: [8]int{ - 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()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), }, BlocksLight: [8]bool{ - 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, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, }, HasCollision: [8]bool{ - 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, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, }, - IsAttackable: d2common.StringToUint8(props[inc()]) == 1, + IsAttackable: d2util.StringToUint8(props[inc()]) == 1, StartFrame: [8]int{ - 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()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.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()]), + EnvEffect: d2util.StringToUint8(props[inc()]) == 1, + IsDoor: d2util.StringToUint8(props[inc()]) == 1, + BlockVisibility: d2util.StringToUint8(props[inc()]) == 1, + Orientation: d2util.StringToInt(props[inc()]), + Trans: d2util.StringToInt(props[inc()]), OrderFlag: [8]int{ - 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()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), }, - PreOperate: d2common.StringToUint8(props[inc()]) == 1, + PreOperate: d2util.StringToUint8(props[inc()]) == 1, HasAnimationMode: [8]bool{ - 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, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, }, - XOffset: d2common.StringToInt(props[inc()]), - YOffset: d2common.StringToInt(props[inc()]), - Draw: d2common.StringToUint8(props[inc()]) == 1, + XOffset: d2util.StringToInt(props[inc()]), + YOffset: d2util.StringToInt(props[inc()]), + Draw: d2util.StringToUint8(props[inc()]) == 1, - LightRed: d2common.StringToUint8(props[inc()]), - LightGreen: d2common.StringToUint8(props[inc()]), - LightBlue: d2common.StringToUint8(props[inc()]), + LightRed: d2util.StringToUint8(props[inc()]), + LightGreen: d2util.StringToUint8(props[inc()]), + LightBlue: d2util.StringToUint8(props[inc()]), - 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, + SelHD: d2util.StringToUint8(props[inc()]) == 1, + SelTR: d2util.StringToUint8(props[inc()]) == 1, + SelLG: d2util.StringToUint8(props[inc()]) == 1, + SelRA: d2util.StringToUint8(props[inc()]) == 1, + SelLA: d2util.StringToUint8(props[inc()]) == 1, + SelRH: d2util.StringToUint8(props[inc()]) == 1, + SelLH: d2util.StringToUint8(props[inc()]) == 1, + SelSH: d2util.StringToUint8(props[inc()]) == 1, SelS: [8]bool{ - 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, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, + d2util.StringToUint8(props[inc()]) == 1, }, - TotalPieces: d2common.StringToInt(props[inc()]), - SubClass: d2common.StringToInt(props[inc()]), + TotalPieces: d2util.StringToInt(props[inc()]), + SubClass: d2util.StringToInt(props[inc()]), - XSpace: d2common.StringToInt(props[inc()]), - YSpace: d2common.StringToInt(props[inc()]), + XSpace: d2util.StringToInt(props[inc()]), + YSpace: d2util.StringToInt(props[inc()]), - NameOffset: d2common.StringToInt(props[inc()]), + NameOffset: d2util.StringToInt(props[inc()]), - MonsterOk: d2common.StringToUint8(props[inc()]) == 1, - OperateRange: d2common.StringToInt(props[inc()]), - ShrineFunction: d2common.StringToInt(props[inc()]), - Restore: d2common.StringToUint8(props[inc()]) == 1, + MonsterOk: d2util.StringToUint8(props[inc()]) == 1, + OperateRange: d2util.StringToInt(props[inc()]), + ShrineFunction: d2util.StringToInt(props[inc()]), + Restore: d2util.StringToUint8(props[inc()]) == 1, Parm: [8]int{ - 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()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), + d2util.StringToInt(props[inc()]), }, - 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, + Act: d2util.StringToInt(props[inc()]), + Lockable: d2util.StringToUint8(props[inc()]) == 1, + Gore: d2util.StringToUint8(props[inc()]) == 1, + Sync: d2util.StringToUint8(props[inc()]) == 1, + Flicker: d2util.StringToUint8(props[inc()]) == 1, + Damage: d2util.StringToInt(props[inc()]), + Beta: d2util.StringToUint8(props[inc()]) == 1, + Overlay: d2util.StringToUint8(props[inc()]) == 1, + CollisionSubst: d2util.StringToUint8(props[inc()]) == 1, - Left: d2common.StringToInt(props[inc()]), - Top: d2common.StringToInt(props[inc()]), - Width: d2common.StringToInt(props[inc()]), - Height: d2common.StringToInt(props[inc()]), + Left: d2util.StringToInt(props[inc()]), + Top: d2util.StringToInt(props[inc()]), + Width: d2util.StringToInt(props[inc()]), + Height: d2util.StringToInt(props[inc()]), - OperateFn: d2common.StringToInt(props[inc()]), - PopulateFn: d2common.StringToInt(props[inc()]), - InitFn: d2common.StringToInt(props[inc()]), - ClientFn: d2common.StringToInt(props[inc()]), + OperateFn: d2util.StringToInt(props[inc()]), + PopulateFn: d2util.StringToInt(props[inc()]), + InitFn: d2util.StringToInt(props[inc()]), + ClientFn: d2util.StringToInt(props[inc()]), - RestoreVirgins: d2common.StringToUint8(props[inc()]) == 1, - BlockMissile: d2common.StringToUint8(props[inc()]) == 1, - DrawUnder: d2common.StringToUint8(props[inc()]) == 1, - OpenWarp: d2common.StringToUint8(props[inc()]) == 1, + RestoreVirgins: d2util.StringToUint8(props[inc()]) == 1, + BlockMissile: d2util.StringToUint8(props[inc()]) == 1, + DrawUnder: d2util.StringToUint8(props[inc()]) == 1, + OpenWarp: d2util.StringToUint8(props[inc()]) == 1, - AutoMap: d2common.StringToInt(props[inc()]), + AutoMap: d2util.StringToInt(props[inc()]), } return result diff --git a/d2common/d2data/d2datadict/overlay.go b/d2common/d2data/d2datadict/overlay.go index 14661e49..cca5f766 100644 --- a/d2common/d2data/d2datadict/overlay.go +++ b/d2common/d2data/d2datadict/overlay.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // The information has been gathered from [https://d2mods.info/forum/kb/viewarticle?a=465] @@ -67,7 +67,7 @@ var Overlays map[string]*OverlayRecord // nolint:gochecknoglobals // Currently g // LoadOverlays loads overlay records from Overlay.txt func LoadOverlays(file []byte) { Overlays = make(map[string]*OverlayRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &OverlayRecord{ diff --git a/d2common/d2data/d2datadict/pettype.go b/d2common/d2data/d2datadict/pettype.go index 90b5f3b5..a22b7538 100644 --- a/d2common/d2data/d2datadict/pettype.go +++ b/d2common/d2data/d2datadict/pettype.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // PetTypeRecord represents a single line in PetType.txt @@ -68,7 +68,7 @@ var PetTypes map[string]*PetTypeRecord // nolint:gochecknoglobals // Currently g func LoadPetTypes(file []byte) { PetTypes = make(map[string]*PetTypeRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &PetTypeRecord{ Name: d.String("pet type"), diff --git a/d2common/d2data/d2datadict/player_class.go b/d2common/d2data/d2datadict/player_class.go index 9a026b25..530bd3b4 100644 --- a/d2common/d2data/d2datadict/player_class.go +++ b/d2common/d2data/d2datadict/player_class.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // PlayerClassRecord represents a single line from PlayerClass.txt @@ -23,7 +23,7 @@ var PlayerClasses map[string]*PlayerClassRecord // nolint:gochecknoglobals // Cu func LoadPlayerClasses(file []byte) { PlayerClasses = make(map[string]*PlayerClassRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &PlayerClassRecord{ Name: d.String("Player Class"), diff --git a/d2common/d2data/d2datadict/plrmode.go b/d2common/d2data/d2datadict/plrmode.go index 7735e243..8da5698a 100644 --- a/d2common/d2data/d2datadict/plrmode.go +++ b/d2common/d2data/d2datadict/plrmode.go @@ -2,8 +2,8 @@ package d2datadict import ( "log" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" + + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // PlrModeRecord represents a single line in PlrMode.txt @@ -22,7 +22,7 @@ var PlrModes map[string]*PlrModeRecord //nolint:gochecknoglobals // Currently gl func LoadPlrModes(file []byte) { PlrModes = make(map[string]*PlrModeRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &PlrModeRecord{ Name: d.String("Name"), diff --git a/d2common/d2data/d2datadict/properties.go b/d2common/d2data/d2datadict/properties.go index 6b70676e..0c3aa458 100644 --- a/d2common/d2data/d2datadict/properties.go +++ b/d2common/d2data/d2datadict/properties.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // PropertyStatRecord contains stat information for a property @@ -28,7 +28,7 @@ var Properties map[string]*PropertyRecord //nolint:gochecknoglobals // Currently func LoadProperties(file []byte) { Properties = make(map[string]*PropertyRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { prop := &PropertyRecord{ Code: d.String("code"), diff --git a/d2common/d2data/d2datadict/quality_items.go b/d2common/d2data/d2datadict/quality_items.go index d4fcea8e..255bdc3c 100644 --- a/d2common/d2data/d2datadict/quality_items.go +++ b/d2common/d2data/d2datadict/quality_items.go @@ -4,7 +4,7 @@ import ( "log" "strconv" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // QualityRecord represents a single row of QualityItems.txt, which controls @@ -46,7 +46,7 @@ var QualityItems map[string]*QualityRecord //nolint:gochecknoglobals // Currentl func LoadQualityItems(file []byte) { QualityItems = make(map[string]*QualityRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { qual := &QualityRecord{ NumMods: d.Number("nummods"), diff --git a/d2common/d2data/d2datadict/rare_prefix.go b/d2common/d2data/d2datadict/rare_prefix.go index fe502cde..35032bb7 100644 --- a/d2common/d2data/d2datadict/rare_prefix.go +++ b/d2common/d2data/d2datadict/rare_prefix.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) const ( @@ -27,7 +27,7 @@ var RarePrefixes []*RareItemPrefixRecord // nolint:gochecknoglobals // global by // LoadRareItemPrefixRecords loads the rare item prefix records from rareprefix.txt func LoadRareItemPrefixRecords(file []byte) { - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) RarePrefixes = make([]*RareItemPrefixRecord, 0) diff --git a/d2common/d2data/d2datadict/rare_suffix.go b/d2common/d2data/d2datadict/rare_suffix.go index 2f019de4..8c47f6c6 100644 --- a/d2common/d2data/d2datadict/rare_suffix.go +++ b/d2common/d2data/d2datadict/rare_suffix.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) const ( @@ -27,7 +27,7 @@ var RareSuffixes []*RareItemSuffixRecord // nolint:gochecknoglobals // global by // LoadRareItemSuffixRecords loads the rare item suffix records from raresuffix.txt func LoadRareItemSuffixRecords(file []byte) { - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) RareSuffixes = make([]*RareItemSuffixRecord, 0) diff --git a/d2common/d2data/d2datadict/runes.go b/d2common/d2data/d2datadict/runes.go index b48a7a41..fb885c82 100644 --- a/d2common/d2data/d2datadict/runes.go +++ b/d2common/d2data/d2datadict/runes.go @@ -3,8 +3,8 @@ package d2datadict import ( "fmt" "log" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" + + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) const ( @@ -67,7 +67,7 @@ var Runewords map[string]*RunesRecord //nolint:gochecknoglobals // Currently glo func LoadRunewords(file []byte) { Runewords = make(map[string]*RunesRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &RunesRecord{ Name: d.String("name"), diff --git a/d2common/d2data/d2datadict/set_items.go b/d2common/d2data/d2datadict/set_items.go index 75e7661d..db56b9ed 100644 --- a/d2common/d2data/d2datadict/set_items.go +++ b/d2common/d2data/d2datadict/set_items.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) const ( @@ -133,7 +133,7 @@ var SetItems map[string]*SetItemRecord //nolint:gochecknoglobals // Currently gl func LoadSetItems(file []byte) { SetItems = make(map[string]*SetItemRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &SetItemRecord{ diff --git a/d2common/d2data/d2datadict/sets.go b/d2common/d2data/d2datadict/sets.go index e010f5d3..7e747a4d 100644 --- a/d2common/d2data/d2datadict/sets.go +++ b/d2common/d2data/d2datadict/sets.go @@ -3,8 +3,8 @@ package d2datadict import ( "fmt" "log" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" + + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) const ( @@ -79,7 +79,7 @@ var SetRecords map[string]*SetRecord //nolint:gochecknoglobals // Currently glob func LoadSetRecords(file []byte) { //nolint:funlen // doesn't make sense to split SetRecords = make(map[string]*SetRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &SetRecord{ Key: d.String("index"), diff --git a/d2common/d2data/d2datadict/shrines.go b/d2common/d2data/d2datadict/shrines.go index ad7779da..1b067165 100644 --- a/d2common/d2data/d2datadict/shrines.go +++ b/d2common/d2data/d2datadict/shrines.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // ShrineRecord is a representation of a row from shrines.txt @@ -29,7 +29,7 @@ var Shrines map[string]*ShrineRecord func LoadShrines(file []byte) { Shrines = make(map[string]*ShrineRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &ShrineRecord{ ShrineType: d.String("Shrine Type"), diff --git a/d2common/d2data/d2datadict/skilldesc.go b/d2common/d2data/d2datadict/skilldesc.go index a59a9fbd..7a74115b 100644 --- a/d2common/d2data/d2datadict/skilldesc.go +++ b/d2common/d2data/d2datadict/skilldesc.go @@ -3,9 +3,9 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2calculation" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2calculation/d2parser" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // SkillDescriptionRecord is a single row from skilldesc.txt and is used for @@ -137,7 +137,7 @@ func LoadSkillDescriptions(file []byte) { //nolint:funlen // doesn't make sense parser := d2parser.New() parser.SetCurrentReference("skill", "TODO: connect skill with description!") //nolint:godox // TODO: Connect skill with description. - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &SkillDescriptionRecord{ d.String("skilldesc"), diff --git a/d2common/d2data/d2datadict/skills.go b/d2common/d2data/d2datadict/skills.go index c36f1696..e5fc7b2b 100644 --- a/d2common/d2data/d2datadict/skills.go +++ b/d2common/d2data/d2datadict/skills.go @@ -3,9 +3,9 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2calculation" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2calculation/d2parser" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // SkillDetails has all of the SkillRecords @@ -266,7 +266,7 @@ func LoadSkills(file []byte) { parser := d2parser.New() - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { name := d.String("skill") parser.SetCurrentReference("skill", name) diff --git a/d2common/d2data/d2datadict/soundenviron.go b/d2common/d2data/d2datadict/soundenviron.go index 6aba7070..986df82c 100644 --- a/d2common/d2data/d2datadict/soundenviron.go +++ b/d2common/d2data/d2datadict/soundenviron.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // SoundEnvironRecord describes the different sound environments. Not listed on Phrozen Keep. @@ -42,7 +42,7 @@ var SoundEnvirons map[int]*SoundEnvironRecord func LoadSoundEnvirons(file []byte) { SoundEnvirons = make(map[int]*SoundEnvironRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &SoundEnvironRecord{ Handle: d.String("Handle"), diff --git a/d2common/d2data/d2datadict/sounds.go b/d2common/d2data/d2datadict/sounds.go index 4707d951..9c83c2f4 100644 --- a/d2common/d2data/d2datadict/sounds.go +++ b/d2common/d2data/d2datadict/sounds.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // SoundEntry represents a sound entry @@ -43,7 +43,7 @@ var Sounds map[string]*SoundEntry func LoadSounds(file []byte) { Sounds = make(map[string]*SoundEntry) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { entry := &SoundEntry{ Handle: d.String("Sound"), diff --git a/d2common/d2data/d2datadict/states.go b/d2common/d2data/d2datadict/states.go index 89015e8e..527cd03b 100644 --- a/d2common/d2data/d2datadict/states.go +++ b/d2common/d2data/d2datadict/states.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // StateRecord describes a body location that items can be equipped to @@ -249,7 +249,7 @@ var States map[string]*StateRecord func LoadStates(file []byte) { States = make(map[string]*StateRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &StateRecord{ State: d.String("state"), diff --git a/d2common/d2data/d2datadict/super_uniques.go b/d2common/d2data/d2datadict/super_uniques.go index 9b5155eb..0378edf1 100644 --- a/d2common/d2data/d2datadict/super_uniques.go +++ b/d2common/d2data/d2datadict/super_uniques.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // https://d2mods.info/forum/kb/viewarticle?a=162 @@ -127,7 +127,7 @@ var SuperUniques map[string]*SuperUniqueRecord func LoadSuperUniques(file []byte) { SuperUniques = make(map[string]*SuperUniqueRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &SuperUniqueRecord{ Key: d.String("Superunique"), diff --git a/d2common/d2data/d2datadict/treasure_class.go b/d2common/d2data/d2datadict/treasure_class.go index 7e417393..0ddccf83 100644 --- a/d2common/d2data/d2datadict/treasure_class.go +++ b/d2common/d2data/d2datadict/treasure_class.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) const ( @@ -42,7 +42,7 @@ var TreasureClass map[string]*TreasureClassRecord //nolint:gochecknoglobals // C func LoadTreasureClassRecords(file []byte) { TreasureClass = make(map[string]*TreasureClassRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &TreasureClassRecord{ diff --git a/d2common/d2data/d2datadict/unique_appellation.go b/d2common/d2data/d2datadict/unique_appellation.go index e910486e..09a89710 100644 --- a/d2common/d2data/d2datadict/unique_appellation.go +++ b/d2common/d2data/d2datadict/unique_appellation.go @@ -3,7 +3,7 @@ package d2datadict import ( "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt" ) // UniqueAppellationRecord described the extra suffix of a unique monster name @@ -20,7 +20,7 @@ var UniqueAppellations map[string]*UniqueAppellationRecord func LoadUniqueAppellations(file []byte) { UniqueAppellations = make(map[string]*UniqueAppellationRecord) - d := d2common.LoadDataDictionary(file) + d := d2txt.LoadDataDictionary(file) for d.Next() { record := &UniqueAppellationRecord{ Name: d.String("Name"), diff --git a/d2common/d2data/d2datadict/unique_items.go b/d2common/d2data/d2datadict/unique_items.go index ebc49ae0..bcb98d18 100644 --- a/d2common/d2data/d2datadict/unique_items.go +++ b/d2common/d2data/d2datadict/unique_items.go @@ -1,10 +1,9 @@ package d2datadict import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "log" "strings" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" ) // UniqueItemRecord is a representation of a row from uniqueitems.txt @@ -56,22 +55,22 @@ func createUniqueItemRecord(r []string) UniqueItemRecord { } result := UniqueItemRecord{ Name: r[inc()], - Version: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), - Enabled: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, + Version: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + Enabled: d2util.StringToInt(d2util.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, + Ladder: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + Rarity: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + NoLimit: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, - Level: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), - RequiredLevel: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + Level: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + RequiredLevel: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), Code: r[inc()], TypeDescription: r[inc()], UberDescription: r[inc()], - SingleCopy: d2common.StringToInt(d2common.EmptyToZero(r[inc()])) == 1, - CostMultiplier: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), - CostAdd: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + SingleCopy: d2util.StringToInt(d2util.EmptyToZero(r[inc()])) == 1, + CostMultiplier: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), + CostAdd: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), CharacterGfxTransform: r[inc()], InventoryGfxTransform: r[inc()], @@ -79,7 +78,7 @@ func createUniqueItemRecord(r []string) UniqueItemRecord { InventoryFile: r[inc()], DropSound: r[inc()], - DropSfxFrame: d2common.StringToInt(d2common.EmptyToZero(r[inc()])), + DropSfxFrame: d2util.StringToInt(d2util.EmptyToZero(r[inc()])), UseSound: r[inc()], Properties: [12]UniqueItemProperty{ @@ -107,8 +106,8 @@ func createUniqueItemProperty(r *[]string, inc func() int) UniqueItemProperty { result := UniqueItemProperty{ Code: (*r)[inc()], Parameter: (*r)[inc()], - Min: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), - Max: d2common.StringToInt(d2common.EmptyToZero((*r)[inc()])), + Min: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), + Max: d2util.StringToInt(d2util.EmptyToZero((*r)[inc()])), } return result diff --git a/d2common/d2data/d2video/binkdecoder.go b/d2common/d2data/d2video/binkdecoder.go index b145ede4..25e3dbaf 100644 --- a/d2common/d2data/d2video/binkdecoder.go +++ b/d2common/d2data/d2video/binkdecoder.go @@ -1,9 +1,8 @@ package d2video import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils" "log" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" ) // BinkVideoMode is the video mode type @@ -53,7 +52,7 @@ type BinkAudioTrack struct { type BinkDecoder struct { AudioTracks []BinkAudioTrack FrameIndexTable []uint32 - streamReader *d2common.StreamReader + streamReader *d2datautils.StreamReader fileSize uint32 numberOfFrames uint32 largestFrameSizeBytes uint32 @@ -74,7 +73,7 @@ type BinkDecoder struct { // CreateBinkDecoder returns a new instance of the bink decoder func CreateBinkDecoder(source []byte) *BinkDecoder { result := &BinkDecoder{ - streamReader: d2common.CreateStreamReader(source), + streamReader: d2datautils.CreateStreamReader(source), } result.loadHeaderInformation() diff --git a/d2common/bitmuncher.go b/d2common/d2datautils/bitmuncher.go similarity index 99% rename from d2common/bitmuncher.go rename to d2common/d2datautils/bitmuncher.go index 9c9a435a..7352970e 100644 --- a/d2common/bitmuncher.go +++ b/d2common/d2datautils/bitmuncher.go @@ -1,4 +1,4 @@ -package d2common +package d2datautils // BitMuncher is used for parsing files that are not byte-aligned such as the DCC files. type BitMuncher struct { diff --git a/d2common/bitstream.go b/d2common/d2datautils/bitstream.go similarity index 98% rename from d2common/bitstream.go rename to d2common/d2datautils/bitstream.go index 2d8882d9..9e706d78 100644 --- a/d2common/bitstream.go +++ b/d2common/d2datautils/bitstream.go @@ -1,4 +1,4 @@ -package d2common +package d2datautils import ( "log" diff --git a/d2common/bitstream_test.go b/d2common/d2datautils/bitstream_test.go similarity index 97% rename from d2common/bitstream_test.go rename to d2common/d2datautils/bitstream_test.go index cb420f1b..3c538e00 100644 --- a/d2common/bitstream_test.go +++ b/d2common/d2datautils/bitstream_test.go @@ -1,4 +1,4 @@ -package d2common +package d2datautils import ( "testing" diff --git a/d2common/stream_reader.go b/d2common/d2datautils/stream_reader.go similarity index 99% rename from d2common/stream_reader.go rename to d2common/d2datautils/stream_reader.go index a262293c..c66d8212 100644 --- a/d2common/stream_reader.go +++ b/d2common/d2datautils/stream_reader.go @@ -1,4 +1,4 @@ -package d2common +package d2datautils import ( "io" diff --git a/d2common/stream_reader_test.go b/d2common/d2datautils/stream_reader_test.go similarity index 98% rename from d2common/stream_reader_test.go rename to d2common/d2datautils/stream_reader_test.go index 6743c5a0..94789ec1 100644 --- a/d2common/stream_reader_test.go +++ b/d2common/d2datautils/stream_reader_test.go @@ -1,4 +1,4 @@ -package d2common +package d2datautils import ( "testing" diff --git a/d2common/stream_writer.go b/d2common/d2datautils/stream_writer.go similarity index 98% rename from d2common/stream_writer.go rename to d2common/d2datautils/stream_writer.go index 38595353..10870a73 100644 --- a/d2common/stream_writer.go +++ b/d2common/d2datautils/stream_writer.go @@ -1,4 +1,4 @@ -package d2common +package d2datautils import "bytes" diff --git a/d2common/stream_writer_test.go b/d2common/d2datautils/stream_writer_test.go similarity index 98% rename from d2common/stream_writer_test.go rename to d2common/d2datautils/stream_writer_test.go index f2e35dda..126425b4 100644 --- a/d2common/stream_writer_test.go +++ b/d2common/d2datautils/stream_writer_test.go @@ -1,4 +1,4 @@ -package d2common +package d2datautils import ( "testing" diff --git a/d2common/d2fileformats/d2cof/cof.go b/d2common/d2fileformats/d2cof/cof.go index 7091aaef..d94b6b4e 100644 --- a/d2common/d2fileformats/d2cof/cof.go +++ b/d2common/d2fileformats/d2cof/cof.go @@ -1,9 +1,9 @@ package d2cof import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils" "strings" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" ) @@ -22,7 +22,7 @@ type COF struct { // Load loads a COF file. func Load(fileData []byte) (*COF, error) { result := &COF{} - streamReader := d2common.CreateStreamReader(fileData) + streamReader := d2datautils.CreateStreamReader(fileData) result.NumberOfLayers = int(streamReader.GetByte()) result.FramesPerDirection = int(streamReader.GetByte()) result.NumberOfDirections = int(streamReader.GetByte()) diff --git a/d2common/d2fileformats/d2dc6/dc6.go b/d2common/d2fileformats/d2dc6/dc6.go index c95bbc80..237c4d06 100644 --- a/d2common/d2fileformats/d2dc6/dc6.go +++ b/d2common/d2fileformats/d2dc6/dc6.go @@ -1,7 +1,7 @@ package d2dc6 import ( - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils" ) const ( @@ -36,7 +36,7 @@ func Load(data []byte) (*DC6, error) { terminatorSize = 3 ) - r := d2common.CreateStreamReader(data) + r := d2datautils.CreateStreamReader(data) var dc DC6 dc.Version = r.GetInt32() diff --git a/d2common/d2fileformats/d2dcc/dcc.go b/d2common/d2fileformats/d2dcc/dcc.go index 918ba436..6210388c 100644 --- a/d2common/d2fileformats/d2dcc/dcc.go +++ b/d2common/d2fileformats/d2dcc/dcc.go @@ -2,8 +2,7 @@ package d2dcc import ( "errors" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils" ) const dccFileSignature = 0x74 @@ -25,7 +24,7 @@ func Load(fileData []byte) (*DCC, error) { fileData: fileData, } - var bm = d2common.CreateBitMuncher(fileData, 0) + var bm = d2datautils.CreateBitMuncher(fileData, 0) result.Signature = int(bm.GetByte()) @@ -54,6 +53,6 @@ func Load(fileData []byte) (*DCC, error) { // DecodeDirection decodes and returns the given direction func (dcc *DCC) DecodeDirection(direction int) *DCCDirection { - return CreateDCCDirection(d2common.CreateBitMuncher(dcc.fileData, + return CreateDCCDirection(d2datautils.CreateBitMuncher(dcc.fileData, dcc.directionOffsets[direction]*directionOffsetMultiplier), dcc) } diff --git a/d2common/d2fileformats/d2dcc/dcc_direction.go b/d2common/d2fileformats/d2dcc/dcc_direction.go index 0004356d..eb0a8597 100644 --- a/d2common/d2fileformats/d2dcc/dcc_direction.go +++ b/d2common/d2fileformats/d2dcc/dcc_direction.go @@ -1,9 +1,10 @@ package d2dcc import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2geom" "log" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2math" ) @@ -26,7 +27,7 @@ type DCCDirection struct { RawPixelCodesBitstreamSize int Frames []*DCCDirectionFrame PaletteEntries [256]byte - Box d2common.Rectangle + Box d2geom.Rectangle Cells []*DCCCell PixelData []byte HorizontalCellCount int @@ -35,7 +36,7 @@ type DCCDirection struct { } // CreateDCCDirection creates an instance of a DCCDirection. -func CreateDCCDirection(bm *d2common.BitMuncher, file *DCC) *DCCDirection { +func CreateDCCDirection(bm *d2datautils.BitMuncher, file *DCC) *DCCDirection { var crazyBitTable = []byte{0, 1, 2, 4, 6, 8, 10, 12, 14, 16, 20, 24, 26, 28, 30, 32} result := &DCCDirection{ @@ -65,7 +66,7 @@ func CreateDCCDirection(bm *d2common.BitMuncher, file *DCC) *DCCDirection { 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 = d2geom.Rectangle{Left: minx, Top: miny, Width: maxx - minx, Height: maxy - miny} if result.OptionalDataBits > 0 { log.Panic("Optional bits in DCC data is not currently supported.") @@ -95,23 +96,23 @@ func CreateDCCDirection(bm *d2common.BitMuncher, file *DCC) *DCCDirection { // here. For example, if you are on byte offset 3, bit offset 6, and // the EqualCellsBitstreamSize is 20 bytes, then the next bit stream // will be located at byte 23, bit offset 6! - equalCellsBitstream := d2common.CopyBitMuncher(bm) + equalCellsBitstream := d2datautils.CopyBitMuncher(bm) bm.SkipBits(result.EqualCellsBitstreamSize) - pixelMaskBitstream := d2common.CopyBitMuncher(bm) + pixelMaskBitstream := d2datautils.CopyBitMuncher(bm) bm.SkipBits(result.PixelMaskBitstreamSize) - encodingTypeBitsream := d2common.CopyBitMuncher(bm) + encodingTypeBitsream := d2datautils.CopyBitMuncher(bm) bm.SkipBits(result.EncodingTypeBitsreamSize) - rawPixelCodesBitstream := d2common.CopyBitMuncher(bm) + rawPixelCodesBitstream := d2datautils.CopyBitMuncher(bm) bm.SkipBits(result.RawPixelCodesBitstreamSize) - pixelCodeandDisplacement := d2common.CopyBitMuncher(bm) + pixelCodeandDisplacement := d2datautils.CopyBitMuncher(bm) // Calculate the cells for the direction result.calculateCells() @@ -137,7 +138,7 @@ func CreateDCCDirection(bm *d2common.BitMuncher, file *DCC) *DCCDirection { return result } -func (v *DCCDirection) verify(equalCellsBitstream, pixelMaskBitstream, encodingTypeBitsream, rawPixelCodesBitstream *d2common.BitMuncher) { +func (v *DCCDirection) verify(equalCellsBitstream, pixelMaskBitstream, encodingTypeBitsream, rawPixelCodesBitstream *d2datautils.BitMuncher) { if equalCellsBitstream.BitsRead() != v.EqualCellsBitstreamSize { log.Panic("Did not read the correct number of bits!") } @@ -156,7 +157,7 @@ func (v *DCCDirection) verify(equalCellsBitstream, pixelMaskBitstream, encodingT } //nolint:gocognit nolint:gocyclo // Can't reduce -func (v *DCCDirection) generateFrames(pcd *d2common.BitMuncher) { +func (v *DCCDirection) generateFrames(pcd *d2datautils.BitMuncher) { pbIdx := 0 for _, cell := range v.Cells { @@ -259,7 +260,7 @@ func (v *DCCDirection) generateFrames(pcd *d2common.BitMuncher) { } //nolint:funlen nolint:gocognit // can't reduce -func (v *DCCDirection) fillPixelBuffer(pcd, ec, pm, et, rp *d2common.BitMuncher) { +func (v *DCCDirection) fillPixelBuffer(pcd, ec, pm, et, rp *d2datautils.BitMuncher) { var pixelMaskLookup = []int{0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4} lastPixel := uint32(0) diff --git a/d2common/d2fileformats/d2dcc/dcc_direction_frame.go b/d2common/d2fileformats/d2dcc/dcc_direction_frame.go index d5cb69e4..6029ac49 100644 --- a/d2common/d2fileformats/d2dcc/dcc_direction_frame.go +++ b/d2common/d2fileformats/d2dcc/dcc_direction_frame.go @@ -1,14 +1,14 @@ package d2dcc import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2geom" "log" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" ) // DCCDirectionFrame represents a direction frame for a DCC. type DCCDirectionFrame struct { - Box d2common.Rectangle + Box d2geom.Rectangle Cells []DCCCell PixelData []byte Width int @@ -24,7 +24,7 @@ type DCCDirectionFrame struct { } // CreateDCCDirectionFrame Creates a DCCDirectionFrame for a DCC. -func CreateDCCDirectionFrame(bits *d2common.BitMuncher, direction *DCCDirection) *DCCDirectionFrame { +func CreateDCCDirectionFrame(bits *d2datautils.BitMuncher, direction *DCCDirection) *DCCDirectionFrame { result := &DCCDirectionFrame{} bits.GetBits(direction.Variable0Bits) // Variable0 @@ -40,7 +40,7 @@ func CreateDCCDirectionFrame(bits *d2common.BitMuncher, direction *DCCDirection) if result.FrameIsBottomUp { log.Panic("Bottom up frames are not implemented.") } else { - result.Box = d2common.Rectangle{ + result.Box = d2geom.Rectangle{ Left: result.XOffset, Top: result.YOffset - result.Height + 1, Width: result.Width, diff --git a/d2common/d2fileformats/d2ds1/ds1.go b/d2common/d2fileformats/d2ds1/ds1.go index 093ab08a..f40a2a07 100644 --- a/d2common/d2fileformats/d2ds1/ds1.go +++ b/d2common/d2fileformats/d2ds1/ds1.go @@ -1,10 +1,11 @@ package d2ds1 import ( - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2math" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2path" ) const maxActNumber = 5 @@ -36,7 +37,7 @@ func LoadDS1(fileData []byte) (*DS1, error) { NumberOfShadowLayers: 1, NumberOfSubstitutionLayers: 0, } - br := d2common.CreateStreamReader(fileData) + br := d2datautils.CreateStreamReader(fileData) ds1.Version = br.GetInt32() ds1.Width = br.GetInt32() + 1 ds1.Height = br.GetInt32() + 1 @@ -107,7 +108,7 @@ func LoadDS1(fileData []byte) (*DS1, error) { return ds1, nil } -func (ds1 *DS1) loadObjects(br *d2common.StreamReader) { +func (ds1 *DS1) loadObjects(br *d2datautils.StreamReader) { if ds1.Version >= 2 { //nolint:gomnd // Version number numberOfObjects := br.GetInt32() ds1.Objects = make([]Object, numberOfObjects) @@ -127,7 +128,7 @@ func (ds1 *DS1) loadObjects(br *d2common.StreamReader) { } } -func (ds1 *DS1) loadSubstitutions(br *d2common.StreamReader) { +func (ds1 *DS1) loadSubstitutions(br *d2datautils.StreamReader) { if ds1.Version >= 12 && (ds1.SubstitutionType == 1 || ds1.SubstitutionType == 2) { if ds1.Version >= 18 { //nolint:gomnd // Version number br.GetUInt32() @@ -188,7 +189,7 @@ func (ds1 *DS1) setupStreamLayerTypes() []d2enum.LayerStreamType { return layerStream } -func (ds1 *DS1) loadNPCs(br *d2common.StreamReader) { +func (ds1 *DS1) loadNPCs(br *d2datautils.StreamReader) { if ds1.Version >= 14 { //nolint:gomnd // Version number numberOfNpcs := br.GetInt32() for npcIdx := 0; npcIdx < int(numberOfNpcs); npcIdx++ { @@ -217,13 +218,13 @@ func (ds1 *DS1) loadNPCs(br *d2common.StreamReader) { } } -func (ds1 *DS1) loadNpcPaths(br *d2common.StreamReader, objIdx, numPaths int) { +func (ds1 *DS1) loadNpcPaths(br *d2datautils.StreamReader, objIdx, numPaths int) { if ds1.Objects[objIdx].Paths == nil { - ds1.Objects[objIdx].Paths = make([]d2common.Path, numPaths) + ds1.Objects[objIdx].Paths = make([]d2path.Path, numPaths) } for pathIdx := 0; pathIdx < numPaths; pathIdx++ { - newPath := d2common.Path{} + newPath := d2path.Path{} newPath.Position = d2vector.NewPosition( float64(br.GetInt32()), float64(br.GetInt32())) @@ -236,7 +237,7 @@ func (ds1 *DS1) loadNpcPaths(br *d2common.StreamReader, objIdx, numPaths int) { } } -func (ds1 *DS1) loadLayerStreams(br *d2common.StreamReader, layerStream []d2enum.LayerStreamType) { +func (ds1 *DS1) loadLayerStreams(br *d2datautils.StreamReader, layerStream []d2enum.LayerStreamType) { var dirLookup = []int32{ 0x00, 0x01, 0x02, 0x01, 0x02, 0x03, 0x03, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, diff --git a/d2common/d2fileformats/d2ds1/object.go b/d2common/d2fileformats/d2ds1/object.go index dcc315c5..6a47164a 100644 --- a/d2common/d2fileformats/d2ds1/object.go +++ b/d2common/d2fileformats/d2ds1/object.go @@ -1,7 +1,7 @@ package d2ds1 import ( - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2path" ) // Object is a game world object @@ -11,5 +11,5 @@ type Object struct { X int Y int Flags int - Paths []d2common.Path + Paths []d2path.Path } diff --git a/d2common/d2fileformats/d2dt1/dt1.go b/d2common/d2fileformats/d2dt1/dt1.go index 9c541b22..a3afb016 100644 --- a/d2common/d2fileformats/d2dt1/dt1.go +++ b/d2common/d2fileformats/d2dt1/dt1.go @@ -2,8 +2,7 @@ package d2dt1 import ( "fmt" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils" ) // DT1 represents a DT1 file. @@ -26,7 +25,7 @@ const ( //nolint:funlen Can't reduce func LoadDT1(fileData []byte) (*DT1, error) { result := &DT1{} - br := d2common.CreateStreamReader(fileData) + br := d2datautils.CreateStreamReader(fileData) ver1 := br.GetInt32() ver2 := br.GetInt32() diff --git a/d2common/d2fileformats/d2tbl/doc.go b/d2common/d2fileformats/d2tbl/doc.go new file mode 100644 index 00000000..b3c1ba27 --- /dev/null +++ b/d2common/d2fileformats/d2tbl/doc.go @@ -0,0 +1,2 @@ +// Package d2tbl provides a file parser for tbl string table files +package d2tbl diff --git a/d2common/text_dictionary.go b/d2common/d2fileformats/d2tbl/text_dictionary.go similarity index 94% rename from d2common/text_dictionary.go rename to d2common/d2fileformats/d2tbl/text_dictionary.go index 072b172c..d852df56 100644 --- a/d2common/text_dictionary.go +++ b/d2common/d2fileformats/d2tbl/text_dictionary.go @@ -1,8 +1,10 @@ -package d2common +package d2tbl import ( "log" "strconv" + + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils" ) type textDictionaryHashEntry struct { @@ -38,7 +40,7 @@ func LoadTextDictionary(dictionaryData []byte) { lookupTable = make(map[string]string) } - br := CreateStreamReader(dictionaryData) + br := d2datautils.CreateStreamReader(dictionaryData) // skip past the CRC br.ReadBytes(crcByteCount) diff --git a/d2common/data_dictionary.go b/d2common/d2fileformats/d2txt/data_dictionary.go similarity index 99% rename from d2common/data_dictionary.go rename to d2common/d2fileformats/d2txt/data_dictionary.go index c6a8445b..75e6ca05 100644 --- a/d2common/data_dictionary.go +++ b/d2common/d2fileformats/d2txt/data_dictionary.go @@ -1,4 +1,4 @@ -package d2common +package d2txt import ( "bytes" diff --git a/d2common/d2fileformats/d2txt/doc.go b/d2common/d2fileformats/d2txt/doc.go new file mode 100644 index 00000000..5f15aa3c --- /dev/null +++ b/d2common/d2fileformats/d2txt/doc.go @@ -0,0 +1,2 @@ +// Package d2txt provides a parser implementation for diablo TSV data files +package d2txt diff --git a/d2common/Point.go b/d2common/d2geom/point.go similarity index 90% rename from d2common/Point.go rename to d2common/d2geom/point.go index f0006357..6ea0e518 100644 --- a/d2common/Point.go +++ b/d2common/d2geom/point.go @@ -1,4 +1,4 @@ -package d2common +package d2geom // Point represents a point type Point struct { diff --git a/d2common/rectangle.go b/d2common/d2geom/rectangle.go similarity index 96% rename from d2common/rectangle.go rename to d2common/d2geom/rectangle.go index 54d2213d..b5df83a1 100644 --- a/d2common/rectangle.go +++ b/d2common/d2geom/rectangle.go @@ -1,4 +1,4 @@ -package d2common +package d2geom // Rectangle represents a rectangle type Rectangle struct { diff --git a/d2common/size.go b/d2common/d2geom/size.go similarity index 79% rename from d2common/size.go rename to d2common/d2geom/size.go index b0c03f59..d0009006 100644 --- a/d2common/size.go +++ b/d2common/d2geom/size.go @@ -1,4 +1,4 @@ -package d2common +package d2geom // Size represents a size type Size struct { diff --git a/d2common/path.go b/d2common/d2path/path.go similarity index 90% rename from d2common/path.go rename to d2common/d2path/path.go index b490bd7b..1da2da77 100644 --- a/d2common/path.go +++ b/d2common/d2path/path.go @@ -1,4 +1,4 @@ -package d2common +package d2path import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector" diff --git a/d2common/d2resource/music_defs.go b/d2common/d2resource/music_defs.go new file mode 100644 index 00000000..3c4973c8 --- /dev/null +++ b/d2common/d2resource/music_defs.go @@ -0,0 +1,66 @@ +package d2resource + +import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" +) + +// MusicDef stores the music definitions of a region +type MusicDef struct { + Region d2enum.RegionIdType + InTown bool + MusicFile string +} + +func getMusicDefs() []MusicDef { + return []MusicDef{ + {d2enum.RegionAct1Town, false, BGMAct1Town1}, + {d2enum.RegionAct1Wilderness, false, BGMAct1Wild}, + {d2enum.RegionAct1Cave, false, BGMAct1Caves}, + {d2enum.RegionAct1Crypt, false, BGMAct1Crypt}, + {d2enum.RegionAct1Monestary, false, BGMAct1Monastery}, + {d2enum.RegionAct1Courtyard, false, BGMAct1Monastery}, + {d2enum.RegionAct1Barracks, false, BGMAct1Monastery}, + {d2enum.RegionAct1Jail, false, BGMAct1Monastery}, + {d2enum.RegionAct1Cathedral, false, BGMAct1Monastery}, + {d2enum.RegionAct1Catacombs, false, BGMAct1Monastery}, + {d2enum.RegionAct1Tristram, false, BGMAct1Tristram}, + {d2enum.RegionAct2Town, false, BGMAct2Town2}, + {d2enum.RegionAct2Sewer, false, BGMAct2Sewer}, + {d2enum.RegionAct2Harem, false, BGMAct2Harem}, + {d2enum.RegionAct2Basement, false, BGMAct2Harem}, + {d2enum.RegionAct2Desert, false, BGMAct2Desert}, + {d2enum.RegionAct2Tomb, false, BGMAct2Tombs}, + {d2enum.RegionAct2Lair, false, BGMAct2Lair}, + {d2enum.RegionAct2Arcane, false, BGMAct2Sanctuary}, + {d2enum.RegionAct3Town, false, BGMAct3Town3}, + {d2enum.RegionAct3Jungle, false, BGMAct3Jungle}, + {d2enum.RegionAct3Kurast, false, BGMAct3Kurast}, + {d2enum.RegionAct3Spider, false, BGMAct3Spider}, + {d2enum.RegionAct3Dungeon, false, BGMAct3KurastSewer}, + {d2enum.RegionAct3Sewer, false, BGMAct3KurastSewer}, + {d2enum.RegionAct4Town, false, BGMAct4Town4}, + {d2enum.RegionAct4Mesa, false, BGMAct4Mesa}, + {d2enum.RegionAct4Lava, false, BGMAct4Mesa}, + {d2enum.RegonAct5Town, false, BGMAct5XTown}, + {d2enum.RegionAct5Siege, false, BGMAct5Siege}, + {d2enum.RegionAct5Barricade, false, BGMAct5Siege}, // ? + {d2enum.RegionAct5Temple, false, BGMAct5XTemple}, + {d2enum.RegionAct5IceCaves, false, BGMAct5IceCaves}, + {d2enum.RegionAct5Baal, false, BGMAct5Baal}, + {d2enum.RegionAct5Lava, false, BGMAct5Nihlathak}, // ? + } +} + +// GetMusicDef returns the MusicDef of the given region +func GetMusicDef(regionType d2enum.RegionIdType) *MusicDef { + musicDefs := getMusicDefs() + for idx := range musicDefs { + if musicDefs[idx].Region != regionType { + continue + } + + return &musicDefs[idx] + } + + return &musicDefs[0] +} diff --git a/d2common/d2debugutil/assets/assets.go b/d2common/d2util/assets/assets.go similarity index 100% rename from d2common/d2debugutil/assets/assets.go rename to d2common/d2util/assets/assets.go diff --git a/d2common/d2debugutil/assets/noto_sans_mono_8x16.bmp b/d2common/d2util/assets/noto_sans_mono_8x16.bmp similarity index 100% rename from d2common/d2debugutil/assets/noto_sans_mono_8x16.bmp rename to d2common/d2util/assets/noto_sans_mono_8x16.bmp diff --git a/d2common/d2debugutil/assets/zipbmp.go b/d2common/d2util/assets/zipbmp.go similarity index 100% rename from d2common/d2debugutil/assets/zipbmp.go rename to d2common/d2util/assets/zipbmp.go diff --git a/d2common/d2debugutil/debug_print.go b/d2common/d2util/debug_print.go similarity index 94% rename from d2common/d2debugutil/debug_print.go rename to d2common/d2util/debug_print.go index f3a5c3cc..36b1a70a 100644 --- a/d2common/d2debugutil/debug_print.go +++ b/d2common/d2util/debug_print.go @@ -1,10 +1,9 @@ -// Package d2debugutil provides debug utilities -package d2debugutil +package d2util import ( "image" - "github.com/OpenDiablo2/OpenDiablo2/d2common/d2debugutil/assets" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util/assets" "github.com/hajimehoshi/ebiten" ) diff --git a/d2common/rgba_color.go b/d2common/d2util/rgba_color.go similarity index 96% rename from d2common/rgba_color.go rename to d2common/d2util/rgba_color.go index 6fc5f266..b667263a 100644 --- a/d2common/rgba_color.go +++ b/d2common/d2util/rgba_color.go @@ -1,4 +1,4 @@ -package d2common +package d2util import "image/color" diff --git a/d2common/stringutils.go b/d2common/d2util/stringutils.go similarity index 99% rename from d2common/stringutils.go rename to d2common/d2util/stringutils.go index 88114656..c9c859cb 100644 --- a/d2common/stringutils.go +++ b/d2common/d2util/stringutils.go @@ -1,4 +1,4 @@ -package d2common +package d2util import ( "bytes" diff --git a/d2common/timeutils.go b/d2common/d2util/timeutils.go similarity index 94% rename from d2common/timeutils.go rename to d2common/d2util/timeutils.go index 641141c9..c856f668 100644 --- a/d2common/timeutils.go +++ b/d2common/d2util/timeutils.go @@ -1,4 +1,4 @@ -package d2common +package d2util import "time" diff --git a/d2common/music_defs.go b/d2common/music_defs.go deleted file mode 100644 index e40bd6f9..00000000 --- a/d2common/music_defs.go +++ /dev/null @@ -1,67 +0,0 @@ -package d2common - -import ( - "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" - "github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource" -) - -// MusicDef stores the music definitions of a region -type MusicDef struct { - Region d2enum.RegionIdType - InTown bool - MusicFile string -} - -func getMusicDefs() []MusicDef { - return []MusicDef{ - {d2enum.RegionAct1Town, false, d2resource.BGMAct1Town1}, - {d2enum.RegionAct1Wilderness, false, d2resource.BGMAct1Wild}, - {d2enum.RegionAct1Cave, false, d2resource.BGMAct1Caves}, - {d2enum.RegionAct1Crypt, false, d2resource.BGMAct1Crypt}, - {d2enum.RegionAct1Monestary, false, d2resource.BGMAct1Monastery}, - {d2enum.RegionAct1Courtyard, false, d2resource.BGMAct1Monastery}, - {d2enum.RegionAct1Barracks, false, d2resource.BGMAct1Monastery}, - {d2enum.RegionAct1Jail, false, d2resource.BGMAct1Monastery}, - {d2enum.RegionAct1Cathedral, false, d2resource.BGMAct1Monastery}, - {d2enum.RegionAct1Catacombs, false, d2resource.BGMAct1Monastery}, - {d2enum.RegionAct1Tristram, false, d2resource.BGMAct1Tristram}, - {d2enum.RegionAct2Town, false, d2resource.BGMAct2Town2}, - {d2enum.RegionAct2Sewer, false, d2resource.BGMAct2Sewer}, - {d2enum.RegionAct2Harem, false, d2resource.BGMAct2Harem}, - {d2enum.RegionAct2Basement, false, d2resource.BGMAct2Harem}, - {d2enum.RegionAct2Desert, false, d2resource.BGMAct2Desert}, - {d2enum.RegionAct2Tomb, false, d2resource.BGMAct2Tombs}, - {d2enum.RegionAct2Lair, false, d2resource.BGMAct2Lair}, - {d2enum.RegionAct2Arcane, false, d2resource.BGMAct2Sanctuary}, - {d2enum.RegionAct3Town, false, d2resource.BGMAct3Town3}, - {d2enum.RegionAct3Jungle, false, d2resource.BGMAct3Jungle}, - {d2enum.RegionAct3Kurast, false, d2resource.BGMAct3Kurast}, - {d2enum.RegionAct3Spider, false, d2resource.BGMAct3Spider}, - {d2enum.RegionAct3Dungeon, false, d2resource.BGMAct3KurastSewer}, - {d2enum.RegionAct3Sewer, false, d2resource.BGMAct3KurastSewer}, - {d2enum.RegionAct4Town, false, d2resource.BGMAct4Town4}, - {d2enum.RegionAct4Mesa, false, d2resource.BGMAct4Mesa}, - {d2enum.RegionAct4Lava, false, d2resource.BGMAct4Mesa}, - {d2enum.RegonAct5Town, false, d2resource.BGMAct5XTown}, - {d2enum.RegionAct5Siege, false, d2resource.BGMAct5Siege}, - {d2enum.RegionAct5Barricade, false, d2resource.BGMAct5Siege}, // ? - {d2enum.RegionAct5Temple, false, d2resource.BGMAct5XTemple}, - {d2enum.RegionAct5IceCaves, false, d2resource.BGMAct5IceCaves}, - {d2enum.RegionAct5Baal, false, d2resource.BGMAct5Baal}, - {d2enum.RegionAct5Lava, false, d2resource.BGMAct5Nihlathak}, // ? - } -} - -// GetMusicDef returns the MusicDef of the given region -func GetMusicDef(regionType d2enum.RegionIdType) *MusicDef { - musicDefs := getMusicDefs() - for idx := range musicDefs { - if musicDefs[idx].Region != regionType { - continue - } - - return &musicDefs[idx] - } - - return &musicDefs[0] -} diff --git a/d2core/d2asset/animation_manager.go b/d2core/d2asset/animation_manager.go index faec5157..1c1a15ae 100644 --- a/d2core/d2asset/animation_manager.go +++ b/d2core/d2asset/animation_manager.go @@ -2,10 +2,10 @@ package d2asset import ( "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2cache" "path/filepath" "strings" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" ) @@ -34,7 +34,7 @@ func (am *animationManager) GetCache() d2interface.Cache { func createAnimationManager(renderer d2interface.Renderer) *animationManager { return &animationManager{ renderer: renderer, - cache: d2common.CreateCache(animationBudget), + cache: d2cache.CreateCache(animationBudget), } } diff --git a/d2core/d2asset/archive_manager.go b/d2core/d2asset/archive_manager.go index cbbea321..0192b0b9 100644 --- a/d2core/d2asset/archive_manager.go +++ b/d2core/d2asset/archive_manager.go @@ -2,10 +2,10 @@ package d2asset import ( "errors" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2cache" "path" "sync" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2mpq" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2config" @@ -27,7 +27,7 @@ const ( ) func createArchiveManager(config *d2config.Configuration) d2interface.ArchiveManager { - return &archiveManager{cache: d2common.CreateCache(archiveBudget), config: config} + return &archiveManager{cache: d2cache.CreateCache(archiveBudget), config: config} } // LoadArchiveForFile loads the archive for the given (in-archive) file path diff --git a/d2core/d2asset/archived_file_manager.go b/d2core/d2asset/archived_file_manager.go index 31d381d1..9a7baf14 100644 --- a/d2core/d2asset/archived_file_manager.go +++ b/d2core/d2asset/archived_file_manager.go @@ -1,9 +1,9 @@ package d2asset import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2cache" "strings" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2config" @@ -26,7 +26,7 @@ type fileManager struct { func createFileManager(config *d2config.Configuration, archiveManager d2interface.ArchiveManager) d2interface.FileManager { return &fileManager{ - d2common.CreateCache(fileBudget), + d2cache.CreateCache(fileBudget), archiveManager, config, } diff --git a/d2core/d2asset/font_manager.go b/d2core/d2asset/font_manager.go index b0c5fc59..1c5eca44 100644 --- a/d2core/d2asset/font_manager.go +++ b/d2core/d2asset/font_manager.go @@ -2,8 +2,7 @@ package d2asset import ( "fmt" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2cache" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" ) @@ -20,7 +19,7 @@ type fontManager struct { } func createFontManager() d2interface.FontManager { - return &fontManager{d2common.CreateCache(fontBudget)} + return &fontManager{d2cache.CreateCache(fontBudget)} } // LoadFont loads a font from the archives managed by the ArchiveManager diff --git a/d2core/d2asset/palette_manager.go b/d2core/d2asset/palette_manager.go index 960b6bed..0c295f20 100644 --- a/d2core/d2asset/palette_manager.go +++ b/d2core/d2asset/palette_manager.go @@ -1,7 +1,7 @@ package d2asset import ( - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2cache" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dat" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" ) @@ -19,7 +19,7 @@ const ( ) func createPaletteManager() d2interface.PaletteManager { - return &paletteManager{d2common.CreateCache(paletteBudget)} + return &paletteManager{d2cache.CreateCache(paletteBudget)} } // LoadPalette loads a palette from archives managed by the ArchiveManager diff --git a/d2core/d2asset/palette_transform_manager.go b/d2core/d2asset/palette_transform_manager.go index 64b2e099..0cf2269f 100644 --- a/d2core/d2asset/palette_transform_manager.go +++ b/d2core/d2asset/palette_transform_manager.go @@ -1,7 +1,7 @@ package d2asset import ( - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2cache" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2pl2" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" ) @@ -15,7 +15,7 @@ const ( ) func createPaletteTransformManager() *paletteTransformManager { - return &paletteTransformManager{d2common.CreateCache(paletteTransformBudget)} + return &paletteTransformManager{d2cache.CreateCache(paletteTransformBudget)} } func (pm *paletteTransformManager) loadPaletteTransform(path string) (*d2pl2.PL2, error) { diff --git a/d2core/d2gui/layout.go b/d2core/d2gui/layout.go index b743a590..5e7433b8 100644 --- a/d2core/d2gui/layout.go +++ b/d2core/d2gui/layout.go @@ -1,7 +1,7 @@ package d2gui import ( - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2geom" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2math" ) @@ -424,7 +424,7 @@ func (l *Layout) handleEntryVerticalAlign(width int, entry *layoutEntry) { // IsIn layout entry, spc. of an event. func (l *layoutEntry) IsIn(event d2interface.HandlerEvent) bool { sx, sy := l.widget.ScreenPos() - rect := d2common.Rectangle{Left: sx, Top: sy, Width: l.width, Height: l.height} + rect := d2geom.Rectangle{Left: sx, Top: sy, Width: l.width, Height: l.height} return rect.IsInRect(event.X(), event.Y()) } diff --git a/d2core/d2item/diablo2item/item.go b/d2core/d2item/diablo2item/item.go index d0023d24..a95c5241 100644 --- a/d2core/d2item/diablo2item/item.go +++ b/d2core/d2item/diablo2item/item.go @@ -2,11 +2,11 @@ package diablo2item import ( "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2tbl" "math/rand" "sort" "strings" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2item" @@ -119,7 +119,7 @@ func (i *Item) Label() string { str := i.name if !i.attributes.identitified { - str = d2common.TranslateString(i.CommonRecord().NameString) + str = d2tbl.TranslateString(i.CommonRecord().NameString) } if i.attributes.crafted { @@ -645,16 +645,16 @@ func (i *Item) generateSetItemProperties() []*Property { func (i *Item) generateName() { if i.SetItemRecord() != nil { - i.name = d2common.TranslateString(i.SetItemRecord().SetItemKey) + i.name = d2tbl.TranslateString(i.SetItemRecord().SetItemKey) return } if i.UniqueRecord() != nil { - i.name = d2common.TranslateString(i.UniqueRecord().Name) + i.name = d2tbl.TranslateString(i.UniqueRecord().Name) return } - name := d2common.TranslateString(i.CommonRecord().NameString) + name := d2tbl.TranslateString(i.CommonRecord().NameString) numAffixes := 0 if prefixes := i.PrefixRecords(); prefixes != nil { @@ -907,46 +907,46 @@ func (i *Item) GetItemDescription() []string { if common.MinAC > 0 { min, max := common.MinAC, common.MaxAC - str = fmt.Sprintf("%s %v %s %v", d2common.TranslateString(defense), min, d2common.TranslateString(to), max) + str = fmt.Sprintf("%s %v %s %v", d2tbl.TranslateString(defense), min, d2tbl.TranslateString(to), max) str = d2ui.ColorTokenize(str, d2ui.ColorTokenWhite) lines = append(lines, str) } if common.MinDamage > 0 { min, max := common.MinDamage, common.MaxDamage - str = fmt.Sprintf("%s %v %s %v", d2common.TranslateString(damage1h), min, d2common.TranslateString(to), max) + str = fmt.Sprintf("%s %v %s %v", d2tbl.TranslateString(damage1h), min, d2tbl.TranslateString(to), max) str = d2ui.ColorTokenize(str, d2ui.ColorTokenWhite) lines = append(lines, str) } if common.Min2HandDamage > 0 { min, max := common.Min2HandDamage, common.Max2HandDamage - str = fmt.Sprintf("%s %v %s %v", d2common.TranslateString(damage2h), min, d2common.TranslateString(to), max) + str = fmt.Sprintf("%s %v %s %v", d2tbl.TranslateString(damage2h), min, d2tbl.TranslateString(to), max) str = d2ui.ColorTokenize(str, d2ui.ColorTokenWhite) lines = append(lines, str) } if common.MinMissileDamage > 0 { min, max := common.MinMissileDamage, common.MaxMissileDamage - str = fmt.Sprintf("%s %v %s %v", d2common.TranslateString(damageThrow), min, d2common.TranslateString(to), max) + str = fmt.Sprintf("%s %v %s %v", d2tbl.TranslateString(damageThrow), min, d2tbl.TranslateString(to), max) str = d2ui.ColorTokenize(str, d2ui.ColorTokenWhite) lines = append(lines, str) } if common.RequiredStrength > 1 { - str = fmt.Sprintf("%s %v", d2common.TranslateString(reqStrength), common.RequiredStrength) + str = fmt.Sprintf("%s %v", d2tbl.TranslateString(reqStrength), common.RequiredStrength) str = d2ui.ColorTokenize(str, d2ui.ColorTokenWhite) lines = append(lines, str) } if common.RequiredDexterity > 1 { - str = fmt.Sprintf("%s %v", d2common.TranslateString(reqDexterity), common.RequiredDexterity) + str = fmt.Sprintf("%s %v", d2tbl.TranslateString(reqDexterity), common.RequiredDexterity) str = d2ui.ColorTokenize(str, d2ui.ColorTokenWhite) lines = append(lines, str) } if common.RequiredLevel > 1 { - str = fmt.Sprintf("%s %v", d2common.TranslateString(reqLevel), common.RequiredLevel) + str = fmt.Sprintf("%s %v", d2tbl.TranslateString(reqLevel), common.RequiredLevel) str = d2ui.ColorTokenize(str, d2ui.ColorTokenWhite) lines = append(lines, str) } diff --git a/d2core/d2map/d2mapengine/engine.go b/d2core/d2map/d2mapengine/engine.go index f7c7bd18..0de4fe08 100644 --- a/d2core/d2map/d2mapengine/engine.go +++ b/d2core/d2map/d2mapengine/engine.go @@ -1,6 +1,7 @@ package d2mapengine import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2geom" "log" "strings" @@ -13,7 +14,6 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapstamp" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2ds1" ) @@ -23,7 +23,7 @@ type MapEngine struct { seed int64 // The map seed entities map[string]d2interface.MapEntity // Entities on the map tiles []MapTile - size d2common.Size // Size of the map, in tiles + size d2geom.Size // Size of the map, in tiles levelType d2datadict.LevelTypeRecord // Level type of this map dt1TileData []d2dt1.Tile // DT1 tile data startSubTileX int // Starting X position @@ -46,7 +46,7 @@ func (m *MapEngine) GetStartingPosition() (x, y int) { func (m *MapEngine) ResetMap(levelType d2enum.RegionIdType, width, height int) { m.entities = make(map[string]d2interface.MapEntity) m.levelType = d2datadict.LevelTypes[levelType] - m.size = d2common.Size{Width: width, Height: height} + m.size = d2geom.Size{Width: width, Height: height} m.tiles = make([]MapTile, width*height) m.dt1TileData = make([]d2dt1.Tile, 0) m.dt1Files = make([]string, 0) @@ -117,7 +117,7 @@ func (m *MapEngine) SetSeed(seed int64) { } // Size returns the size of the map in sub-tiles. -func (m *MapEngine) Size() d2common.Size { +func (m *MapEngine) Size() d2geom.Size { return m.size } diff --git a/d2core/d2map/d2mapentity/d2mapentity.go b/d2core/d2map/d2mapentity/d2mapentity.go index 7addd79a..eab1878f 100644 --- a/d2core/d2map/d2mapentity/d2mapentity.go +++ b/d2core/d2map/d2mapentity/d2mapentity.go @@ -3,9 +3,9 @@ package d2mapentity import ( "errors" "fmt" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2tbl" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset" @@ -169,7 +169,7 @@ func NewNPC(x, y int, monstat *d2datadict.MonStatsRecord, direction int) (*NPC, result.composite.SetDirection(direction) if result.monstatRecord != nil && result.monstatRecord.IsInteractable { - result.name = d2common.TranslateString(result.monstatRecord.NameString) + result.name = d2tbl.TranslateString(result.monstatRecord.NameString) } return result, nil diff --git a/d2core/d2map/d2mapentity/npc.go b/d2core/d2map/d2mapentity/npc.go index e16dcc43..f3c7c21b 100644 --- a/d2core/d2map/d2mapentity/npc.go +++ b/d2core/d2map/d2mapentity/npc.go @@ -1,9 +1,9 @@ package d2mapentity import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2path" "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/d2interface" @@ -15,7 +15,7 @@ import ( // For example, Deckard Cain. type NPC struct { mapEntity - Paths []d2common.Path + Paths []d2path.Path name string composite *d2asset.Composite action int @@ -64,12 +64,12 @@ func (v *NPC) Render(target d2interface.Surface) { } // Path returns the current part of the entity's path. -func (v *NPC) Path() d2common.Path { +func (v *NPC) Path() d2path.Path { return v.Paths[v.path] } // NextPath returns the next part of the entity's path. -func (v *NPC) NextPath() d2common.Path { +func (v *NPC) NextPath() d2path.Path { v.path++ if v.path == len(v.Paths) { v.path = 0 @@ -81,7 +81,7 @@ func (v *NPC) NextPath() d2common.Path { // SetPaths sets the entity's paths to the given slice. It also sets flags // on the entity indicating that it has paths and has completed the // previous none. -func (v *NPC) SetPaths(paths []d2common.Path) { +func (v *NPC) SetPaths(paths []d2path.Path) { v.Paths = paths v.HasPaths = len(paths) > 0 v.isDone = true diff --git a/d2core/d2map/d2mapgen/act1_overworld.go b/d2core/d2map/d2mapgen/act1_overworld.go index 4421fdfd..dcf5ef6d 100644 --- a/d2core/d2map/d2mapgen/act1_overworld.go +++ b/d2core/d2map/d2mapgen/act1_overworld.go @@ -2,11 +2,11 @@ package d2mapgen import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2geom" "log" "math/rand" "strings" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2ds1" @@ -99,7 +99,7 @@ func generateWilderness1TownEast(mapEngine *d2mapengine.MapEngine, startX, start fenceSouthEastStamp := loadPreset(mapEngine, d2wilderness.TreeBorderSouthEast, 0) fenceWestEdge := loadPreset(mapEngine, d2wilderness.TreeBoxNorthEast, 0) - areaRect := d2common.Rectangle{ + areaRect := d2geom.Rectangle{ Left: startX, Top: startY + 9, Width: levelDetails.SizeXNormal, @@ -154,7 +154,7 @@ func generateWilderness1TownSouth(mapEngine *d2mapengine.MapEngine, startX, star fenceSouthWestStamp := loadPreset(mapEngine, d2wilderness.TreeBorderSouthWest, 0) fenceWaterBorderSouthEast := loadPreset(mapEngine, d2wilderness.WaterBorderEast, 1) - areaRect := d2common.Rectangle{ + areaRect := d2geom.Rectangle{ Left: startX + 2, Top: startY, Width: levelDetails.SizeXNormal - 2, @@ -239,7 +239,7 @@ func generateWilderness1TownWest(mapEngine *d2mapengine.MapEngine, startX, start mapEngine.PlaceStamp(fenceSouthWestStamp, startX, startY+levelDetails.SizeYNormal-12) mapEngine.PlaceStamp(fenceNorthEastStamp, startX+levelDetails.SizeXNormal-9, startY-15) - areaRect := d2common.Rectangle{ + areaRect := d2geom.Rectangle{ Left: startX + 9, Top: startY - 10, Width: levelDetails.SizeXNormal - 9, @@ -248,11 +248,11 @@ func generateWilderness1TownWest(mapEngine *d2mapengine.MapEngine, startX, start generateWilderness1Contents(mapEngine, areaRect) } -func generateWilderness1Contents(mapEngine *d2mapengine.MapEngine, rect d2common.Rectangle) { +func generateWilderness1Contents(mapEngine *d2mapengine.MapEngine, rect d2geom.Rectangle) { levelDetails := d2datadict.GetLevelDetails(2) denOfEvil := loadPreset(mapEngine, d2wilderness.DenOfEvilEntrance, 0) - denOfEvilLoc := d2common.Point{ + denOfEvilLoc := d2geom.Point{ X: rect.Left + (rect.Width / 2) + rand.Intn(10), Y: rect.Top + (rect.Height / 2) + rand.Intn(10), } @@ -295,7 +295,7 @@ func generateWilderness1Contents(mapEngine *d2mapengine.MapEngine, rect d2common for numPlaced < 25 { stamp := stuff[rand.Intn(len(stuff))] - stampRect := d2common.Rectangle{ + stampRect := d2geom.Rectangle{ Left: rect.Left + rand.Intn(rect.Width) - stamp.Size().Width, Top: rect.Top + rand.Intn(rect.Height) - stamp.Size().Height, Width: stamp.Size().Width, @@ -309,7 +309,7 @@ func generateWilderness1Contents(mapEngine *d2mapengine.MapEngine, rect d2common } } -func areaEmpty(mapEngine *d2mapengine.MapEngine, rect d2common.Rectangle) bool { +func areaEmpty(mapEngine *d2mapengine.MapEngine, rect d2geom.Rectangle) bool { mapHeight := mapEngine.Size().Height mapWidth := mapEngine.Size().Width diff --git a/d2core/d2map/d2maprenderer/renderer.go b/d2core/d2map/d2maprenderer/renderer.go index e8325133..551fa1bb 100644 --- a/d2core/d2map/d2maprenderer/renderer.go +++ b/d2core/d2map/d2maprenderer/renderer.go @@ -3,11 +3,11 @@ package d2maprenderer import ( "errors" "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "image/color" "log" "math" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" @@ -431,8 +431,8 @@ func (mr *MapRenderer) renderEntityDebug(target d2interface.Surface) { yWithin := (t <= my) && (b >= my) within := xWithin && yWithin - boxLineColor := d2common.Color(magentaFullOpacity) - boxHoverColor := d2common.Color(yellowFullOpacity) + boxLineColor := d2util.Color(magentaFullOpacity) + boxHoverColor := d2util.Color(yellowFullOpacity) boxColor := boxLineColor @@ -465,14 +465,14 @@ func (mr *MapRenderer) renderEntityDebug(target d2interface.Surface) { if within { mr.viewport.PushTranslationWorld(x, y) target.PushTranslation(screenX, screenY) - target.DrawLine(offX, offY, d2common.Color(whiteHalfOpacity)) + target.DrawLine(offX, offY, d2util.Color(whiteHalfOpacity)) target.PushTranslation(offX+dbgBoxPadding, offY-dbgBoxPadding*two) target.PushTranslation(-dbgOffsetXY, -dbgOffsetXY) - target.DrawRect(dbgBoxWidth, dbgBoxHeight, d2common.Color(blackQuarterOpacity)) + target.DrawRect(dbgBoxWidth, dbgBoxHeight, d2util.Color(blackQuarterOpacity)) target.Pop() target.DrawTextf("World (%.2f, %.2f)\nVelocity (%.2f, %.2f)", x, y, vx, vy) target.Pop() - target.DrawLine(int(vx), int(vy), d2common.Color(lightGreenFullOpacity)) + target.DrawLine(int(vx), int(vy), d2util.Color(lightGreenFullOpacity)) target.Pop() mr.viewport.PopTranslation() } @@ -490,9 +490,9 @@ func (mr *MapRenderer) WorldToScreenF(x, y float64) (screenX, screenY float64) { } func (mr *MapRenderer) renderTileDebug(ax, ay, debugVisLevel int, target d2interface.Surface) { - subTileColor := d2common.Color(lightBlueQuarterOpacity) - tileColor := d2common.Color(whiteQuarterOpacity) - tileCollisionColor := d2common.Color(redQuarterOpacity) + subTileColor := d2util.Color(lightBlueQuarterOpacity) + tileColor := d2util.Color(whiteQuarterOpacity) + tileCollisionColor := d2util.Color(redQuarterOpacity) screenX1, screenY1 := mr.viewport.WorldToScreen(float64(ax), float64(ay)) screenX2, screenY2 := mr.viewport.WorldToScreen(float64(ax+1), float64(ay)) diff --git a/d2core/d2map/d2maprenderer/viewport.go b/d2core/d2map/d2maprenderer/viewport.go index 105f1fba..505d02a2 100644 --- a/d2core/d2map/d2maprenderer/viewport.go +++ b/d2core/d2map/d2maprenderer/viewport.go @@ -1,9 +1,8 @@ package d2maprenderer import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2geom" "math" - - "github.com/OpenDiablo2/OpenDiablo2/d2common" ) type worldTrans struct { @@ -22,8 +21,8 @@ const ( // Viewport is used for converting vectors between screen (pixel), orthogonal (Camera) and world (isometric) space. type Viewport struct { - defaultScreenRect d2common.Rectangle - screenRect d2common.Rectangle + defaultScreenRect d2geom.Rectangle + screenRect d2geom.Rectangle transStack []worldTrans transCurrent worldTrans camera *Camera @@ -33,13 +32,13 @@ type Viewport struct { // NewViewport creates a new Viewport with the given parameters and returns a pointer to it. func NewViewport(x, y, width, height int) *Viewport { return &Viewport{ - screenRect: d2common.Rectangle{ + screenRect: d2geom.Rectangle{ Left: x, Top: y, Width: width, Height: height, }, - defaultScreenRect: d2common.Rectangle{ + defaultScreenRect: d2geom.Rectangle{ Left: x, Top: y, Width: width, @@ -120,7 +119,7 @@ func (v *Viewport) IsTileVisible(x, y float64) bool { } // IsTileRectVisible returns false if none of the tiles rects are within the game screen. -func (v *Viewport) IsTileRectVisible(rect d2common.Rectangle) bool { +func (v *Viewport) IsTileRectVisible(rect d2geom.Rectangle) bool { left := float64((rect.Left - rect.Bottom()) * tileWidth) top := float64((rect.Left + rect.Top) * tileHeight) right := float64((rect.Right() - rect.Top) * tileWidth) diff --git a/d2core/d2map/d2mapstamp/stamp.go b/d2core/d2map/d2mapstamp/stamp.go index e6d541b8..7ab37a01 100644 --- a/d2core/d2map/d2mapstamp/stamp.go +++ b/d2core/d2map/d2mapstamp/stamp.go @@ -1,6 +1,8 @@ package d2mapstamp import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2geom" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2path" "math" "math/rand" @@ -9,7 +11,6 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapentity" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2object" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2ds1" @@ -80,8 +81,8 @@ func LoadStamp(levelType d2enum.RegionIdType, levelPreset, fileIndex int) *Stamp } // Size returns the size of the stamp in tiles. -func (mr *Stamp) Size() d2common.Size { - return d2common.Size{Width: int(mr.ds1.Width), Height: int(mr.ds1.Height)} +func (mr *Stamp) Size() d2geom.Size { + return d2geom.Size{Width: int(mr.ds1.Width), Height: int(mr.ds1.Height)} } // LevelPreset returns the level preset ID. @@ -169,8 +170,8 @@ func (mr *Stamp) Entities(tileOffsetX, tileOffsetY int) []d2interface.MapEntity return entities } -func convertPaths(tileOffsetX, tileOffsetY int, paths []d2common.Path) []d2common.Path { - result := make([]d2common.Path, len(paths)) +func convertPaths(tileOffsetX, tileOffsetY int, paths []d2path.Path) []d2path.Path { + result := make([]d2path.Path, len(paths)) for i := 0; i < len(paths); i++ { result[i].Action = paths[i].Action result[i].Position = d2vector.NewPosition( diff --git a/d2core/d2object/object.go b/d2core/d2object/object.go index 8bfb1470..71aad1c8 100644 --- a/d2core/d2object/object.go +++ b/d2core/d2object/object.go @@ -2,11 +2,11 @@ package d2object import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2tbl" "math/rand" uuid "github.com/satori/go.uuid" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" @@ -31,10 +31,10 @@ type Object struct { func CreateObject(x, y int, objectRec *d2datadict.ObjectRecord, palettePath string) (*Object, error) { locX, locY := float64(x), float64(y) entity := &Object{ - uuid: uuid.NewV4().String(), + uuid: uuid.NewV4().String(), objectRecord: objectRec, Position: d2vector.NewPosition(locX, locY), - name: d2common.TranslateString(objectRec.Name), + name: d2tbl.TranslateString(objectRec.Name), } objectType := &d2datadict.ObjectTypes[objectRec.Index] diff --git a/d2core/d2render/ebiten/ebiten_surface.go b/d2core/d2render/ebiten/ebiten_surface.go index 89daf30c..895abd3f 100644 --- a/d2core/d2render/ebiten/ebiten_surface.go +++ b/d2core/d2render/ebiten/ebiten_surface.go @@ -9,7 +9,7 @@ import ( "github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten/ebitenutil" - "github.com/OpenDiablo2/OpenDiablo2/d2common/d2debugutil" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" ) @@ -226,7 +226,7 @@ func (s *ebitenSurface) RenderSection(sfc d2interface.Surface, bound image.Recta // DrawTextf renders the string to the surface with the given format string and a set of parameters func (s *ebitenSurface) DrawTextf(format string, params ...interface{}) { str := fmt.Sprintf(format, params...) - d2debugutil.DebugPrinter.PrintAt(s.image, str, s.stateCurrent.x, s.stateCurrent.y) + d2util.DebugPrinter.PrintAt(s.image, str, s.stateCurrent.x, s.stateCurrent.y) } // DrawLine draws a line diff --git a/d2core/d2stats/diablo2stats/stat.go b/d2core/d2stats/diablo2stats/stat.go index 29fac985..37a5dc54 100644 --- a/d2core/d2stats/diablo2stats/stat.go +++ b/d2core/d2stats/diablo2stats/stat.go @@ -2,9 +2,9 @@ package diablo2stats import ( "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2tbl" "strings" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2stats" ) @@ -391,7 +391,7 @@ func (s *diablo2Stat) descFn1() string { stringTableKey = s.record.DescStrPos } - stringTableString := d2common.TranslateString(stringTableKey) + stringTableString := d2tbl.TranslateString(stringTableKey) switch descValPosition(s.record.DescVal) { case descValPrefix: @@ -420,8 +420,8 @@ func (s *diablo2Stat) descFn6() string { stringTableKey = s.record.DescStrPos } - str1 := d2common.TranslateString(stringTableKey) - str2 := d2common.TranslateString(s.record.DescStr2) + str1 := d2tbl.TranslateString(stringTableKey) + str2 := d2tbl.TranslateString(s.record.DescStr2) switch descValPosition(s.record.DescVal) { case descValPrefix: @@ -451,8 +451,8 @@ func (s *diablo2Stat) descFn9() string { stringTableKey = s.record.DescStrPos } - str1 := d2common.TranslateString(stringTableKey) - str2 := d2common.TranslateString(s.record.DescStr2) + str1 := d2tbl.TranslateString(stringTableKey) + str2 := d2tbl.TranslateString(s.record.DescStr2) switch descValPosition(s.record.DescVal) { case descValPrefix: @@ -479,7 +479,7 @@ func (s *diablo2Stat) descFn11() string { stringTableKey = s.record.DescStrPos } - str1 := d2common.TranslateString(stringTableKey) + str1 := d2tbl.TranslateString(stringTableKey) formatString := str1 @@ -522,7 +522,7 @@ func (s *diablo2Stat) descFn14() string { // `to Combat Skills` skillTabKey := classRecord.SkillStrTab[skillTabIndex] - skillTabStr := d2common.TranslateString(skillTabKey) + skillTabStr := d2tbl.TranslateString(skillTabKey) skillTabStr = strings.ReplaceAll(skillTabStr, "+%d ", "") // has a token we dont need // `(Paladin Only)` @@ -535,7 +535,7 @@ func (s *diablo2Stat) descFn15() string { chance, lvl, skill := s.values[0], s.values[1], s.values[2] // Special case, `chance to cast` format is actually in the string table! - chanceToCastStr := d2common.TranslateString(s.record.DescStrPos) + chanceToCastStr := d2tbl.TranslateString(s.record.DescStrPos) return fmt.Sprintf(chanceToCastStr, chance.Int(), lvl.Int(), skill) } @@ -544,14 +544,14 @@ func (s *diablo2Stat) descFn16() string { skillLevel, skillIndex := s.values[0], s.values[1] // Special case, `Level # XYZ Aura When Equipped`, format is actually in the string table! - format := d2common.TranslateString(s.record.DescStrPos) + format := d2tbl.TranslateString(s.record.DescStrPos) return fmt.Sprintf(format, skillLevel.Int(), skillIndex) } func (s *diablo2Stat) descFn22() string { arBonus, monsterIndex := s.values[0], s.values[1] - arVersus := d2common.TranslateString(s.record.DescStrPos) + arVersus := d2tbl.TranslateString(s.record.DescStrPos) return fmt.Sprintf(threeComponentStr, arBonus, arVersus, monsterIndex) } @@ -565,7 +565,7 @@ func (s *diablo2Stat) descFn24() string { s.values[2].Int(), s.values[3].Int() - chargeStr := d2common.TranslateString(s.record.DescStrPos) + chargeStr := d2tbl.TranslateString(s.record.DescStrPos) chargeStr = fmt.Sprintf(chargeStr, chargeCurrent, chargeMax) return fmt.Sprintf(format, lvl, skill, chargeStr) diff --git a/d2core/d2stats/diablo2stats/stat_value_stringers.go b/d2core/d2stats/diablo2stats/stat_value_stringers.go index 0603e836..051f39c9 100644 --- a/d2core/d2stats/diablo2stats/stat_value_stringers.go +++ b/d2core/d2stats/diablo2stats/stat_value_stringers.go @@ -2,8 +2,8 @@ package diablo2stats import ( "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2tbl" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2stats" @@ -55,7 +55,7 @@ func stringerClassAllSkills(sv d2stats.StatValue) string { heroMap := getHeroMap() classRecord := d2datadict.CharStats[heroMap[heroIndex]] - return d2common.TranslateString(classRecord.SkillStrAll) + return d2tbl.TranslateString(classRecord.SkillStrAll) } func stringerClassOnly(sv d2stats.StatValue) string { @@ -64,7 +64,7 @@ func stringerClassOnly(sv d2stats.StatValue) string { classRecord := d2datadict.CharStats[heroMap[heroIndex]] classOnlyKey := classRecord.SkillStrClassOnly - return d2common.TranslateString(classOnlyKey) + return d2tbl.TranslateString(classOnlyKey) } func stringerSkillName(sv d2stats.StatValue) string { diff --git a/d2core/d2ui/button.go b/d2core/d2ui/button.go index 3c283a8c..ba4a662d 100644 --- a/d2core/d2ui/button.go +++ b/d2core/d2ui/button.go @@ -2,9 +2,9 @@ package d2ui import ( "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "image" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" @@ -190,7 +190,7 @@ func (ui *UIManager) NewButton(buttonType ButtonType, text string) *Button { lbl := ui.NewLabel(buttonLayout.FontPath, d2resource.PaletteUnits) lbl.SetText(text) - lbl.Color[0] = d2common.Color(greyAlpha100) + lbl.Color[0] = d2util.Color(greyAlpha100) lbl.Alignment = d2gui.HorizontalAlignCenter animation, _ := d2asset.LoadAnimation(buttonLayout.ResourceName, buttonLayout.PaletteName) @@ -333,7 +333,7 @@ func (v *Button) Render(target d2interface.Surface) error { switch { case !v.enabled: - target.PushColor(d2common.Color(lightGreyAlpha75)) + target.PushColor(d2util.Color(lightGreyAlpha75)) defer target.Pop() err = target.Render(v.disabledSurface) case v.toggled && v.pressed: diff --git a/d2core/d2ui/label.go b/d2core/d2ui/label.go index 32d57051..46cd2291 100644 --- a/d2core/d2ui/label.go +++ b/d2core/d2ui/label.go @@ -1,12 +1,12 @@ package d2ui import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "image/color" "log" "regexp" "strings" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui" @@ -166,15 +166,15 @@ func (v *Label) getAlignOffset(textWidth int) int { func getColor(token ColorToken) color.Color { // todo this should really come from the PL2 files colors := map[ColorToken]color.Color{ - ColorTokenGrey: d2common.Color(colorGrey100Alpha), - ColorTokenWhite: d2common.Color(colorWhite100Alpha), - ColorTokenBlue: d2common.Color(colorBlue100Alpha), - ColorTokenYellow: d2common.Color(colorYellow100Alpha), - ColorTokenGreen: d2common.Color(colorGreen100Alpha), - ColorTokenGold: d2common.Color(colorGold100Alpha), - ColorTokenOrange: d2common.Color(colorOrange100Alpha), - ColorTokenRed: d2common.Color(colorRed100Alpha), - ColorTokenBlack: d2common.Color(colorBlack100Alpha), + ColorTokenGrey: d2util.Color(colorGrey100Alpha), + ColorTokenWhite: d2util.Color(colorWhite100Alpha), + ColorTokenBlue: d2util.Color(colorBlue100Alpha), + ColorTokenYellow: d2util.Color(colorYellow100Alpha), + ColorTokenGreen: d2util.Color(colorGreen100Alpha), + ColorTokenGold: d2util.Color(colorGold100Alpha), + ColorTokenOrange: d2util.Color(colorOrange100Alpha), + ColorTokenRed: d2util.Color(colorRed100Alpha), + ColorTokenBlack: d2util.Color(colorBlack100Alpha), } chosen := colors[token] diff --git a/d2game/d2gamescreen/credits.go b/d2game/d2gamescreen/credits.go index 3c04fec3..591e7c71 100644 --- a/d2game/d2gamescreen/credits.go +++ b/d2game/d2gamescreen/credits.go @@ -3,12 +3,12 @@ package d2gamescreen import ( "bufio" "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "log" "os" "path" "strings" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset" @@ -104,7 +104,7 @@ func (v *Credits) OnLoad(loading d2screen.LoadingState) { loading.Progress(sixtyPercent) - creditData, _ := d2common.Utf16BytesToString(fileData[2:]) + creditData, _ := d2util.Utf16BytesToString(fileData[2:]) v.creditsText = strings.Split(creditData, "\r\n") for i := range v.creditsText { diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index fa4ddaf8..5df807bb 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -3,12 +3,12 @@ package d2gamescreen import ( "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2tbl" "log" "os" "os/exec" "runtime" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource" @@ -281,7 +281,7 @@ func (v *MainMenu) createButtons(loading d2screen.LoadingState) { v.mapTestButton.OnActivated(func() { v.onMapTestClicked() }) v.btnTCPIPCancel = v.uiManager.NewButton(d2ui.ButtonTypeMedium, - d2common.TranslateString("cancel")) + d2tbl.TranslateString("cancel")) v.btnTCPIPCancel.SetPosition(tcpBtnX, tcpBtnY) v.btnTCPIPCancel.OnActivated(func() { v.onTCPIPCancelClicked() }) @@ -307,7 +307,7 @@ func (v *MainMenu) createMultiplayerMenuButtons() { v.networkTCPIPButton.OnActivated(func() { v.onNetworkTCPIPClicked() }) v.networkCancelButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, - d2common.TranslateString("cancel")) + d2tbl.TranslateString("cancel")) v.networkCancelButton.SetPosition(networkCancelBtnX, networkCancelBtnY) v.networkCancelButton.OnActivated(func() { v.onNetworkCancelClicked() }) diff --git a/d2game/d2gamescreen/map_engine_testing.go b/d2game/d2gamescreen/map_engine_testing.go index 2df44a95..3f64a1e5 100644 --- a/d2game/d2gamescreen/map_engine_testing.go +++ b/d2game/d2gamescreen/map_engine_testing.go @@ -2,13 +2,12 @@ package d2gamescreen import ( "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource" "log" "os" "strings" "time" - "github.com/OpenDiablo2/OpenDiablo2/d2common" - "github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapgen" @@ -181,7 +180,7 @@ func (met *MapEngineTest) loadRegionByIndex(n, levelPreset, fileIndex int) { position := d2vector.NewPosition(met.mapRenderer.WorldToOrtho(met.mapEngine.GetCenterPosition())) met.mapRenderer.SetCameraPosition(&position) - musicDef := d2common.GetMusicDef(met.regionSpec.regionType) + musicDef := d2resource.GetMusicDef(met.regionSpec.regionType) met.audioProvider.PlayBGM(musicDef.MusicFile) } diff --git a/d2game/d2gamescreen/select_hero_class.go b/d2game/d2gamescreen/select_hero_class.go index 11867194..35db81dd 100644 --- a/d2game/d2gamescreen/select_hero_class.go +++ b/d2game/d2gamescreen/select_hero_class.go @@ -2,9 +2,10 @@ package d2gamescreen import ( "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2tbl" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "image" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" @@ -650,25 +651,25 @@ func (v *SelectHeroClass) updateHeroText() { case d2enum.HeroNone: return case d2enum.HeroBarbarian: - v.heroClassLabel.SetText(d2common.TranslateString("partycharbar")) + v.heroClassLabel.SetText(d2tbl.TranslateString("partycharbar")) v.setDescLabels("He is unequaled in close-quarters combat and mastery of weapons.") case d2enum.HeroNecromancer: - v.heroClassLabel.SetText(d2common.TranslateString("partycharnec")) + v.heroClassLabel.SetText(d2tbl.TranslateString("partycharnec")) v.setDescLabels("Summoning undead minions and cursing his enemies are his specialties.") case d2enum.HeroPaladin: - v.heroClassLabel.SetText(d2common.TranslateString("partycharpal")) + v.heroClassLabel.SetText(d2tbl.TranslateString("partycharpal")) v.setDescLabels("He is a natural party leader, holy man, and blessed warrior.") case d2enum.HeroAssassin: - v.heroClassLabel.SetText(d2common.TranslateString("partycharass")) + v.heroClassLabel.SetText(d2tbl.TranslateString("partycharass")) v.setDescLabels("Schooled in the Martial Arts, her mind and body are deadly weapons.") case d2enum.HeroSorceress: - v.heroClassLabel.SetText(d2common.TranslateString("partycharsor")) + v.heroClassLabel.SetText(d2tbl.TranslateString("partycharsor")) v.setDescLabels("She has mastered the elemental magicks -- fire, lightning, and ice.") case d2enum.HeroAmazon: - v.heroClassLabel.SetText(d2common.TranslateString("partycharama")) + v.heroClassLabel.SetText(d2tbl.TranslateString("partycharama")) v.setDescLabels("Skilled with the spear and the bow, she is a very versatile fighter.") case d2enum.HeroDruid: - v.heroClassLabel.SetText(d2common.TranslateString("partychardru")) + v.heroClassLabel.SetText(d2tbl.TranslateString("partychardru")) v.setDescLabels("Commanding the forces of nature, he summons wild beasts and raging storms to his side.") } } @@ -679,8 +680,8 @@ const ( ) func (v *SelectHeroClass) setDescLabels(descKey string) { - heroDesc := d2common.TranslateString(descKey) - parts := d2common.SplitIntoLinesWithMaxWidth(heroDesc, heroDescCharWidth) + heroDesc := d2tbl.TranslateString(descKey) + parts := d2util.SplitIntoLinesWithMaxWidth(heroDesc, heroDescCharWidth) numLines := len(parts) diff --git a/d2game/d2player/game_controls.go b/d2game/d2player/game_controls.go index 3ae31070..5a2df5de 100644 --- a/d2game/d2player/game_controls.go +++ b/d2game/d2player/game_controls.go @@ -2,6 +2,8 @@ package d2player import ( "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2geom" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "image" "image/color" "log" @@ -13,7 +15,6 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui" - "github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset" @@ -78,7 +79,7 @@ type ActionableType int type ActionableRegion struct { ActionableTypeId ActionableType - Rect d2common.Rectangle + Rect d2geom.Rectangle } const ( @@ -171,18 +172,18 @@ func NewGameControls( zoneChangeText: zoneLabel, hpManaStatsLabel: globeStatsLabel, actionableRegions: []ActionableRegion{ - {leftSkill, d2common.Rectangle{Left: 115, Top: 550, Width: 50, Height: 50}}, - {leftSelect, d2common.Rectangle{Left: 206, Top: 563, Width: 30, Height: 30}}, - {xp, d2common.Rectangle{Left: 253, Top: 560, Width: 125, Height: 5}}, - {walkRun, d2common.Rectangle{Left: 255, Top: 573, Width: 17, Height: 20}}, - {stamina, d2common.Rectangle{Left: 273, Top: 573, Width: 105, Height: 20}}, - {miniPnl, d2common.Rectangle{Left: 393, Top: 563, Width: 12, Height: 23}}, - {rightSelect, d2common.Rectangle{Left: 562, Top: 563, Width: 30, Height: 30}}, - {rightSkill, d2common.Rectangle{Left: 634, Top: 550, Width: 50, Height: 50}}, - {hpGlobe, d2common.Rectangle{Left: 30, Top: 525, Width: 65, Height: 50}}, - {manaGlobe, d2common.Rectangle{Left: 700, Top: 525, Width: 65, Height: 50}}, - {miniPanelCharacter, d2common.Rectangle{Left: 325, Top: 526, Width: 26, Height: 26}}, - {miniPanelInventory, d2common.Rectangle{Left: 351, Top: 526, Width: 26, Height: 26}}, + {leftSkill, d2geom.Rectangle{Left: 115, Top: 550, Width: 50, Height: 50}}, + {leftSelect, d2geom.Rectangle{Left: 206, Top: 563, Width: 30, Height: 30}}, + {xp, d2geom.Rectangle{Left: 253, Top: 560, Width: 125, Height: 5}}, + {walkRun, d2geom.Rectangle{Left: 255, Top: 573, Width: 17, Height: 20}}, + {stamina, d2geom.Rectangle{Left: 273, Top: 573, Width: 105, Height: 20}}, + {miniPnl, d2geom.Rectangle{Left: 393, Top: 563, Width: 12, Height: 23}}, + {rightSelect, d2geom.Rectangle{Left: 562, Top: 563, Width: 30, Height: 30}}, + {rightSkill, d2geom.Rectangle{Left: 634, Top: 550, Width: 50, Height: 50}}, + {hpGlobe, d2geom.Rectangle{Left: 30, Top: 525, Width: 65, Height: 50}}, + {manaGlobe, d2geom.Rectangle{Left: 700, Top: 525, Width: 65, Height: 50}}, + {miniPanelCharacter, d2geom.Rectangle{Left: 325, Top: 526, Width: 26, Height: 26}}, + {miniPanelInventory, d2geom.Rectangle{Left: 351, Top: 526, Width: 26, Height: 26}}, }, lastLeftBtnActionTime: 0, lastRightBtnActionTime: 0, @@ -272,7 +273,7 @@ func (g *GameControls) OnMouseButtonRepeat(event d2interface.MouseEvent) bool { px = float64(int(px*10)) / 10.0 py = float64(int(py*10)) / 10.0 - now := d2common.Now() + now := d2util.Now() button := event.Button() isLeft := button == d2enum.MouseButtonLeft isRight := button == d2enum.MouseButtonRight @@ -350,7 +351,7 @@ func (g *GameControls) OnMouseButtonDown(event d2interface.MouseEvent) bool { py = float64(int(py*10)) / 10.0 if event.Button() == d2enum.MouseButtonLeft && !g.isInActiveMenusRect(mx, my) { - g.lastLeftBtnActionTime = d2common.Now() + g.lastLeftBtnActionTime = d2util.Now() g.inputListener.OnPlayerMove(px, py) @@ -358,7 +359,7 @@ func (g *GameControls) OnMouseButtonDown(event d2interface.MouseEvent) bool { } if event.Button() == d2enum.MouseButtonRight && !g.isInActiveMenusRect(mx, my) { - g.lastRightBtnActionTime = d2common.Now() + g.lastRightBtnActionTime = d2util.Now() g.inputListener.OnPlayerCast(g.missileID, px, py) @@ -442,11 +443,11 @@ func (g *GameControls) isRightPanelOpen() bool { } func (g *GameControls) isInActiveMenusRect(px, py int) bool { - var bottomMenuRect = d2common.Rectangle{Left: 0, Top: 550, Width: 800, Height: 50} + var bottomMenuRect = d2geom.Rectangle{Left: 0, Top: 550, Width: 800, Height: 50} - var leftMenuRect = d2common.Rectangle{Left: 0, Top: 0, Width: 400, Height: 600} + var leftMenuRect = d2geom.Rectangle{Left: 0, Top: 0, Width: 400, Height: 600} - var rightMenuRect = d2common.Rectangle{Left: 400, Top: 0, Width: 400, Height: 600} + var rightMenuRect = d2geom.Rectangle{Left: 400, Top: 0, Width: 400, Height: 600} if bottomMenuRect.IsInRect(px, py) { return true diff --git a/d2game/d2player/mini_panel.go b/d2game/d2player/mini_panel.go index acc839f2..3a06c033 100644 --- a/d2game/d2player/mini_panel.go +++ b/d2game/d2player/mini_panel.go @@ -1,7 +1,7 @@ package d2player import ( - "github.com/OpenDiablo2/OpenDiablo2/d2common" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2geom" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset" @@ -13,7 +13,7 @@ type miniPanel struct { button *d2ui.Sprite isOpen bool isSinglePlayer bool - rectangle d2common.Rectangle + rectangle d2geom.Rectangle } func newMiniPanel(uiManager *d2ui.UIManager, isSinglePlayer bool) *miniPanel { @@ -27,7 +27,7 @@ func newMiniPanel(uiManager *d2ui.UIManager, isSinglePlayer bool) *miniPanel { animation, _ = d2asset.LoadAnimation(d2resource.MinipanelButton, d2resource.PaletteSky) buttonSprite, _ := uiManager.NewSprite(animation) - rectangle := d2common.Rectangle{Left: 325, Top: 526, Width: 156, Height: 26} + rectangle := d2geom.Rectangle{Left: 325, Top: 526, Width: 156, Height: 26} if !isSinglePlayer { rectangle.Width = 182