summaryrefslogtreecommitdiff
path: root/asciifarm/client/inputhandling.hy
diff options
context:
space:
mode:
authortroido <troido@hotmail.com>2018-01-02 21:26:46 +0100
committertroido <troido@hotmail.com>2018-01-02 21:26:46 +0100
commit44c26befaab94781e35d159db82d875bff2ed31e (patch)
tree2667a10afd1b62c1217f9bce6b266a5d114cac46 /asciifarm/client/inputhandling.hy
parent8cd98452054fbfe46bc3c78b5b844742e7ed07a4 (diff)
keybindings are now executed a bit smarter as hy code
Diffstat (limited to 'asciifarm/client/inputhandling.hy')
-rw-r--r--asciifarm/client/inputhandling.hy55
1 files changed, 55 insertions, 0 deletions
diff --git a/asciifarm/client/inputhandling.hy b/asciifarm/client/inputhandling.hy
new file mode 100644
index 0000000..8d19e4a
--- /dev/null
+++ b/asciifarm/client/inputhandling.hy
@@ -0,0 +1,55 @@
+
+(require [asciifarm.client.keymacros [*]])
+
+(defmacro eval-in-context [code]
+ `(
+ (eval `(do
+ (require [asciifarm.client.keymacros [*]])
+ (fn [client display connection]
+ ~~code)))
+ self.client
+ self.display
+ self.connection))
+
+(defmacro sendinput [message] `(
+ self.client.send ["input" ~message]))
+
+(defclass InputHandler []
+
+ (defn --init-- [self client display connection]
+ (setv self.client client)
+ (setv self.display display)
+ (setv self.connection connection)
+ (setv self.commands None))
+
+ (defn readCommands [self commandsstring]
+ (setv self.commands
+ (dict-comp
+ (eval key)
+ (
+ (eval `(do
+ (require [asciifarm.client.keymacros [*]])
+ (fn [handler]
+ (fn [] ~value))))
+ self)
+ [[key value] (.items (read-str commandsstring))])))
+
+ (defn runCommand [self commandstring]
+ (eval (read-str (+ "(" commandstring ")"))))
+
+ (defn parseMessage [self message]
+ (if message
+ (if (= (first message) "/")
+ (do
+ (setv msg (.join "" (drop 1 message)))
+ (if (= (first msg) "/")
+ (inp ["say" msg])
+ (self.runCommand msg)))
+ (inp ["say" message]))))
+
+ (defn getDocs [self]
+ (if (in "help" self.commands) ((get self.commands "help")) ""))
+
+ (defn onKey [self key]
+ (if (in key self.commands) ((get self.commands key))))
+)