Use reify instead of proxy, add input function, and add global interop macros
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
(ns play-clj.core
|
||||
(:require [clojure.set :as set]
|
||||
[play-clj.utils :as utils])
|
||||
(:import [com.badlogic.gdx Game Gdx Screen]
|
||||
(:import [com.badlogic.gdx Application Audio Files Game Gdx Graphics Input
|
||||
InputProcessor Net Screen]
|
||||
[com.badlogic.gdx.graphics Camera Color GL20 OrthographicCamera
|
||||
PerspectiveCamera Texture]
|
||||
[com.badlogic.gdx.graphics.g2d Animation BitmapFont SpriteBatch
|
||||
@@ -28,6 +29,8 @@
|
||||
[obj]
|
||||
{:type :actor :object obj})
|
||||
|
||||
(defn- dummy [& args])
|
||||
|
||||
(load "core_2d")
|
||||
(load "core_deprecated")
|
||||
(load "core_global")
|
||||
@@ -35,8 +38,6 @@
|
||||
(load "core_render")
|
||||
(load "core_ui")
|
||||
|
||||
(defn- dummy [& args])
|
||||
|
||||
(defn defscreen*
|
||||
[{:keys [on-show on-render on-hide on-pause on-resize on-resume]
|
||||
:or {on-show dummy on-render dummy on-hide dummy
|
||||
@@ -95,13 +96,14 @@
|
||||
(let [run-fn! (fn [k & args]
|
||||
(doseq [screen screens]
|
||||
(apply (get screen k) args)))]
|
||||
(.setScreen game (proxy [Screen] []
|
||||
(show [] (run-fn! :show))
|
||||
(render [delta-time] (run-fn! :render delta-time))
|
||||
(hide [] (run-fn! :hide))
|
||||
(pause [] (run-fn! :pause))
|
||||
(resize [w h] (run-fn! :resize))
|
||||
(resume [] (run-fn! :resume))))))
|
||||
(.setScreen game (reify Screen
|
||||
(show [this] (run-fn! :show))
|
||||
(render [this delta-time] (run-fn! :render delta-time))
|
||||
(hide [this] (run-fn! :hide))
|
||||
(pause [this] (run-fn! :pause))
|
||||
(resize [this w h] (run-fn! :resize))
|
||||
(resume [this] (run-fn! :resume))
|
||||
(dispose [this])))))
|
||||
|
||||
(defn update!
|
||||
[{:keys [update-fn!]} & {:keys [] :as args}]
|
||||
|
||||
@@ -34,8 +34,29 @@
|
||||
:y (.getY (Gdx/input))
|
||||
nil))
|
||||
|
||||
(defmacro input-key
|
||||
[key]
|
||||
`~(symbol
|
||||
(str utils/gdx-package ".Input$Keys/" (utils/key->static-field key))))
|
||||
|
||||
(defmacro is-pressed?
|
||||
[key]
|
||||
`(.isKeyPressed (Gdx/input)
|
||||
~(symbol (str utils/gdx-package ".Input$Keys/"
|
||||
(utils/key->static-field key)))))
|
||||
`(.isKeyPressed (Gdx/input) (input-key ~key)))
|
||||
|
||||
(defn input
|
||||
[& {:keys [key-down key-typed key-up mouse-moved
|
||||
scrolled touch-down touch-dragged touch-up]
|
||||
:or {key-down dummy key-typed dummy key-up dummy mouse-moved dummy
|
||||
scrolled dummy touch-down dummy touch-dragged dummy touch-up dummy}}]
|
||||
(reify InputProcessor
|
||||
(keyDown [this keycode] (key-down keycode))
|
||||
(keyTyped [this character] (key-typed character))
|
||||
(keyUp [this keycode] (key-up keycode))
|
||||
(mouseMoved [this screen-x screen-y] (mouse-moved screen-x screen-y))
|
||||
(scrolled [this amount] (scrolled amount))
|
||||
(touchDown [this screen-x screen-y pointer button]
|
||||
(touch-down screen-x screen-y pointer button))
|
||||
(touchDragged [this screen-x screen-y pointer]
|
||||
(touch-dragged screen-x screen-y pointer))
|
||||
(touchUp [this screen-x screen-y pointer button]
|
||||
(touch-up screen-x screen-y pointer button))))
|
||||
|
||||
@@ -36,6 +36,36 @@
|
||||
[{:keys [camera]} k & options]
|
||||
`(utils/call! ^PerspectiveCamera ~camera ~k ~@options))
|
||||
|
||||
; global
|
||||
|
||||
(defmacro app!
|
||||
[k & options]
|
||||
`(utils/call! ^Application (Gdx/app) ~k ~@options))
|
||||
|
||||
(defmacro audio!
|
||||
[k & options]
|
||||
`(utils/call! ^Audio (Gdx/audio) ~k ~@options))
|
||||
|
||||
(defmacro files!
|
||||
[k & options]
|
||||
`(utils/call! ^Files (Gdx/files) ~k ~@options))
|
||||
|
||||
(defmacro gl!
|
||||
[k & options]
|
||||
`(utils/call! ^GL20 (Gdx/gl20) ~k ~@options))
|
||||
|
||||
(defmacro graphics!
|
||||
[k & options]
|
||||
`(utils/call! ^Graphics (Gdx/graphics) ~k ~@options))
|
||||
|
||||
(defmacro input!
|
||||
[k & options]
|
||||
`(utils/call! ^Input (Gdx/input) ~k ~@options))
|
||||
|
||||
(defmacro net!
|
||||
[k & options]
|
||||
`(utils/call! ^Net (Gdx/net) ~k ~@options))
|
||||
|
||||
; ui
|
||||
|
||||
(defmacro check-box!
|
||||
|
||||
Reference in New Issue
Block a user