git.s-ol.nu alive / 50697f5
move love main.lua to alv.copilot.love.main s-ol 1 year, 12 days ago
5 changed file(s) with 86 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
0 ----
1 -- löve Copilot entrypoint.
2 --
3 -- @classmod LoveCopilot
4 import CLICopilot from require 'alv.copilot.cli'
5 import T, Array from require 'alv.base'
6
7 export COPILOT
8
9 vec2 = Array 2, T.num
10
11 class LoveCopilot extends CLICopilot
12 new: (arg) =>
13 table.remove arg, 1
14 super arg
15
16 @drawlist = {}
17 @mouse_pos = vec2\mk_sig { love.mouse.getPosition! }
18 @mouse_delta = vec2\mk_evt!
19 @mouse_presses = T['love/_click']\mk_evt!
20 @mouse_releases = T['love/_click']\mk_evt!
21 @wheel_delta = vec2\mk_evt!
22 @key_presses = T.str\mk_evt!
23 @key_releases = T.str\mk_evt!
24 @textinput = T.str\mk_evt!
25
26 draw: =>
27 love.graphics.origin!
28 love.graphics.clear!
29
30 for id, list in pairs @drawlist
31 for fn in *list
32 fn!
33
34 love.graphics.present!
35
36 run: =>
37 @setup!
38
39 love.run = ->
40 return ->
41 love.event.pump!
42 did_tick = false
43 for name, a,b,c,d,e,f in love.event.poll!
44 COPILOT = @
45 switch name
46 when 'quit'
47 return a or 0
48 when 'mousemoved'
49 @mouse_pos\set { a, b }
50 @mouse_delta\set { c, d }, true
51 when 'mousepressed'
52 @mouse_presses\set { pos: { a, b }, button: c }, true
53 when 'mousereleased'
54 @mouse_releases\set { pos: { a, b }, button: c }, true
55 when 'wheelmoved'
56 @wheel_delta\set { a, b }, true
57 when 'keypressed'
58 @key_presses\set a, true
59 when 'textinput'
60 @textinput\set a, true
61 when 'keyreleased'
62 @key_releases\set a, true
63 --else
64 -- print "unhandled: '#{name}'", a,b,c,d,e,f
65
66 COPILOT = nil
67 did_tick = true
68 @tick!
69
70 @tick! unless did_tick
71 @draw!
72
73 love.timer.sleep 0.001 if love.timer
74
75 {
76 :LoveCopilot
77 }
0 require('moonscript')
1 local Copilot = require('alv.copilot.love').LoveCopilot
2 Copilot(arg):run()
+0
-29
alv/copilot/love.moon less more
0 ----
1 -- löve Copilot entrypoint.
2 --
3 -- @classmod LoveCopilot
4 import CLICopilot from require 'alv.copilot.cli'
5
6 class LoveCopilot extends CLICopilot
7 new: (arg) =>
8 table.remove arg, 1
9 super arg
10 @drawlist = {}
11
12 update: =>
13 @tick!
14
15 draw: =>
16 for id, list in pairs @drawlist
17 for fn in *list
18 fn!
19
20 run: =>
21 @setup!
22
23 love.draw = @\draw
24 love.update = @\update
25
26 {
27 :LoveCopilot
28 }
0 #!/bin/sh
1 LOVE=$(which love11 love 2>/dev/null | head -n 1)
2 BASE=$(dirname "$0")
3 echo "base '$BASE'"
4 exec "$LOVE" "$BASE/../alv/copilot/love" "$@"
+0
-3
bin/alv-love/main.lua less more
0 require('moonscript')
1 local Copilot = require('alv.copilot.love').LoveCopilot
2 Copilot(arg):run()