added a startup error screen shown when the mpq files are not found (#442)

This commit is contained in:
Gürkan Kaymak 2020-06-24 21:42:39 +03:00 committed by GitHub
parent d8a817eddf
commit d4ec09db6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 10 deletions

32
main.go
View File

@ -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 {