From 73804519b033ab994aba7919a34233c4b686b339 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Sat, 13 Oct 2018 03:24:10 +0100 Subject: [PATCH] Beginnings of a WH40K.EXE implementation So far, we just play the opening credits on an external video player. I want to start loading and displaying the menus next. Perhaps I can get the entire non-gameplay flow working? --- .gitignore | 1 + Makefile | 5 ++++- cmd/wh40k/main.go | 18 +++++++++++++++++- internal/wh40k/videos.go | 36 ++++++++++++++++++++++++++++++++++++ internal/wh40k/wh40k.go | 30 ++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 internal/wh40k/videos.go create mode 100644 internal/wh40k/wh40k.go diff --git a/.gitignore b/.gitignore index 8bb6dc8..64aa390 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /view-map /view-minimap /view-set +/wh40k diff --git a/Makefile b/Makefile index a73b208..9097cc6 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,10 @@ view-minimap: $(srcfiles) view-set: $(srcfiles) go build -o view-set ur.gs/ordoor/cmd/view-set +wh40k: $(srcfiles) + go build -o wh40k ur.gs/ordoor/cmd/wh40k + clean: - rm -f loader view-obj view-map view-minimap view-set + rm -f loader view-obj view-map view-minimap view-set wh40k .PHONY: all clean diff --git a/cmd/wh40k/main.go b/cmd/wh40k/main.go index 7905807..6a0cb63 100644 --- a/cmd/wh40k/main.go +++ b/cmd/wh40k/main.go @@ -1,5 +1,21 @@ package main -func main() { +import ( + "log" + "os" + "ur.gs/ordoor/internal/wh40k" +) + +func main() { + configFile := "config.toml" + if len(os.Args) == 2 { + configFile = os.Args[1] + } + + if err := wh40k.Run(configFile); err != nil { + log.Fatalf(err.Error()) + } + + os.Exit(0) } diff --git a/internal/wh40k/videos.go b/internal/wh40k/videos.go new file mode 100644 index 0000000..0cd9e0b --- /dev/null +++ b/internal/wh40k/videos.go @@ -0,0 +1,36 @@ +package wh40k + +import ( + "log" + "os/exec" +) + +func (w *WH40K) PlayVideo(name string, skippable bool) { + // TODO: allow the video to be skipped by pressing the ESC key or so. For + // now, skip unconditionally + if skippable { + log.Printf("TODO: Make videos conditionally skippable") + return + } + + filename := w.Config.DataFile("SMK/" + name + ".smk") + + if len(w.Config.VideoPlayer) == 0 { + log.Printf("Video player not configured, skipping video %v", filename) + return + } + + argc := w.Config.VideoPlayer[0] + argv := append(w.Config.VideoPlayer[1:], filename) + if err := exec.Command(argc, argv...).Run(); err != nil { + log.Printf("Error playing video %v: %v", filename, err) + } +} + +func (w *WH40K) PlayUnskippableVideo(name string) { + w.PlayVideo(name, false) +} + +func (w *WH40K) PlaySkippableVideo(name string) { + w.PlayVideo(name, true) +} diff --git a/internal/wh40k/wh40k.go b/internal/wh40k/wh40k.go new file mode 100644 index 0000000..01f6d15 --- /dev/null +++ b/internal/wh40k/wh40k.go @@ -0,0 +1,30 @@ +// package wh40k implements the full WH40K.EXE functionality, and is used from +// cmd/wh40k/main.go +// +// Entrypoint is Run() +package wh40k + +import ( + "fmt" + + "ur.gs/ordoor/internal/config" +) + +type WH40K struct { + Config *config.Config +} + +func Run(configFile string) error { + cfg, err := config.Load(configFile) + if err != nil { + return fmt.Errorf("Couldn't load config file: %v", err) + } + + wh40k := &WH40K{ + Config: cfg, + } + + wh40k.PlayUnskippableVideo("LOGOS") + + return nil +}