feat: add OpenComputers RC bot
This commit is contained in:
parent
98a9d0f0c2
commit
6de04ed12c
2 changed files with 88 additions and 0 deletions
54
opencomputers/rc_bot/rcbot.fnl
Normal file
54
opencomputers/rc_bot/rcbot.fnl
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
(local ev (require :event))
|
||||||
|
(local bot (require :robot))
|
||||||
|
(local com (require :component))
|
||||||
|
|
||||||
|
(local infostr "WASD/Space/Shift: Move
|
||||||
|
B: Swing
|
||||||
|
P: Place
|
||||||
|
U: Use
|
||||||
|
,/.: Prev/Next slot
|
||||||
|
I: Inventory
|
||||||
|
Q: Drop Slot
|
||||||
|
C: Collect
|
||||||
|
O: Empty Inventory")
|
||||||
|
|
||||||
|
(local evmap {:__infomsg (fn [] infostr)
|
||||||
|
:w bot.forward
|
||||||
|
:a bot.turnLeft
|
||||||
|
:s bot.back
|
||||||
|
:d bot.turnRight
|
||||||
|
:space bot.up
|
||||||
|
:lshift bot.down
|
||||||
|
:b bot.swing
|
||||||
|
:p bot.place
|
||||||
|
:u bot.use
|
||||||
|
:comma (fn []
|
||||||
|
(bot.select (- (bot.select) 1)))
|
||||||
|
:period (fn []
|
||||||
|
(bot.select (+ (bot.select) 1)))
|
||||||
|
:i (fn []
|
||||||
|
(local selected (bot.select))
|
||||||
|
(faccumulate [s "" i 1 (bot.inventorySize)]
|
||||||
|
(let [info (com.inventory_controller.getStackInInternalSlot i)]
|
||||||
|
(.. s (if (= i selected) "> " " ")
|
||||||
|
(if info
|
||||||
|
(.. info.label "\t" info.size "/" info.maxSize)
|
||||||
|
"-") "\n"))))
|
||||||
|
:q bot.drop
|
||||||
|
:c bot.suck
|
||||||
|
:o (fn []
|
||||||
|
(let [prev (bot.select)
|
||||||
|
total (faccumulate [total 0 i 1 (bot.inventorySize)]
|
||||||
|
(do
|
||||||
|
(bot.select i)
|
||||||
|
(+ total (if (bot.drop) 1 0))))]
|
||||||
|
(bot.select prev)
|
||||||
|
(.. "Dropped items from " total " Slots.\nSelected Slot: "
|
||||||
|
prev)))})
|
||||||
|
|
||||||
|
(while true
|
||||||
|
(let [(_ _ _ _ _ msg) (ev.pull :modem_message)
|
||||||
|
func (. evmap msg)
|
||||||
|
(_ ret) (if func (pcall func) "Unknown Command")]
|
||||||
|
(print msg)
|
||||||
|
(com.tunnel.send ret)))
|
34
opencomputers/rc_bot/remote.fnl
Normal file
34
opencomputers/rc_bot/remote.fnl
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
(local ev (require :event))
|
||||||
|
(local com (require :component))
|
||||||
|
(local term (require :term))
|
||||||
|
(local keyboard (require :keyboard))
|
||||||
|
|
||||||
|
(local infomsg (do
|
||||||
|
(print "fetching infomsg...")
|
||||||
|
(com.tunnel.send :__infomsg)
|
||||||
|
(let [(_ _ _ _ _ msg) (ev.pull :modem_message)]
|
||||||
|
msg)))
|
||||||
|
|
||||||
|
(fn show-info []
|
||||||
|
(term.clear)
|
||||||
|
(print infomsg)
|
||||||
|
(let [width (term.getViewport)]
|
||||||
|
(print (string.rep "=" width))))
|
||||||
|
|
||||||
|
(fn on-key [key]
|
||||||
|
(let [kname (. keyboard.keys key)]
|
||||||
|
(print ">> " kname)
|
||||||
|
(com.tunnel.send kname)))
|
||||||
|
|
||||||
|
(fn on-message [distance payload]
|
||||||
|
(show-info)
|
||||||
|
(print "D: " distance)
|
||||||
|
(print payload))
|
||||||
|
|
||||||
|
(show-info)
|
||||||
|
|
||||||
|
(while true
|
||||||
|
(let [(ev-type p1 p2 p3 p4 p5) (ev.pull)]
|
||||||
|
(case ev-type
|
||||||
|
:key_down (on-key p3)
|
||||||
|
:modem_message (on-message p4 p5))))
|
Loading…
Reference in a new issue