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
|
editModeWidth := false
|
||||||
editModeHeight := false
|
editModeHeight := false
|
||||||
generateGridError := false
|
generateGridError := false
|
||||||
|
posError := false
|
||||||
|
|
||||||
toolOptions := []string{"Wall", "Start", "End", "Erase"}
|
toolOptions := []string{"Wall", "Start", "End", "Erase"}
|
||||||
toolOptionsText := strings.Join(toolOptions, ";")
|
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
|
// Generate Grid Button
|
||||||
if rg.Button(rl.NewRectangle(sidebarX+(10*scale), (40*scale), (180*scale), (30*scale)), "Generate Grid") {
|
if rg.Button(rl.NewRectangle(sidebarX+(10*scale), (40*scale), (180*scale), (30*scale)), "Generate Grid") {
|
||||||
width, _ = strconv.Atoi(widthInputValue)
|
width, _ = strconv.Atoi(widthInputValue)
|
||||||
@@ -521,6 +529,9 @@ func main() {
|
|||||||
|
|
||||||
// Calculate Path Button
|
// Calculate Path Button
|
||||||
if rg.Button(rl.NewRectangle(sidebarX+(10*scale), (screenHeight-(40*scale)), (180*scale), (30*scale)), "Calculate Path") {
|
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.ResetGrid(false) // keep grid types, otherwise it will delete the board before simulating
|
||||||
astar.SetHeuristic(activeHeuristic)
|
astar.SetHeuristic(activeHeuristic)
|
||||||
gridTypes := astar.GetGridTypes()
|
gridTypes := astar.GetGridTypes()
|
||||||
@@ -555,6 +566,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
tex.markFull()
|
tex.markFull()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Status Label
|
// 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())
|
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