@@ -10,7 +10,7 @@ local moveThrottle = 300
1010local dragThrottle = 50
1111
1212local baseTerm = term .current ()
13- local version = " 1.6.3 "
13+ local version = " 1.6.4 "
1414
1515local projectDirectory = fs .getDir (table.pack (... )[2 ] or " " )
1616
@@ -23,13 +23,26 @@ if not term.isColor or not term.isColor() then
2323 error (' Basalt requires an advanced (golden) computer to run.' , 0 )
2424end
2525
26+ local defaultColors = {}
27+ for k ,v in pairs (colors )do
28+ if (type (v )== " number" )then
29+ defaultColors [k ] = {baseTerm .getPaletteColor (v )}
30+ end
31+ end
32+
33+
2634local function stop ()
2735 updaterActive = false
2836 baseTerm .clear ()
2937 baseTerm .setCursorPos (1 , 1 )
38+ for k ,v in pairs (colors )do
39+ if (type (v )== " number" )then
40+ baseTerm .setPaletteColor (v , colors .packRGB (table.unpack (defaultColors [k ])))
41+ end
42+ end
3043end
3144
32- local basaltError = function (errMsg )
45+ local function basaltError (errMsg )
3346 baseTerm .clear ()
3447 baseTerm .setBackgroundColor (colors .black )
3548 baseTerm .setTextColor (colors .red )
@@ -79,6 +92,10 @@ local getTheme = function(name)
7992end
8093
8194local bInstance = {
95+ getDynamicValueEventSetting = function ()
96+ return basalt .dynamicValueEvents
97+ end ,
98+
8299 getMainFrame = function ()
83100 return mainFrame
84101 end ,
176193
177194local stopped , moveX , moveY = nil , nil , nil
178195local moveTimer = nil
179- local function mouseMoveEvent (stp , x , y )
180- stopped , moveX , moveY = stopped , x , y
196+ local function mouseMoveEvent (_ , stp , x , y )
197+ stopped , moveX , moveY = stp , x , y
181198 if (moveTimer == nil )then
182199 moveTimer = os .startTimer (moveThrottle / 1000 )
183200 end
@@ -197,7 +214,7 @@ local function dragHandlerTimer()
197214 activeFrame = mainFrame
198215end
199216
200- local function mouseDragEvent (b , x , y )
217+ local function mouseDragEvent (_ , b , x , y )
201218 btn , dragX , dragY = b , x , y
202219 if (dragThrottle < 50 )then
203220 dragHandlerTimer ()
@@ -208,79 +225,75 @@ local function mouseDragEvent(b, x, y)
208225 end
209226end
210227
211- local function basaltUpdateEvent (event , p1 , p2 , p3 , p4 )
212- if (basaltEvent :sendEvent (" basaltEventCycle" , event , p1 , p2 , p3 , p4 )== false )then return end
228+ local function basaltUpdateEvent (event , ...)
229+ local a = {... }
230+ if (basaltEvent :sendEvent (" basaltEventCycle" , event , ... )== false )then return end
231+ if (event == " terminate" )then basalt .stop () end
213232 if (mainFrame ~= nil )then
214- if (event == " mouse_click" ) then
215- mainFrame :mouseHandler (p1 , p2 , p3 , false )
216- activeFrame = mainFrame
217- elseif (event == " mouse_drag" ) then
218- mouseDragEvent (p1 , p2 , p3 )
219- elseif (event == " mouse_up" ) then
220- mainFrame :mouseUpHandler (p1 , p2 , p3 , p4 )
221- activeFrame = mainFrame
222- elseif (event == " mouse_scroll" ) then
223- mainFrame :scrollHandler (p1 , p2 , p3 , p4 )
224- activeFrame = mainFrame
225- elseif (event == " mouse_move" ) then
226- mouseMoveEvent (p1 , p2 , p3 )
233+ local mouseEvents = {
234+ mouse_click = mainFrame .mouseHandler ,
235+ mouse_up = mainFrame .mouseUpHandler ,
236+ mouse_scroll = mainFrame .scrollHandler ,
237+ mouse_drag = mouseDragEvent ,
238+ mouse_move = mouseMoveEvent ,
239+ }
240+ local mouseEvent = mouseEvents [event ]
241+ if (mouseEvent ~= nil )then
242+ mouseEvent (mainFrame , ... )
243+ drawFrames ()
244+ return
227245 end
228246 end
229247
230248 if (event == " monitor_touch" ) then
231249 if (monFrames [p1 ]~= nil )then
232- monFrames [p1 ]:mouseHandler (1 , p2 , p3 , true )
250+ monFrames [p1 ]:mouseHandler (1 , a [ 2 ], a [ 3 ] , true )
233251 activeFrame = monFrames [p1 ]
234252 end
235253 if (count (monGroups )> 0 )then
236254 for k ,v in pairs (monGroups )do
237- v [1 ]:mouseHandler (1 , p2 , p3 , true , p1 )
255+ v [1 ]:mouseHandler (1 , a [ 2 ], a [ 3 ] , true , a [ 1 ] )
238256 end
239257 end
258+ drawFrames ()
259+ return
240260 end
241261
242-
243-
244- if (event == " char" )then
245- if (activeFrame ~= nil )then
246- activeFrame :charHandler (p1 )
247- end
248- end
249- if (event == " key_up" )then
250- if (activeFrame ~= nil )then
251- activeFrame :keyUpHandler (p1 )
252- end
253- activeKey [p1 ] = false
254- end
255- if (event == " key" )then
256- if (activeFrame ~= nil )then
257- activeFrame :keyHandler (p1 , p2 )
258- end
259- activeKey [p1 ] = true
260- end
261- if (event == " terminate" )then
262- if (activeFrame ~= nil )then
263- activeFrame :eventHandler (event )
264- if (updaterActive == false )then return end
262+ if (activeFrame ~= nil )then
263+ local keyEvents = {
264+ char = activeFrame .charHandler ,
265+ key = activeFrame .keyHandler ,
266+ key_up = activeFrame .keyUpHandler ,
267+ }
268+ local keyEvent = keyEvents [event ]
269+ if (keyEvent ~= nil )then
270+ if (event == " key" )then
271+ activeKey [a [1 ]] = true
272+ elseif (event == " key_up" )then
273+ activeKey [a [1 ]] = false
274+ end
275+ keyEvent (activeFrame , ... )
276+ drawFrames ()
277+ return
265278 end
266279 end
267- if (event ~= " mouse_click" )and (event ~= " mouse_up" )and (event ~= " mouse_scroll" )and (event ~= " mouse_drag" )and (event ~= " mouse_move" )and (event ~= " key" )and (event ~= " key_up" )and (event ~= " char" )and (event ~= " terminate" )then
268- if (event == " timer" )and (p1 == moveTimer )then
269- moveHandlerTimer ()
270- elseif (event == " timer" )and (p1 == dragTimer )then
271- dragHandlerTimer ()
272- else
273- for k , v in pairs (frames ) do
274- v :eventHandler (event , p1 , p2 , p3 , p4 )
275- end
280+
281+ if (event == " timer" )and (a [1 ]== moveTimer )then
282+ moveHandlerTimer ()
283+ elseif (event == " timer" )and (a [1 ]== dragTimer )then
284+ dragHandlerTimer ()
285+ else
286+ for k , v in pairs (frames ) do
287+ v :eventHandler (event , ... )
276288 end
277289 end
278- handleSchedules (event , p1 , p2 , p3 , p4 )
290+ handleSchedules (event , ... )
279291 drawFrames ()
280292end
281293
282294basalt = {
283295 logging = false ,
296+ dynamicValueEvents = false ,
284297 setTheme = setTheme ,
285298 getTheme = getTheme ,
286299 drawFrames = drawFrames ,
@@ -337,9 +350,9 @@ basalt = {
337350 end
338351 end ,
339352
340- update = function (event , p1 , p2 , p3 , p4 )
353+ update = function (event , ... )
341354 if (event ~= nil ) then
342- local ok , err = xpcall (basaltUpdateEvent , debug.traceback , event , p1 , p2 , p3 , p4 )
355+ local ok , err = xpcall (basaltUpdateEvent , debug.traceback , event , ... )
343356 if not (ok )then
344357 basaltError (err )
345358 return
0 commit comments