git.s-ol.nu alive / c3b5dd1
more love2d transforms s-ol 4 months ago
1 changed file(s) with 102 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
0 import Constant, Op, PureOp, Input, T, Struct, sig, evt from require 'alv.base'
0 import Constant, Op, PureOp, Input, T, Array, any from require 'alv.base'
11
22 unpack or= table.unpack
3
4 vec2 = Array 2, T.num
5 vec3 = Array 3, T.num
6 vec4 = Array 4, T.num
37
48 class DrawId
59 new: =>
1519 super ...
1620 @state or= DrawId!
1721
18 pattern = sig['love/shape']*0
22 pattern = any['love/shape']*0
1923 setup: (inputs, scope) =>
2024 shapes = pattern\match inputs
21 super [Input.hot shape for shape in *shapes]
25 inputs = [Input.hot shape for shape in *shapes]
26 inputs.num = Input.cold Constant.num #shapes
27 super inputs
2228
2329 tick: =>
2430 shapes = @unwrap_all!
31 for i=1, shapes.num do shapes[i] or= ->
2532 COPILOT.drawlist[@state] = shapes
2633
2734 destroy: =>
3138 meta:
3239 name: 'rectangle'
3340 summary: "create a rectangle shape."
34 examples: { '(love/rectangle mode w h)' }
35
36 value: class extends PureOp
37 pattern: sig.str + sig.num + sig.num
38 type: T['love/shape']
39
40 tick: =>
41 { mode, w, h } = @unwrap_all!
41 examples: { '(love/rectangle mode size)', '(love/rectangle mode w h)' }
42
43 value: class extends PureOp
44 pattern: any.str + (any(vec2) / (any.num + any.num))
45 type: T['love/shape']
46
47 tick: =>
48 { mode, size } = @unwrap_all!
49 { w, h } = size
4250 x, y = -w/2, -h/2
4351
4452 @out\set ->
5159 examples: { '(love/color r g b [a] shape)' }
5260
5361 value: class extends PureOp
54 pattern: sig.num\rep(3, 4) + sig['love/shape']
62 pattern: any.num\rep(3, 4) + any['love/shape']
5563 type: T['love/shape']
5664
5765 tick: =>
6775 meta:
6876 name: 'translate'
6977 summary: "translate a shape."
70 examples: { '(love/translate x y hape)' }
71
72 value: class extends PureOp
73 pattern: sig.num + sig.num + sig['love/shape']
74 type: T['love/shape']
75
76 tick: =>
77 { x, y, shape } = @unwrap_all!
78 examples: { '(love/translate [delta] shape)', '(love/translate x y shape)' }
79
80 value: class extends PureOp
81 pattern: (any(vec2) / (any.num + any.num)) + any['love/shape']
82 type: T['love/shape']
83
84 tick: =>
85 { pos, shape } = @unwrap_all!
86 { x, y } = pos
7887
7988 @out\set ->
8089 love.graphics.push!
8695 meta:
8796 name: 'rotate'
8897 summary: "rotate a shape."
89 examples: { '(love/rotate angle hape)' }
90
91 value: class extends PureOp
92 pattern: sig.num + sig['love/shape']
98 examples: { '(love/rotate angle shape)' }
99
100 value: class extends PureOp
101 pattern: any.num + any['love/shape']
93102 type: T['love/shape']
94103
95104 tick: =>
100109 love.graphics.rotate angle
101110 shape!
102111 love.graphics.pop!
112
113 scale = Constant.meta
114 meta:
115 name: 'scale'
116 summary: "scale a shape."
117 examples: { '(love/scale scale shape)', '(love/scale sx [sy] shape)' }
118
119 value: class extends PureOp
120 pattern: (any(vec2) / (any.num + -any.num)) + any['love/shape']
121 type: T['love/shape']
122
123 tick: =>
124 { pos, shape } = @unwrap_all!
125 { sx, sy } = pos
126
127 @out\set ->
128 love.graphics.push!
129 love.graphics.scale sx, sy
130 shape!
131 love.graphics.pop!
132
133 shear = Constant.meta
134 meta:
135 name: 'shear'
136 summary: "shear a shape."
137 examples: { '(love/shear x y shape)' }
138
139 value: class extends PureOp
140 pattern: (any(vec2) / (any.num + any.num)) + any['love/shape']
141 type: T['love/shape']
142
143 tick: =>
144 { pos, shape } = @unwrap_all!
145 { sx, sy } = pos
146
147 @out\set ->
148 love.graphics.push!
149 love.graphics.shear sx, sy
150 shape!
151 love.graphics.pop!
152
153 mouse_pos = Constant.meta
154 meta:
155 name: 'mouse-pos'
156 summary: "outputs current mouse position."
157 examples: { '(love/mouse-pos)' }
158
159 value: class extends Op
160 new: (...) =>
161 super ...
162 @out or= vec2\mk_evt!
163 @state = {}
164
165 setup: =>
166 super io: Input.hot T.bang\mk_evt!
167
168 poll: =>
169 x, y = love.mouse.getPosition!
170 if x != @state.x or y != @state.y
171 @state.x, @state.y = x, y
172 if not @inputs.io\dirty!
173 @inputs.io.result\set true
174 true
175
176 tick: =>
177 @out\set { @state.x, @state.y }
103178
104179 Constant.meta
105180 meta:
138213
139214 :rectangle
140215
141 :translate, :rotate
216 :translate, :rotate, :scale, :shear
142217 :color
218
219 'mouse-pos': mouse_pos