Skip to content

Commit

Permalink
fix few issues and panic
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorgimenez committed May 1, 2024
1 parent 8a642b1 commit b4d9370
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
36 changes: 17 additions & 19 deletions internal/action/leveling_tools.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package action

import (
"github.com/hectorgimenez/koolo/internal/game"
"github.com/hectorgimenez/koolo/internal/pather"
"github.com/lxn/win"
"log/slog"
"slices"
"time"

"github.com/hectorgimenez/koolo/internal/game"
"github.com/hectorgimenez/koolo/internal/pather"
"github.com/lxn/win"

"github.com/hectorgimenez/d2go/pkg/data"
"github.com/hectorgimenez/d2go/pkg/data/area"
"github.com/hectorgimenez/d2go/pkg/data/difficulty"
Expand Down Expand Up @@ -276,14 +277,12 @@ func (b *Builder) calculateSkillPositionInUI(d game.Data, mainSkill bool, skillI
}
descs[skID] = sk

// Main skill list grows to the left, secondary skill list grows to the right
displaceSkill := targetSkill.ID < skID
if mainSkill {
displaceSkill = targetSkill.ID > skID
}

if skID != targetSkill.ID && sk.Desc().ListRow == targetSkill.Desc().ListRow && displaceSkill {
column++
if skID != targetSkill.ID && sk.Desc().Page == targetSkill.Desc().Page {
if sk.Desc().ListRow > targetSkill.Desc().ListRow {
column++
} else if sk.Desc().ListRow == targetSkill.Desc().ListRow && sk.Desc().Column > targetSkill.Desc().Column {
column++
}
}

totalRows = append(totalRows, sk.Desc().ListRow)
Expand All @@ -298,12 +297,11 @@ func (b *Builder) calculateSkillPositionInUI(d game.Data, mainSkill bool, skillI
totalRows = slices.Compact(totalRows)

// If we don't have any skill of a specific tree, the entire row gets one line down
previousRow := 0
for _, currentRow := range totalRows {
if currentRow != 0 && currentRow != previousRow+1 {
row--
for i, currentRow := range totalRows {
if currentRow == row {
row = i
break
}
previousRow = currentRow
}

// Scrolls and charges are not in the same list
Expand All @@ -320,13 +318,13 @@ func (b *Builder) calculateSkillPositionInUI(d game.Data, mainSkill bool, skillI
}
}

skillOffsetX := ui.MainSkillListFirstSkillX
skillOffsetX := ui.MainSkillListFirstSkillX - (ui.SkillListSkillOffset * column)
if !mainSkill {
skillOffsetX = ui.SecondarySkillListFirstSkillX
skillOffsetX = ui.SecondarySkillListFirstSkillX + (ui.SkillListSkillOffset * column)
}

return data.Position{
X: skillOffsetX + ui.SkillListSkillOffset*column,
X: skillOffsetX,
Y: ui.SkillListFirstSkillY - ui.SkillListSkillOffset*row,
}, true
}
Expand Down
14 changes: 8 additions & 6 deletions internal/game/keyboard.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package game

import (
"github.com/hectorgimenez/d2go/pkg/data"
"github.com/inkeliz/w32"
"github.com/lxn/win"
"math/rand"
"strings"
"time"

"github.com/hectorgimenez/d2go/pkg/data"
"github.com/inkeliz/w32"
"github.com/lxn/win"
)

const (
Expand Down Expand Up @@ -60,11 +61,12 @@ func getKeysForKB(kb data.KeyBinding) [2]byte {
}

func (hid *HID) GetASCIICode(key string) byte {
if len(key) == 1 {
return strings.ToUpper(key)[0]
char, found := specialChars[strings.ToLower(key)]
if found {
return char
}

return specialChars[strings.ToLower(key)]
return strings.ToUpper(key)[0]
}

var specialChars = map[string]byte{
Expand Down
8 changes: 7 additions & 1 deletion internal/pather/path_finding_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package pather

import (
"fmt"
"github.com/hectorgimenez/koolo/internal/game"
"image"
"image/color"
"image/draw"
"image/png"
"math"
"os"

"github.com/hectorgimenez/koolo/internal/game"

"github.com/beefsack/go-astar"
"github.com/hectorgimenez/d2go/pkg/data"
"github.com/hectorgimenez/d2go/pkg/data/area"
Expand Down Expand Up @@ -197,5 +198,10 @@ func IsWalkable(pos data.Position, areaOriginPos data.Position, collisionGrid []
indexX := pos.X - areaOriginPos.X
indexY := pos.Y - areaOriginPos.Y

// When we are close to the level border, we need to check if monster is outside the collision grid
if indexX < 0 || indexY < 0 || indexY >= len(collisionGrid) || indexX >= len(collisionGrid[indexY]) {
return false
}

return collisionGrid[indexY][indexX]
}
2 changes: 1 addition & 1 deletion internal/ui/coordinates.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
GambleRefreshButtonY = 515

SecondarySkillListFirstSkillX = 687
MainSkillListFirstSkillX = 550
MainSkillListFirstSkillX = 592
SkillListFirstSkillY = 590
SkillListSkillOffset = 45

Expand Down

0 comments on commit b4d9370

Please sign in to comment.