From 16962e1836251526fa08895b1a76dd72b7fd5ef9 Mon Sep 17 00:00:00 2001 From: s-ol Date: Fri, 31 Jan 2020 19:28:10 +0100 Subject: modularize --- lib/gui.moon | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 lib/gui.moon (limited to 'lib/gui.moon') 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 +} -- cgit v1.2.3