@@ -43,6 +43,19 @@ Blockly.Words['awtrix-light_timer'] = {
43
43
uk : 'Awtrix-light Таймер' ,
44
44
'zh-cn' : 'Awtrix-light 时间' ,
45
45
} ;
46
+ Blockly . Words [ 'awtrix-light_playsound' ] = {
47
+ en : 'Play sound' ,
48
+ de : 'Sound spielen' ,
49
+ ru : 'Играть звук' ,
50
+ pt : 'Tocar som' ,
51
+ nl : 'Speel' ,
52
+ fr : 'Play sound' ,
53
+ it : 'Suoni suono' ,
54
+ es : 'Jugar sonido' ,
55
+ pl : 'Dźwięk' ,
56
+ uk : 'Грати звук' ,
57
+ 'zh-cn' : '声音' ,
58
+ } ;
46
59
Blockly . Words [ 'awtrix-light_message' ] = {
47
60
en : 'Message' ,
48
61
de : 'Nachricht' ,
@@ -362,3 +375,49 @@ Blockly.JavaScript['awtrix-light_timer'] = function (block) {
362
375
363
376
return `sendTo('awtrix-light${ block . getFieldValue ( 'INSTANCE' ) } ', 'timer', { ${ objText . join ( ', ' ) } }, (res) => { if (res && res.error) { console.error(res.error); } });` ;
364
377
} ;
378
+
379
+ Blockly . Sendto . blocks [ 'awtrix-light_playsound' ] = '<block type="awtrix-light_playsound"><value name="INSTANCE"></value><value name="SOUND"></value></block>' ;
380
+
381
+ Blockly . Blocks [ 'awtrix-light_playsound' ] = {
382
+ init : function ( ) {
383
+ const options = [ ] ;
384
+
385
+ if ( typeof main !== 'undefined' && main . instances ) {
386
+ for ( let i = 0 ; i < main . instances . length ; i ++ ) {
387
+ const m = main . instances [ i ] . match ( / ^ s y s t e m .a d a p t e r .a w t r i x - l i g h t .( \d + ) $ / ) ;
388
+ if ( m ) {
389
+ const n = parseInt ( m [ 1 ] , 10 ) ;
390
+ options . push ( [ 'awtrix-light.' + n , '.' + n ] ) ;
391
+ }
392
+ }
393
+ }
394
+
395
+ if ( ! options . length ) {
396
+ for ( let k = 0 ; k <= 4 ; k ++ ) {
397
+ options . push ( [ 'awtrix-light.' + k , '.' + k ] ) ;
398
+ }
399
+ }
400
+
401
+ options . unshift ( [ Blockly . Translate ( 'awtrix-light_anyInstance' ) , '' ] ) ;
402
+
403
+ this . appendDummyInput ( 'INSTANCE' ) . appendField ( Blockly . Translate ( 'awtrix-light_playsound' ) ) . appendField ( new Blockly . FieldDropdown ( options ) , 'INSTANCE' ) ;
404
+ this . appendValueInput ( 'SOUND' ) . appendField ( Blockly . Translate ( 'awtrix-light_sound' ) ) ;
405
+
406
+ this . setInputsInline ( false ) ;
407
+ this . setPreviousStatement ( true , null ) ;
408
+ this . setNextStatement ( true , null ) ;
409
+
410
+ this . setColour ( Blockly . Sendto . HUE ) ;
411
+ this . setTooltip ( Blockly . Translate ( 'awtrix-light_tooltip' ) ) ;
412
+ this . setHelpUrl ( Blockly . Translate ( 'awtrix-light_help' ) ) ;
413
+ } ,
414
+ } ;
415
+
416
+ Blockly . JavaScript [ 'awtrix-light_playsound' ] = function ( block ) {
417
+ const sound = Blockly . JavaScript . valueToCode ( block , 'SOUND' , Blockly . JavaScript . ORDER_ATOMIC ) ;
418
+
419
+ const objText = [ ] ;
420
+ sound && objText . push ( 'sound: ' + sound ) ;
421
+
422
+ return `sendTo('awtrix-light${ block . getFieldValue ( 'INSTANCE' ) } ', 'sound', { ${ objText . join ( ', ' ) } }, (res) => { if (res && res.error) { console.error(res.error); } });` ;
423
+ } ;
0 commit comments