laneya2

cave exploration game
git clone https://git.ce9e.org/laneya2.git

commit
7a7b5bee1133bd39a89337c6b09e279184808659
parent
3e693ef5041a924e27e3a98e0b2d25f7463d6926
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-10-05 10:03
dump items to file in production

Diffstat

M Makefile 1 +
M server.go 11 ++++++++++-
M static/main.js 2 +-

3 files changed, 12 insertions, 2 deletions


diff --git a/Makefile b/Makefile

@@ -21,3 +21,4 @@ install:
   21    21 	install -Dm 644 static/dpad.js "${DESTDIR}/var/www/laneya/static/dpad.js"
   22    22 	install -Dm 644 static/style.css "${DESTDIR}/var/www/laneya/static/style.css"
   23    23 	install -Dm 644 README.md "${DESTDIR}/usr/share/doc/laneya/README.md"
   -1    24 	./server --dump-items > "${DESTDIR}/var/www/laneya/items.json"

diff --git a/server.go b/server.go

@@ -154,15 +154,24 @@ func serve(addr string) {
  154   154 }
  155   155 
  156   156 func main() {
   -1   157 	dumpItems := false
   -1   158 
  157   159 	flag.Usage = func() {
  158   160 		fmt.Fprintf(os.Stderr, "laneya [-v] [-s] [port]\n")
   -1   161 		fmt.Fprintf(os.Stderr, "laneya [-v] [-s] [--dump-items] [port]\n")
  159   162 		flag.PrintDefaults()
  160   163 	}
  161   164 
  162   165 	flag.BoolVar(&verbose, "v", false, "enable verbose logs")
  163   166 	flag.BoolVar(&static, "s", false, "serve static files (for development)")
   -1   167 	flag.BoolVar(&dumpItems, "dump-items", false, "dump items.json and exit")
  164   168 	flag.Parse()
  165   169 
   -1   170 	if dumpItems {
   -1   171 		json.NewEncoder(os.Stdout).Encode(Items)
   -1   172 		return
   -1   173 	}
   -1   174 
  166   175 	addr := "localhost:8000"
  167   176 	if len(flag.Args()) > 0 {
  168   177 		addr = fmt.Sprintf("localhost:%s", flag.Args()[0])
@@ -172,7 +181,7 @@ func main() {
  172   181 		http.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
  173   182 			http.ServeFile(w, r, "index.html")
  174   183 		})
  175    -1 		http.HandleFunc("GET /items/", serveItems)
   -1   184 		http.HandleFunc("GET /items.json", serveItems)
  176   185 		http.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
  177   186 	}
  178   187 

diff --git a/static/main.js b/static/main.js

@@ -18,7 +18,7 @@ var COLORS = {
   18    18     'pile': 3,
   19    19 };
   20    20 
   21    -1 var ITEMS = await fetch('/items/').then(r => r.json());
   -1    21 var ITEMS = await fetch('/items.json').then(r => r.json());
   22    22 
   23    23 var inRect = function(pos, rect, withWalls) {
   24    24     if (withWalls) {