generate_game_index.lsp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env newlisp
  2. (module "util.lsp")
  3. (module "getopts.lsp")
  4. (module "json.lsp")
  5. (shortopt "d" (setq gamefolder getopts:arg) "" "game folder")
  6. (shortopt "?" (getopts:usage) nil "Print this help message")
  7. (getopts (2 (main-args))); parse getopt
  8. (if (or (nil? gamefolder) (= gamefolder ""))
  9. (begin
  10. (getopts:usage)
  11. (exit)
  12. )
  13. )
  14. (setq files (directory gamefolder))
  15. (setq res (list ))
  16. (dolist (x files)
  17. (if (and (not (starts-with x ".")) (directory? (string gamefolder "/" x )))
  18. (begin
  19. (setq gametype (read-file (string gamefolder "/" x "/.game")))
  20. ;(println gametype)
  21. (if (not (nil? gametype))
  22. (begin
  23. (setq item_list '())
  24. (setq _file (exec (string "raw.github.lsp " gamefolder "/'" x "'/file/*")))
  25. (setq _shots (exec (string "raw.github.lsp " gamefolder "/'" x "'/shots/*")))
  26. (setq item_list (list (list "title" x) (list "type" gametype)))
  27. (if (= (length _file) 1)
  28. (push (list "file" (nth 0 _file)) item_list)
  29. (push (list "file" _file) item_list)
  30. )
  31. (if (= (length _shots) 1)
  32. (push (list "shots" (nth 0 _shots)) item_list)
  33. (push (list "shots" _shots) item_list)
  34. )
  35. ;(println item_list)
  36. (reverse item_list)
  37. (push item_list res)
  38. )
  39. )
  40. )
  41. )
  42. )
  43. (set 'indexjson:list res)
  44. (println (Json:Lisp->Json indexjson))
  45. (exit)