Make is-pressed? work with all keys
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
(ns play-clj.core
|
||||
(:require [clojure.set :as set]
|
||||
[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
|
||||
PerspectiveCamera Texture]
|
||||
[com.badlogic.gdx.graphics.g2d Animation BitmapFont SpriteBatch
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
[& options]
|
||||
`(BitmapFont. ~@options))
|
||||
|
||||
; input/output
|
||||
|
||||
(defn game
|
||||
[key]
|
||||
(case key
|
||||
@@ -32,19 +34,8 @@
|
||||
:y (.getY (Gdx/input))
|
||||
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?
|
||||
[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
|
||||
[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) "Style."))
|
||||
~@options))
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
(:require [clojure.string :as s])
|
||||
(:import [com.badlogic.gdx.utils Array]))
|
||||
|
||||
(def ^:const gdx-package "com.badlogic.gdx.")
|
||||
(def ^:const gdx-package "com.badlogic.gdx")
|
||||
|
||||
(defn- split-key
|
||||
[key]
|
||||
@@ -10,14 +10,35 @@
|
||||
|
||||
(defn- join-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*
|
||||
[args]
|
||||
(->> (last args)
|
||||
split-key
|
||||
(map s/upper-case)
|
||||
(s/join "_")
|
||||
(->> (key->static-field (last args))
|
||||
(str (join-keys (butlast args)) "/")
|
||||
symbol))
|
||||
|
||||
@@ -29,23 +50,6 @@
|
||||
[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!
|
||||
[obj k & args]
|
||||
`(~(key->method k) ~obj ~@args))
|
||||
|
||||
Reference in New Issue
Block a user