1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-12-25 11:36:26 -05:00

error handling in d2gamescreen.CreateNewGame

This commit is contained in:
M. Sz 2020-12-11 10:26:49 +01:00
parent 509dfda5e5
commit 8f1aadc223
2 changed files with 11 additions and 5 deletions

View File

@ -943,9 +943,14 @@ func (a *App) ToCreateGame(filePath string, connType d2clientconnectiontype.Clie
fmt.Println(errorMessage)
a.ToMainMenu(errorMessage)
} else {
a.screen.SetNextScreen(d2gamescreen.CreateGame(
game, err := d2gamescreen.CreateGame(
a, a.asset, a.ui, a.renderer, a.inputManager, a.audio, gameClient, a.terminal, a.config.LogLevel, a.guiManager,
))
)
if err != nil {
a.Error(err.Error())
}
a.screen.SetNextScreen(game)
}
}

View File

@ -1,6 +1,7 @@
package d2gamescreen
import (
"errors"
"fmt"
"image/color"
@ -47,7 +48,7 @@ func CreateGame(
term d2interface.Terminal,
l d2util.LogLevel,
guiManager *d2gui.GuiManager,
) *Game {
) (*Game, error) {
// find the local player and its initial location
var startX, startY float64
@ -93,10 +94,10 @@ func CreateGame(
game.escapeMenu.OnLoad()
if err := inputManager.BindHandler(game.escapeMenu); err != nil {
game.Error("failed to add gameplay screen as event handler")
return nil, errors.New("failed to add gameplay screen as event handler")
}
return game
return game, nil
}
// Game represents the Gameplay screen