-
Notifications
You must be signed in to change notification settings - Fork 9
/
macros.clj
44 lines (40 loc) · 1.34 KB
/
macros.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(ns herfi.scene.macros
(:require
[cljs.core.async.macros :refer [go-loop]]
[clojure.java.io :as io]
[clojure.string :as str]))
(def three-objects
(->> "node_modules/three/src"
io/file
file-seq
(filter #(.isFile %))
(filter #(str/ends-with? (.getFileName (.toPath %)) ".js"))
(mapv #(str (.getFileName (.toPath %))))
(filter #(Character/isUpperCase (first %)))
(map #(subs % 0 (str/index-of % ".js")))
(map #(str "THREE/" %))))
(defmacro go-loop-sub [pub key binding & body]
`(let [ch# (cljs.core.async/chan)]
(herfi.common.communication/add-to-exit-ch ~key ch#)
(cljs.core.async/sub ~pub ~key ch#)
(go-loop []
(let [~binding (cljs.core.async/<! ch#)]
(when-not (= (first ~binding) :exit)
(try
~@body
(catch js/Error e
(js/console.error "go-loop")
(js/console.error e)))
(recur))))))
(defmacro fnd [id & body]
`(herfi.scene.ecs/update-script-update-fn ~id
(fn [~'delta]
~@body)))
(defmacro three? [obj]
`(try
(or (instance? THREE/Object3D ~obj)
~@(map
(fn [x]
`(= ~(symbol x) (.-constructor ~obj))) three-objects))
(catch js/Error _#
false)))