· 6 years ago · Apr 02, 2020, 09:58 AM
1Entry.staticBlocks = [
2 {
3 category: 'start',
4 blocks: [
5 'when_run_button_click',
6 'when_some_key_pressed',
7 'mouse_clicked',
8 'mouse_click_cancled',
9 'when_object_click',
10 'when_object_click_canceled',
11 'when_message_cast',
12 'message_cast',
13 'message_cast_wait',
14 'when_scene_start',
15 'start_scene',
16 'start_neighbor_scene',
17 'check_object_property',
18 'check_block_execution',
19 'switch_scope',
20 'is_answer_submited',
21 'check_lecture_goal',
22 'check_variable_by_name',
23 'show_prompt',
24 'check_goal_success',
25 'positive_number',
26 'negative_number',
27 'wildcard_string',
28 'wildcard_boolean',
29 'register_score',
30 ],
31 },
32 {
33 category: 'flow',
34 blocks: [
35 'wait_second',
36 'repeat_basic',
37 'repeat_inf',
38 'repeat_while_true',
39 'stop_repeat',
40 '_if',
41 'if_else',
42 'wait_until_true',
43 'stop_object',
44 'restart_project',
45 'when_clone_start',
46 'create_clone',
47 'delete_clone',
48 'remove_all_clones',
49 ],
50 },
51 {
52 category: 'moving',
53 blocks: [
54 'move_direction',
55 'bounce_wall',
56 'move_x',
57 'move_y',
58 'move_xy_time',
59 'locate_x',
60 'locate_y',
61 'locate_xy',
62 'locate_xy_time',
63 'locate',
64 'locate_object_time',
65 'rotate_relative',
66 'direction_relative',
67 'rotate_by_time',
68 'direction_relative_duration',
69 'rotate_absolute',
70 'direction_absolute',
71 'see_angle_object',
72 'move_to_angle',
73 ],
74 },
75 {
76 category: 'looks',
77 blocks: [
78 'show',
79 'hide',
80 'dialog_time',
81 'dialog',
82 'remove_dialog',
83 'change_to_some_shape',
84 'change_to_next_shape',
85 'add_effect_amount',
86 'change_effect_amount',
87 'erase_all_effects',
88 'change_scale_size',
89 'set_scale_size',
90 'flip_x',
91 'flip_y',
92 'change_object_index',
93 ],
94 },
95 {
96 category: 'brush',
97 blocks: [
98 'brush_stamp',
99 'start_drawing',
100 'stop_drawing',
101 'set_color',
102 'set_random_color',
103 'change_thickness',
104 'set_thickness',
105 'change_brush_transparency',
106 'set_brush_tranparency',
107 'brush_erase_all',
108 ],
109 },
110 {
111 category: 'text',
112 blocks: ['text_read', 'text_write', 'text_append', 'text_prepend', 'text_flush'],
113 },
114 {
115 category: 'sound',
116 blocks: [
117 'sound_something_with_block',
118 'sound_something_second_with_block',
119 'sound_from_to',
120 'sound_something_wait_with_block',
121 'sound_something_second_wait_with_block',
122 'sound_from_to_and_wait',
123 'sound_volume_change',
124 'sound_volume_set',
125 'sound_silent_all',
126 ],
127 },
128 {
129 category: 'judgement',
130 blocks: [
131 'is_clicked',
132 'is_press_some_key',
133 'reach_something',
134 'boolean_basic_operator',
135 'boolean_and_or',
136 'boolean_not',
137 ],
138 },
139 {
140 category: 'calc',
141 blocks: [
142 'calc_basic',
143 'calc_rand',
144 'coordinate_mouse',
145 'coordinate_object',
146 'get_sound_volume',
147 'quotient_and_mod',
148 'calc_operation',
149 'get_project_timer_value',
150 'choose_project_timer_action',
151 'set_visible_project_timer',
152 'get_date',
153 'distance_something',
154 'get_sound_duration',
155 'get_user_name',
156 'length_of_string',
157 'combine_something',
158 'char_at',
159 'substring',
160 'index_of_string',
161 'replace_string',
162 'change_string_case',
163 ],
164 },
165 {
166 category: 'variable',
167 blocks: [
168 'variableAddButton',
169 'listAddButton',
170 'ask_and_wait',
171 'get_canvas_input_value',
172 'set_visible_answer',
173 'get_variable',
174 'change_variable',
175 'set_variable',
176 'show_variable',
177 'hide_variable',
178 'value_of_index_from_list',
179 'add_value_to_list',
180 'remove_value_from_list',
181 'insert_value_to_list',
182 'change_value_list_index',
183 'length_of_list',
184 'is_included_in_list',
185 'show_list',
186 'hide_list',
187 ],
188 },
189 {
190 category: 'func',
191 blocks: ['functionAddButton'],
192 },
193 {
194 category: 'analysis',
195 blocks: [
196 'analizyDataAddButton',
197 'append_row_to_table',
198 'insert_row_to_table',
199 'delete_row_from_table',
200 'set_value_from_table',
201 'get_table_count',
202 'get_value_from_table',
203 'calc_values_from_table',
204 'open_table_chart',
205 'close_table_chart',
206 ],
207 },
208 {
209 category: 'ai_utilize',
210 blocks: [
211 'aiUtilizeBlockAddButton',
212 'aiUtilizeModelTrainButton',
213 'audio_title',
214 'check_microphone',
215 'speech_to_text_convert',
216 'speech_to_text_get_value',
217 'get_microphone_volume',
218 'tts_title',
219 'read_text',
220 'read_text_wait_with_block',
221 'set_tts_property',
222 'translate_title',
223 'get_translated_string',
224 'check_language',
225 'video_title',
226 'video_draw_webcam',
227 'video_check_webcam',
228 'video_flip_camera',
229 'video_set_camera_opacity_option',
230 'video_motion_value',
231 'video_toggle_model',
232 'video_is_model_loaded',
233 'video_number_detect',
234 'video_toggle_ind',
235 'video_body_part_coord',
236 'video_face_part_coord',
237 'video_detected_face_info',
238 ],
239 },
240 {
241 category: 'expansion',
242 blocks: [
243 'expansionBlockAddButton',
244 'weather_title',
245 'check_weather',
246 'check_finedust',
247 'get_weather_data',
248 'get_current_weather_data',
249 'get_today_temperature',
250 'check_city_weather',
251 'check_city_finedust',
252 'get_city_weather_data',
253 'get_current_city_weather_data',
254 'get_today_city_temperature',
255 'festival_title',
256 'count_festival',
257 'get_festival_info',
258 'behaviorConductDisaster_title',
259 'count_disaster_behavior',
260 'get_disaster_behavior',
261 'behaviorConductLifeSafety_title',
262 'count_lifeSafety_behavior',
263 'get_lifeSafety_behavior',
264 ],
265 },
266 {
267 category: 'arduino',
268 blocks: [
269 'arduino_reconnect',
270 'arduino_open',
271 'arduino_cloud_pc_open',
272 'arduino_connect',
273 'arduino_download_connector',
274 'download_guide',
275 'arduino_download_source',
276 'arduino_noti',
277 ].concat(EntryStatic.DynamicHardwareBlocks),
278 }
279];
280EntryStatic.getAllBlocks = () => {
281 return Entry.staticBlocks;
282}
283const updateCategory = (category, options) => {
284 Entry.playground.mainWorkspace.blockMenu._generateCategoryView([
285 { category: 'start', visible: true },
286 { category: 'flow', visible: true },
287 { category: 'moving', visible: true },
288 { category: 'looks', visible: true },
289 { category: 'brush', visible: true },
290 { category: 'text', visible: true },
291 { category: 'sound', visible: true },
292 { category: 'judgement', visible: true },
293 { category: 'calc', visible: true },
294 { category: 'variable', visible: true },
295 { category: 'func', visible: true },
296 { category: 'analysis', visible: true },
297 { category: 'ai_utilize', visible: true },
298 { category: 'expansion', visible: true },
299 { category: 'arduino', visible: false },
300 { category: category, visible: true }
301 ]);
302 for (let i = 0; i < $('.entryCategoryElementWorkspace').length; i++) {
303 if (!($($('.entryCategoryElementWorkspace')[i]).attr('id') == 'entryCategorytext')) {
304 $($('.entryCategoryElementWorkspace')[i]).attr('class', 'entryCategoryElementWorkspace');
305 }
306 }
307 Entry.playground.blockMenu._categoryData = EntryStatic.getAllBlocks();
308 Entry.playground.blockMenu._generateCategoryCode(category);
309 if (options) {
310 if (options.background) {
311 $(`#entryCategory${category}`).css('background-image', 'url(' + options.background + ')');
312 $(`#entryCategory${category}`).css('background-repeat', 'no-repeat');
313 if (options.backgroundSize) {
314 $(`#entryCategory${category}`).css('background-size', options.backgroundSize + 'px');
315 }
316 }
317 if (options.name) {
318 $(`#entryCategory${category}`)[0].innerText = options.name
319 }
320 }
321}
322const addBlock = (blockname, template, color, params, _class, func, skeleton = 'basic') => {
323 Entry.block[blockname] = {
324 color: color.color,
325 outerLine: color.outerline,
326 skeleton: skeleton,
327 statement: [],
328 params: params.params,
329 events: {},
330 def: {
331 params: params.def,
332 type: blockname
333 },
334 paramsKeyMap: params.map,
335 class: _class ? _class : 'default',
336 func: func,
337 template: template
338 }
339}
340
341// 블록 추가 시작
342
343////////////////////
344addBlock('fetch', '%1 가져오기', {
345 color: EntryStatic.colorSet.block.default.HARDWARE,
346 outerLine: EntryStatic.colorSet.block.darken.HARDWARE
347}, {
348 params: [
349 {
350 type: 'Block',
351 accept: 'string'
352 }
353 ],
354 def: [
355 {
356 type: 'text',
357 params: ['https://playentry.org/api/discuss/findNotice']
358 }
359 ],
360 map: {
361 APIURL: 0
362 }
363}, 'text', async (sprite, script) => {
364 let res = await fetch(script.getValue('APIURL', script))
365 let data = await res.json()
366 return data
367}, 'basic_string_field')
368////////////////////
369
370////////////////////
371addBlock('array_number', '배열 %1 의 %2 번째 항목', {
372 color: EntryStatic.colorSet.block.default.HARDWARE,
373 outerLine: EntryStatic.colorSet.block.darken.HARDWARE
374}, {
375 params: [
376 {
377 type: 'Block',
378 accept: 'string'
379 },
380 {
381 type: 'Block',
382 accept: 'string'
383 }
384 ],
385 def: [
386 {
387 type: 'text',
388 params: [`['1', '2']`]
389 },
390 {
391 type: 'text',
392 params: ['1']
393 }
394 ],
395 map: {
396 ARRAY: 0,
397 NUM: 1
398 }
399}, 'text', (sprite, script) => {
400 let array = eval(script.getValue('ARRAY', script))
401 let done = array[script.getValue('NUM', script) - 1]
402 return done
403}, 'basic_string_field');
404////////////////////
405
406////////////////////
407addBlock('json_length', 'JSON %1 의 항목 수', {
408 color: EntryStatic.colorSet.block.default.HARDWARE,
409 outerLine: EntryStatic.colorSet.block.darken.HARDWARE
410}, {
411 params: [
412 {
413 type: 'Block',
414 accept: 'string'
415 },
416 {
417 type: 'Block',
418 accept: 'string'
419 }
420 ],
421 def: [
422 {
423 type: 'text',
424 params: [`{ 'title': 'Hello, world!' }`]
425 },
426 {
427 type: 'text',
428 params: ['title']
429 }
430 ],
431 map: {
432 JSON: 0
433 }
434}, 'text', (sprite, script) => {
435 let done = Object.keys(JSON.parse(script.getValue('JSON', script))).length
436 return done
437}, 'basic_string_field')
438////////////////////
439
440////////////////////
441addBlock('json_key', 'JSON %1 의 %2 항목', {
442 color: EntryStatic.colorSet.block.default.HARDWARE,
443 outerLine: EntryStatic.colorSet.block.darken.HARDWARE
444}, {
445 params: [
446 {
447 type: 'Block',
448 accept: 'string'
449 },
450 {
451 type: 'Block',
452 accept: 'string'
453 }
454 ],
455 def: [
456 {
457 type: 'text',
458 params: [`{ 'title': 'Hello, world!' }`]
459 },
460 {
461 type: 'text',
462 params: ['title']
463 }
464 ],
465 map: {
466 JSON: 0,
467 KEY: 1
468 }
469}, 'text', (sprite, script) => {
470 let array = eval(script.getValue('JSON', script))
471 let done = array[script.getValue('KEY', script)]
472 return done
473}, 'basic_string_field')
474////////////////////
475
476////////////////////
477addBlock('array_length', '배열 %1 의 항목 수', {
478 color: EntryStatic.colorSet.block.default.HARDWARE,
479 outerLine: EntryStatic.colorSet.block.darken.HARDWARE
480}, {
481 params: [
482 {
483 type: 'Block',
484 accept: 'string'
485 }
486 ],
487 def: [
488 {
489 type: 'text',
490 params: [`['1', '2']`]
491 }
492 ],
493 map: {
494 ARRAY: 0
495 }
496}, 'text', (sprite, script) => {
497 let done = eval(script.getValue('ARRAY', script)).length
498 return done
499}, 'basic_string_field')
500////////////////////
501
502////////////////////
503addBlock('toast', '%1 제목과 %2 내용의 %3 토스트를 %4 출력하기%5', {
504 color: EntryStatic.colorSet.block.default.HARDWARE,
505 outerLine: EntryStatic.colorSet.block.darken.HARDWARE
506}, {
507 params: [
508 {
509 type: 'Block',
510 accept: 'string'
511 },
512 {
513 type: 'Block',
514 accept: 'string'
515 },
516 {
517 type: 'Dropdown',
518 options: [
519 ['성공', 'success'],
520 ['경고', 'warning'],
521 ['오류', 'alert']
522 ],
523 fontSize: 11,
524 arrowColor: '#FFD974',
525 value: 'success'
526 },
527 {
528 type: 'Dropdown',
529 options: [
530 ['유지되게', 'true'],
531 ['잠시 뒤 사라지게', 'false']
532 ],
533 fontSize: 11,
534 arrowColor: '#FFD974',
535 value: 'true'
536 },
537 {
538 type: 'Indicator',
539 img: 'block_icon/hardware_icon.svg',
540 size: 11,
541 }
542 ],
543 def: [
544 {
545 type: 'text',
546 params: [`알림`]
547 },
548 {
549 type: 'text',
550 params: [`엔트리`]
551 },
552 null,
553 null,
554 null
555 ],
556 map: {
557 TITLE: 0,
558 CONTENT: 1,
559 TYPE: 2,
560 HIDE: 3
561 }
562}, 'text', (sprite, script) => {
563 let hide
564 if (script.getValue('HIDE', script) == 'true') {
565 hide = true
566 } else {
567 hide = false
568 }
569 eval(`Entry.toast.${script.getValue('TYPE', script)}('${script.getValue('TITLE', script)}', '${script.getValue('CONTENT', script)}', ${hide})`)
570 return script.callReturn()
571})
572////////////////////
573
574////////////////////
575addBlock('console', '%1 내용을 브라우저 콘솔에 %2 하기%3', {
576 color: EntryStatic.colorSet.block.default.HARDWARE,
577 outerLine: EntryStatic.colorSet.block.darken.HARDWARE
578}, {
579 params: [
580 {
581 type: 'Block',
582 accept: 'string'
583 },
584 {
585 type: 'Dropdown',
586 options: [
587 ['log', 'log'],
588 ['warn', 'warn'],
589 ['error', 'error'],
590 ['info', 'info']
591 ],
592 fontSize: 11,
593 arrowColor: '#FFD974',
594 value: 'log'
595 },
596 {
597 type: 'Indicator',
598 img: 'block_icon/hardware_icon.svg',
599 size: 11,
600 }
601 ],
602 def: [
603 {
604 type: 'text',
605 params: [`엔트리`]
606 },
607 null,
608 null
609 ],
610 map: {
611 CONTENT: 0,
612 TYPE: 1
613 }
614}, 'text', (sprite, script) => {
615 eval(`console.${script.getValue('TYPE', script)}('${script.getValue('CONTENT', script)}')`)
616 return script.callReturn()
617})
618////////////////////
619
620////////////////////
621addBlock('console_clear', '브라우저 콘솔 모두 지우기%1', {
622 color: EntryStatic.colorSet.block.default.HARDWARE,
623 outerLine: EntryStatic.colorSet.block.darken.HARDWARE
624}, {
625 params: [
626 {
627 type: 'Indicator',
628 img: 'block_icon/hardware_icon.svg',
629 size: 11,
630 }
631 ],
632 def: [
633 null
634 ],
635 map: {}
636}, 'text', (sprite, script) => {
637 console.clear()
638 return script.callReturn()
639})
640////////////////////
641
642////////////////////
643addBlock('entry_console', '%1 내용을 엔트리 콘솔에 출력하기%2', {
644 color: EntryStatic.colorSet.block.default.HARDWARE,
645 outerLine: EntryStatic.colorSet.block.darken.HARDWARE
646}, {
647 params: [
648 {
649 type: 'Block',
650 accept: 'string'
651 },
652 {
653 type: 'Indicator',
654 img: 'block_icon/hardware_icon.svg',
655 size: 11,
656 }
657 ],
658 def: [
659 {
660 type: 'text',
661 params: [`엔트리`]
662 },
663 null
664 ],
665 map: {
666 CONTENT: 0
667 }
668}, 'text', (sprite, script) => {
669 Entry.console.print(script.getValue('CONTENT', script))
670 return script.callReturn()
671})
672////////////////////
673
674////////////////////
675addBlock('entry_console_clear', '엔트리 콘솔 모두 지우기%1', {
676 color: EntryStatic.colorSet.block.default.HARDWARE,
677 outerLine: EntryStatic.colorSet.block.darken.HARDWARE
678}, {
679 params: [
680 {
681 type: 'Indicator',
682 img: 'block_icon/hardware_icon.svg',
683 size: 11,
684 }
685 ],
686 def: [
687 null
688 ],
689 map: {}
690}, 'text', (sprite, script) => {
691 Entry.console.clear()
692 return script.callReturn()
693})
694////////////////////
695
696////////////////////
697addBlock('get_browser', '브라우저 이름', {
698 color: EntryStatic.colorSet.block.default.HARDWARE,
699 outerLine: EntryStatic.colorSet.block.darken.HARDWARE
700}, {
701 params: [],
702 def: [],
703 map: {}
704}, 'text', (sprite, script) => {
705 return Entry.userAgent
706}, 'basic_string_field')
707////////////////////
708
709////////////////////
710addBlock('change_var', '%1 값을 %2 으로 변경%3', {
711 color: EntryStatic.colorSet.block.default.HARDWARE,
712 outerLine: EntryStatic.colorSet.block.darken.HARDWARE
713}, {
714 params: [
715 {
716 type: 'Block',
717 accept: 'string'
718 },
719 {
720 type: 'Block',
721 accept: 'string'
722 },
723 {
724 type: 'Indicator',
725 img: 'block_icon/hardware_icon.svg',
726 size: 11,
727 }
728 ],
729 def: [
730 {
731 type: 'text',
732 params: [`user.username`]
733 },
734 {
735 type: 'text',
736 params: ['entry']
737 },
738 null
739 ],
740 map: {
741 VARNAME: 0,
742 VALUE: 1
743 }
744}, 'text', (sprite, script) => {
745 eval(`${script.getValue('VARNAME', script)} = '${script.getValue('VALUE', script)}'`)
746 return script.callReturn()
747});
748////////////////////
749
750////////////////////
751addBlock('post_commu', '%1 제목과 %2 내용의 글을 엔커뮤에 올리기%3', {
752 color: EntryStatic.colorSet.block.default.HARDWARE,
753 outerLine: EntryStatic.colorSet.block.darken.HARDWARE
754}, {
755 params: [
756 {
757 type: 'Block',
758 accept: 'string'
759 },
760 {
761 type: 'Block',
762 accept: 'string'
763 },
764 {
765 type: 'Indicator',
766 img: 'block_icon/hardware_icon.svg',
767 size: 11,
768 }
769 ],
770 def: [
771 {
772 type: 'text',
773 params: [`엔트리봇`]
774 },
775 {
776 type: 'text',
777 params: [`사랑스러워`]
778 },
779 null
780 ],
781 map: {
782 TITLE: 0,
783 CONTENT: 1
784 }
785}, 'text', (sprite, script) => {
786 fetch('https://playentry.org/api/discuss/', {
787 method: 'POST',
788 body: `{ "images": [], "category": "free", "title": "${script.getValue('TITLE', script)}", "content": "${script.getValue('CONTENT', script)}", "groupNotice": ture }`,
789 headers: {
790 'Content-Type': 'application/json'
791 }
792 })
793 return script.callReturn()
794})
795////////////////////
796
797
798// 블록 추가 끝
799
800
801
802Entry.staticBlocks.push({
803 category: 'API', blocks: [
804 'fetch',
805 'array_number',
806 'array_length',
807 'json_key',
808 'json_length',
809 'post_commu',
810 'get_browser',
811 'toast',
812 'console',
813 'console_clear',
814 'entry_console',
815 'entry_console_clear',
816 'change_var'
817 ]
818});
819
820
821updateCategory('API')
822
823$('head').append(`
824<style>
825#entryCategoryAPI {
826 background-image: url(/lib/entry-js/images/hardware.svg);
827 background-repeat: no-repeat;
828 border-bottom-right-radius: 6px;
829 border-bottom-left-radius: 6px;
830 margin-bottom: 1px;
831}
832.entrySelectedCategory#entryCategoryAPI {
833 background-image: url(/lib/entry-js/images/hardware_on.svg);
834 background-color: #00b6b1;
835 border-color: #00b6b1;
836 color: #fff;
837}
838#entryCategoryarduino {
839 display: none;
840}
841</style>
842`)
843
844$('#entryCategoryAPI').append('기타')