mirror of
https://github.com/wisplite/a-star-go.git
synced 2026-06-27 15:37:07 -05:00
add error box to prevent an occasional panic when the start or end pos wasn't set right
This commit is contained in:
@@ -290,6 +290,7 @@ func main() {
|
||||
editModeWidth := false
|
||||
editModeHeight := false
|
||||
generateGridError := false
|
||||
posError := false
|
||||
|
||||
toolOptions := []string{"Wall", "Start", "End", "Erase"}
|
||||
toolOptionsText := strings.Join(toolOptions, ";")
|
||||
@@ -467,6 +468,13 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
if posError {
|
||||
result := rg.MessageBox(rl.NewRectangle(screenWidth/2-(100*scale), screenHeight/2-(40*scale), (200*scale), (120*scale)), "Error", "Start and end positions must be\nwithin the generated grid", "OK")
|
||||
if result >= 0 {
|
||||
posError = false
|
||||
}
|
||||
}
|
||||
|
||||
// Generate Grid Button
|
||||
if rg.Button(rl.NewRectangle(sidebarX+(10*scale), (40*scale), (180*scale), (30*scale)), "Generate Grid") {
|
||||
width, _ = strconv.Atoi(widthInputValue)
|
||||
@@ -521,6 +529,9 @@ func main() {
|
||||
|
||||
// Calculate Path Button
|
||||
if rg.Button(rl.NewRectangle(sidebarX+(10*scale), (screenHeight-(40*scale)), (180*scale), (30*scale)), "Calculate Path") {
|
||||
if int(startPos.X) < 0 || int(startPos.X) >= width || int(startPos.Y) < 0 || int(startPos.Y) >= height || int(endPos.X) < 0 || int(endPos.X) >= width || int(endPos.Y) < 0 || int(endPos.Y) >= height {
|
||||
posError = true
|
||||
} else {
|
||||
astar.ResetGrid(false) // keep grid types, otherwise it will delete the board before simulating
|
||||
astar.SetHeuristic(activeHeuristic)
|
||||
gridTypes := astar.GetGridTypes()
|
||||
@@ -555,6 +566,7 @@ func main() {
|
||||
}
|
||||
tex.markFull()
|
||||
}
|
||||
}
|
||||
|
||||
// Status Label
|
||||
rg.Label(rl.NewRectangle((10*scale), (screenHeight-(30*scale)), (180*scale), (30*scale)), "Evaluated "+strconv.Itoa(astar.GetEvaluatedCells())+" cells in "+astar.GetTimeTaken().String())
|
||||
|
||||
Reference in New Issue
Block a user