Make is-pressed? work with all keys
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
(ns play-clj.core
|
(ns play-clj.core
|
||||||
(:require [clojure.set :as set]
|
(:require [clojure.set :as set]
|
||||||
[play-clj.utils :as utils])
|
[play-clj.utils :as utils])
|
||||||
(:import [com.badlogic.gdx Game Gdx Input$Keys Screen]
|
(:import [com.badlogic.gdx Game Gdx Screen]
|
||||||
[com.badlogic.gdx.graphics Camera Color GL20 OrthographicCamera
|
[com.badlogic.gdx.graphics Camera Color GL20 OrthographicCamera
|
||||||
PerspectiveCamera Texture]
|
PerspectiveCamera Texture]
|
||||||
[com.badlogic.gdx.graphics.g2d Animation BitmapFont SpriteBatch
|
[com.badlogic.gdx.graphics.g2d Animation BitmapFont SpriteBatch
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
[& options]
|
[& options]
|
||||||
`(BitmapFont. ~@options))
|
`(BitmapFont. ~@options))
|
||||||
|
|
||||||
|
; input/output
|
||||||
|
|
||||||
(defn game
|
(defn game
|
||||||
[key]
|
[key]
|
||||||
(case key
|
(case key
|
||||||
@@ -32,19 +34,8 @@
|
|||||||
:y (.getY (Gdx/input))
|
:y (.getY (Gdx/input))
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
; input
|
|
||||||
|
|
||||||
(defn resolve-key
|
|
||||||
[key]
|
|
||||||
(if (keyword? key)
|
|
||||||
(case key
|
|
||||||
:up Input$Keys/DPAD_UP
|
|
||||||
:down Input$Keys/DPAD_DOWN
|
|
||||||
:left Input$Keys/DPAD_LEFT
|
|
||||||
:right Input$Keys/DPAD_RIGHT
|
|
||||||
nil)
|
|
||||||
key))
|
|
||||||
|
|
||||||
(defmacro is-pressed?
|
(defmacro is-pressed?
|
||||||
[key]
|
[key]
|
||||||
`(.isKeyPressed (Gdx/input) ~(resolve-key key)))
|
`(.isKeyPressed (Gdx/input)
|
||||||
|
~(symbol (str utils/gdx-package ".Input$Keys/"
|
||||||
|
(utils/key->static-field key)))))
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
(defmacro style
|
(defmacro style
|
||||||
[type & options]
|
[type & options]
|
||||||
`(~(symbol (str utils/gdx-package "scenes.scene2d.ui."
|
`(~(symbol (str utils/gdx-package ".scenes.scene2d.ui."
|
||||||
(utils/key->class type) "$"
|
(utils/key->class type) "$"
|
||||||
(utils/key->class type) "Style."))
|
(utils/key->class type) "Style."))
|
||||||
~@options))
|
~@options))
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
(:require [clojure.string :as s])
|
(:require [clojure.string :as s])
|
||||||
(:import [com.badlogic.gdx.utils Array]))
|
(:import [com.badlogic.gdx.utils Array]))
|
||||||
|
|
||||||
(def ^:const gdx-package "com.badlogic.gdx.")
|
(def ^:const gdx-package "com.badlogic.gdx")
|
||||||
|
|
||||||
(defn- split-key
|
(defn- split-key
|
||||||
[key]
|
[key]
|
||||||
@@ -10,14 +10,35 @@
|
|||||||
|
|
||||||
(defn- join-keys
|
(defn- join-keys
|
||||||
[keys]
|
[keys]
|
||||||
(->> keys (map name) (s/join ".") (str gdx-package)))
|
(->> keys (map name) (s/join ".") (str gdx-package ".")))
|
||||||
|
|
||||||
|
(defn key->static-field
|
||||||
|
[key]
|
||||||
|
(->> (split-key key)
|
||||||
|
(map s/upper-case)
|
||||||
|
(s/join "_")
|
||||||
|
symbol))
|
||||||
|
|
||||||
|
(defn key->class
|
||||||
|
[key]
|
||||||
|
(->> (split-key key)
|
||||||
|
(map s/capitalize)
|
||||||
|
(s/join "")
|
||||||
|
symbol))
|
||||||
|
|
||||||
|
(defn key->method
|
||||||
|
[key]
|
||||||
|
(let [parts (split-key key)]
|
||||||
|
(->> (rest parts)
|
||||||
|
(map s/capitalize)
|
||||||
|
(cons (first parts))
|
||||||
|
(s/join "")
|
||||||
|
(str ".")
|
||||||
|
symbol)))
|
||||||
|
|
||||||
(defn gdx-static-field*
|
(defn gdx-static-field*
|
||||||
[args]
|
[args]
|
||||||
(->> (last args)
|
(->> (key->static-field (last args))
|
||||||
split-key
|
|
||||||
(map s/upper-case)
|
|
||||||
(s/join "_")
|
|
||||||
(str (join-keys (butlast args)) "/")
|
(str (join-keys (butlast args)) "/")
|
||||||
symbol))
|
symbol))
|
||||||
|
|
||||||
@@ -29,23 +50,6 @@
|
|||||||
[a]
|
[a]
|
||||||
(Array. true (into-array a) 1 (count a)))
|
(Array. true (into-array a) 1 (count a)))
|
||||||
|
|
||||||
(defn key->class
|
|
||||||
[k]
|
|
||||||
(->> (split-key k)
|
|
||||||
(map s/capitalize)
|
|
||||||
(s/join "")
|
|
||||||
symbol))
|
|
||||||
|
|
||||||
(defn key->method
|
|
||||||
[k]
|
|
||||||
(let [parts (split-key k)]
|
|
||||||
(->> (rest parts)
|
|
||||||
(map s/capitalize)
|
|
||||||
(cons (first parts))
|
|
||||||
(s/join "")
|
|
||||||
(str ".")
|
|
||||||
symbol)))
|
|
||||||
|
|
||||||
(defmacro call!
|
(defmacro call!
|
||||||
[obj k & args]
|
[obj k & args]
|
||||||
`(~(key->method k) ~obj ~@args))
|
`(~(key->method k) ~obj ~@args))
|
||||||
|
|||||||
Reference in New Issue
Block a user