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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
assert love, "this module only works from within love2d!"
{ graphics: lg, keyboard: lk } = love
import Op from require 'core'
import Copilot from require 'copilot'
import Logger from require 'logger'
class out extends Op
@doc: "(out name-str value) - show the output
display value as a bar"
setup: (name, @chld) =>
@@instances[@name] = nil if @name
@name = name\getc!
@@instances[@name] = @
update: (dt) =>
@chld\update dt
@value = @chld\get!
destroy: =>
@@instances[@name] = nil
MARGIN = 16
WIDTH = 24
HEIGHT = 120
@instances: {}
@draw_all: ->
outs = [name for name in pairs @@instances]
table.sort outs
x = MARGIN
lg.setColor 1, 1, 1
for name in *outs
value = @@instances[name].value * HEIGHT
lg.rectangle 'line', x, MARGIN, WIDTH, HEIGHT
lg.rectangle 'fill', x, MARGIN + HEIGHT - value, WIDTH, value
lg.print name, x, MARGIN + HEIGHT + MARGIN
x += WIDTH + MARGIN
class key extends Op
@doc: "(key name-str) - gate from keypress"
setup: (@key) =>
assert @key
update: (dt) =>
@value = lk.isDown @key\get!
arguments, k = {}
for a in *arg
if match = a\match '^%-%-(.*)'
k = match
arguments[k] = true
elseif k
arguments[k] = a
k = nil
else
table.insert arguments, a
Logger.init arguments.log
copilot = Copilot arguments[#arguments]
love.update = (dt) ->
copilot\update dt
love.draw = ->
out.draw_all!
{
:out
:key
}
|