From d4ec09db6c6b679c9611df82cec6127ad4605b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrkan=20Kaymak?= <7164005+gurkankaymak@users.noreply.github.com> Date: Wed, 24 Jun 2020 21:42:39 +0300 Subject: [PATCH] added a startup error screen shown when the mpq files are not found (#442) --- main.go | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index c610068c..fe350270 100644 --- a/main.go +++ b/main.go @@ -64,12 +64,6 @@ var singleton struct { } func main() { - if len(GitBranch) == 0 { - GitBranch = "Local Build" - } - - d2common.SetBuildInfo(GitBranch, GitCommit) - region := kingpin.Arg("region", "Region type id").Int() preset := kingpin.Arg("preset", "Level preset").Int() profileOption := kingpin.Flag("profile", "Profiles the program, one of (cpu, mem, block, goroutine, trace, thread, mutex)").String() @@ -80,6 +74,9 @@ func main() { log.Println("OpenDiablo2 - Open source Diablo 2 engine") if err := initialize(); err != nil { + if os.IsNotExist(err) { + run(updateInitError) + } log.Fatal(err) } @@ -96,10 +93,7 @@ func main() { d2screen.SetNextScreen(d2gamescreen.CreateMapEngineTest(*region, *preset)) } - windowTitle := fmt.Sprintf("OpenDiablo2 (%s)", GitBranch) - if err := d2render.Run(update, 800, 600, windowTitle); err != nil { - log.Fatal(err) - } + run(update) } func initialize() error { @@ -214,6 +208,17 @@ func initialize() error { return nil } +func run(updateFunc func(d2render.Surface) error) { + if len(GitBranch) == 0 { + GitBranch = "Local Build" + } + d2common.SetBuildInfo(GitBranch, GitCommit) + windowTitle := fmt.Sprintf("OpenDiablo2 (%s)", GitBranch) + if err := d2render.Run(updateFunc, 800, 600, windowTitle); err != nil { + log.Fatal(err) + } +} + func update(target d2render.Surface) error { currentTime := d2common.Now() elapsedTime := (currentTime - singleton.lastTime) * singleton.timeScale @@ -234,6 +239,13 @@ func update(target d2render.Surface) error { return nil } +func updateInitError(target d2render.Surface) error { + width, height := target.GetSize() + target.PushTranslation(width/5, height/2) + target.DrawText("Could not find the MPQ files in the directory: %s\nPlease put the files and re-run the game.", d2config.Get().MpqPath) + return nil +} + const FPS_25 = 0.04 // 1/25 func advance(elapsed, current float64) error {