git.s-ol.nu watch-cad / d25e3bf
initial commit s-ol a month ago
3 changed file(s) with 267 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1 function love.conf(t)
2 t.identity = nil -- The name of the save directory (string)
3 t.appendidentity = false -- Search files in source directory before save directory (boolean)
4 t.version = "11.0" -- The LÖVE version this game was made for (string)
5 t.console = false -- Attach a console (boolean, Windows only)
6 t.accelerometerjoystick = true -- Enable the accelerometer on iOS and Android by exposing it as a Joystick (boolean)
7 t.externalstorage = false -- True to save files (and read from the save directory) in external storage on Android (boolean)
8 t.gammacorrect = false -- Enable gamma-correct rendering, when supported by the system (boolean)
9
10 t.audio.mixwithsystem = true -- Keep background music playing when opening LOVE (boolean, iOS and Android only)
11
12 t.window.title = "Untitled" -- The window title (string)
13 t.window.icon = nil -- Filepath to an image to use as the window's icon (string)
14 t.window.width = 800 -- The window width (number)
15 t.window.height = 600 -- The window height (number)
16 t.window.borderless = false -- Remove all border visuals from the window (boolean)
17 t.window.resizable = false -- Let the window be user-resizable (boolean)
18 t.window.minwidth = 1 -- Minimum window width if the window is resizable (number)
19 t.window.minheight = 1 -- Minimum window height if the window is resizable (number)
20 t.window.fullscreen = false -- Enable fullscreen (boolean)
21 t.window.fullscreentype = "desktop" -- Choose between "desktop" fullscreen or "exclusive" fullscreen mode (string)
22 t.window.vsync = 0 -- Vertical sync mode (number)
23 t.window.msaa = 0 -- The number of samples to use with multi-sampled antialiasing (number)
24 t.window.depth = nil -- The number of bits per sample in the depth buffer
25 t.window.stencil = nil -- The number of bits per sample in the stencil buffer
26 t.window.display = 1 -- Index of the monitor to show the window in (number)
27 t.window.highdpi = false -- Enable high-dpi mode for the window on a Retina display (boolean)
28 t.window.x = nil -- The x-coordinate of the window's position in the specified display (number)
29 t.window.y = nil -- The y-coordinate of the window's position in the specified display (number)
30
31 t.modules.audio = true -- Enable the audio module (boolean)
32 t.modules.data = true -- Enable the data module (boolean)
33 t.modules.event = true -- Enable the event module (boolean)
34 t.modules.font = true -- Enable the font module (boolean)
35 t.modules.graphics = true -- Enable the graphics module (boolean)
36 t.modules.image = true -- Enable the image module (boolean)
37 t.modules.joystick = true -- Enable the joystick module (boolean)
38 t.modules.keyboard = true -- Enable the keyboard module (boolean)
39 t.modules.math = true -- Enable the math module (boolean)
40 t.modules.mouse = true -- Enable the mouse module (boolean)
41 t.modules.physics = true -- Enable the physics module (boolean)
42 t.modules.sound = true -- Enable the sound module (boolean)
43 t.modules.system = true -- Enable the system module (boolean)
44 t.modules.thread = true -- Enable the thread module (boolean)
45 t.modules.timer = true -- Enable the timer module (boolean), Disabling it will result 0 delta time in love.update
46 t.modules.touch = true -- Enable the touch module (boolean)
47 t.modules.video = true -- Enable the video module (boolean)
48 t.modules.window = true -- Enable the window module (boolean)
49 end
1 print "scratch buffer is #{file}"
2 lfs = require 'lfs'
3 require 'moon.all'
4
5 love.timer = nil
6
7 { graphics: lg, mouse: lm } = love
8
9 red = { 1, 0, 0 }
10 turk = { 0, 1, 1 }
11 orng = { .6, .5, 0 }
12 gren = { 0, .8, 0 }
13
14 rect = (x, y, w, h, opts={mode: 'line'}) ->
15 lg.setColor opts.color if opts.color
16 lg.rectangle opts.mode, x, y, w, h
17
18 mx, my = lm.getPosition!
19 (lm.isDown 1) and x < mx and x + w > mx and y < my and y + h > my
20
21 export ^
22 COMMIT = false
23
24 Move = (obj, x, y) ->
25 if COMMIT
26 obj.x = x
27 obj.y = y
28 return
29
30 lg.setColor orng
31 lg.line x + obj.w/2, y + obj.h/2, obj\center!
32 obj = obj\clone!
33 obj.x = x
34 obj.y = y
35 obj\draw 'line', orng
36
37 Add = (obj) ->
38 if COMMIT
39 table.insert OBJS, obj
40 return
41
42 obj\draw 'line', gren
43
44 Select_objs = (match) =>
45 if not @selection
46 @selection = {o for o in *OBJS when match and o.name\match match}
47
48 lg.push 'all'
49 lg.setLineWidth 5
50 for obj in *OBJS
51 selected = @selection[obj]
52 if selected
53 obj\draw 'line', orng
54
55 if obj\hit!
56 @selection[obj] = if selected then nil else obj
57
58 lg.pop!
59
60 [o for o in pairs @selection]
61
62 Select_rect = =>
63 { :x, :y, :w, :h } = @rect or { x: 222, y: 200, w: 400, h: 200 }
64
65 opts = mode: 'line', color: turk
66 rect x, y, w, h, opts
67
68 if rect x, y, 30, 30, opts
69 dx, dy = lm.getDelta!
70 x += dx
71 y += dy
72 w -= dx
73 h -= dy
74 if rect x + w - 30, y + h - 30, 30, 30, opts
75 dx, dy = lm.getDelta!
76 w += dx
77 h += dy
78
79 @rect = { :x, :y, :w, :h }
80 @rect
81
82
83 Select_circle = (cx, cy) =>
84 @circ or= do
85 r = math.random! * 100 + 50
86 a = math.random! * math.pi * 2 * 50 + 50
87 hx, hy = r * math.cos(a), r * math.sin(a)
88 { cx: 150, cy: 150, :hx, :hy, :r }
89
90 { :r, :hx, :hy } = @circ
91 if cx and cy
92 @fix_center = true
93 else
94 { :cx, :cy } = @circ
95
96 lg.setColor turk
97 lg.circle 'line', cx, cy, r
98
99 opts = color: turk, mode: 'line'
100
101 if not @fix_center
102 if rect cx - 15, cy - 15, 30, 30, opts
103 dx, dy = lm.getDelta!
104 cx += dx
105 cy += dy
106
107 if rect cx + hx - 15, cy + hy - 15, 30, 30
108 dx, dy = lm.getDelta!
109 hx += dx
110 hy += dy
111
112
113 @circ = { :cx, :cy, :hx, :hy, r: math.sqrt hx*hx + hy*hy }
114 @circ
115
116 update_script = do
117 file = arg[2]
118 last_mod = 0
119 last_script = ->
120
121 wrapper = () ->
122 ok, err = pcall last_script
123
124 if ok and 'function' != type err
125 ok = false
126 err = 'script did not return a function'
127
128 if not ok
129 print "--- ERROR EXECUTING SCRIPT: ---"
130 print err
131 return
132
133 ok, err = pcall err, STATE
134 if not ok
135 print "--- ERROR EXECUTING SCRIPT: ---"
136 print err
137
138 print "watching '#{file}'..."
139 ->
140 mod = lfs.attributes file, 'modification'
141 if last_mod < mod
142 last_mod = mod
143 script, err = loadfile file
144 if script
145 last_script = script
146 else
147 print "--- ERROR PARSING SCRIPT: ---"
148 print err
149
150 wrapper
151
152
153 class Object
154 new: (@name, @x, @y, @w=60, @h=30) =>
155
156 center: =>
157 @x + @w/2, @y + @h/2
158
159 draw: (mode, color) =>
160 rect @x, @y, @w, @h, :mode, :color
161
162 clone: =>
163 Object "", @x, @y, @w, @h
164
165 hit: =>
166 mx, my = lm.getPosition!
167 (lm.justDown!) and @x < mx and @x + @w > mx and @y < my and @y + @h > my
168
169 OBJS = {
170 Object 'led-1', 50, 50
171 Object 'led-2', 50, 150
172 Object 'led-3', 150, 50
173 Object 'led-3', 250, 150
174 Object 'btn', 150, 150, 40, 40
175 }
176
177 lm.doesHit = (x, y, w, h) ->
178 mx, my = lm.getPosition!
179
180 mkstate = -> setmetatable {}, __index: (t, k) ->
181 with val = {}
182 rawset t, k, val
183 STATE = mkstate!
184
185 commit = ->
186 COMMIT = true
187 print "COMMITTING"
188 script = update_script!
189 script!
190 STATE = mkstate!
191 COMMIT = false
192
193 local last_mx, last_my, last_down
194 love.draw = ->
195 script = update_script!
196
197 for obj in *OBJS
198 obj\draw 'fill', red
199
200 script!
201
202 last_mx, last_my = lm.getPosition!
203 last_down = lm.isDown 1
204
205 love.keypressed = (key) ->
206 if key == 'return'
207 commit!
208 if key == 'escape'
209 STATE = mkstate!
210
211 lm.justDown = ->
212 (lm.isDown 1) and not last_down
213
214 lm.getDelta = ->
215 mx, my = lm.getPosition!
216 mx - last_mx, my - last_my
1 require 'moonscript'
2 require 'init'