(ns advent.core.desktop-launcher
  (:require [advent.core :refer :all]
            [clojure.tools.nrepl.server])
  (:import [com.badlogic.gdx.backends.lwjgl LwjglApplication]
           [org.lwjgl.input Keyboard])
  (:gen-class))

(defmacro start-nrepl-expr [port]
  `(let [{port# :port} (clojure.tools.nrepl.server/start-server :port ~port)]
     (doseq [port-file# ["target/repl-port" ".nrepl-port"]]
       (-> port-file#
           java.io.File.
           (doto .deleteOnExit)
           (spit port#)))
     (println "Started nREPL server on port" port#)))

(defn -main
  [& [port]]
  (when port (start-nrepl-expr (Integer/parseInt port)))
  (LwjglApplication. advent "advent"  1280 960)

  (Keyboard/enableRepeatEvents true))
