aboutsummaryrefslogtreecommitdiffstats
path: root/lib/gui.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-01-31 18:28:10 +0000
committers-ol <s-ol@users.noreply.github.com>2020-01-31 18:28:10 +0000
commit16962e1836251526fa08895b1a76dd72b7fd5ef9 (patch)
treeef60d08e792825407d41fb77c14c26ecb135e2fc /lib/gui.moon
parentnested parens in comments (diff)
downloadalive-16962e1836251526fa08895b1a76dd72b7fd5ef9.tar.gz
alive-16962e1836251526fa08895b1a76dd72b7fd5ef9.zip
modularize
Diffstat (limited to 'lib/gui.moon')
-rw-r--r--lib/gui.moon45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/gui.moon b/lib/gui.moon
new file mode 100644
index 0000000..979854f
--- /dev/null
+++ b/lib/gui.moon
@@ -0,0 +1,45 @@
+{ graphics: lg } = love
+import Op from require 'base'
+import Copilot from require 'copilot'
+
+class out extends Op
+ setup: (name, @chld) =>
+ @@instances[@name] = nil if @name
+ @name = name\getc!
+ @@instances[@name] = @
+
+ update: =>
+ @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
+
+copilot = Copilot arg[#arg], env
+
+love.update = (dt) ->
+ copilot\poll!
+ env\update dt
+
+love.draw = ->
+ out.draw_all!
+
+{
+ :out
+}