[fix] Blockly のアップデートに伴って動かなくなっていたブロックを修正

This commit is contained in:
ocogeclub 2022-01-11 14:03:17 +09:00
parent eedad643c0
commit a91f8f1168
5 changed files with 720 additions and 452 deletions

View File

@ -1,20 +1,7 @@
/** /**
* Blockly Demos: Custom Dialogs * @license
* * Copyright 2016 Google LLC
* Copyright 2016 Google Inc. * SPDX-License-Identifier: Apache-2.0
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
/** /**
@ -26,16 +13,16 @@
*/ */
CustomDialog = {}; CustomDialog = {};
/** Override Blockly.alert() with custom implementation. */ /** Override Blockly.dialog.alert() with custom implementation. */
Blockly.alert = function(message, callback) { Blockly.dialog.setAlert(function(message, callback) {
console.log('Alert: ' + message); console.log('Alert: ' + message);
CustomDialog.show('Alert', message, { CustomDialog.show('Alert', message, {
onCancel: callback onCancel: callback
}); });
}; });
/** Override Blockly.confirm() with custom implementation. */ /** Override Blockly.dialog.confirm() with custom implementation. */
Blockly.confirm = function(message, callback) { Blockly.dialog.setConfirm(function(message, callback) {
console.log('Confirm: ' + message); console.log('Confirm: ' + message);
CustomDialog.show('Confirm', message, { CustomDialog.show('Confirm', message, {
showOkay: true, showOkay: true,
@ -47,10 +34,10 @@ Blockly.confirm = function(message, callback) {
callback(false); callback(false);
} }
}); });
}; });
/** Override Blockly.prompt() with custom implementation. */ /** Override Blockly.dialog.prompt() with custom implementation. */
Blockly.prompt = function(message, defaultValue, callback) { Blockly.dialog.setPrompt(function(message, defaultValue, callback) {
console.log('Prompt: ' + message); console.log('Prompt: ' + message);
CustomDialog.show('Prompt', message, { CustomDialog.show('Prompt', message, {
showInput: true, showInput: true,
@ -64,7 +51,7 @@ Blockly.prompt = function(message, defaultValue, callback) {
} }
}); });
CustomDialog.inputField.value = defaultValue; CustomDialog.inputField.value = defaultValue;
}; });
/** Hides any currently visible dialog. */ /** Hides any currently visible dialog. */
CustomDialog.hide = function() { CustomDialog.hide = function() {
@ -146,11 +133,11 @@ CustomDialog.show = function(title, message, options) {
dialogInput.focus(); dialogInput.focus();
dialogInput.onkeyup = function(event) { dialogInput.onkeyup = function(event) {
if (event.keyCode == 13) { if (event.keyCode === 13) {
// Process as OK when user hits enter. // Process as OK when user hits enter.
onOkay(); onOkay();
return false; return false;
} else if (event.keyCode == 27) { } else if (event.keyCode === 27) {
// Process as cancel when user hits esc. // Process as cancel when user hits esc.
onCancel(); onCancel();
return false; return false;

View File

@ -103,6 +103,29 @@
<field name="MODE">WHILE</field> <field name="MODE">WHILE</field>
</block> </block>
<block type="ugj_control_for"> <block type="ugj_control_for">
<field name="crease">+</field>
<value name="index">
<block type="variables_get">
<field name="VAR" id="CP-q*|4;)+PZj!ExWdjr">番号</field>
</block>
</value>
<value name="from">
<shadow type="math_number">
<field name="NUM">1</field>
</shadow>
</value>
<value name="to">
<shadow type="math_number">
<field name="NUM">10</field>
</shadow>
</value>
<value name="by">
<shadow type="math_number">
<field name="NUM">1</field>
</shadow>
</value>
</block>
<!-- <block type="ugj_control_for">
<field name="index" id="[0Dv+s57IrE5bItrMx6V">番号</field> <field name="index" id="[0Dv+s57IrE5bItrMx6V">番号</field>
<field name="crease">+</field> <field name="crease">+</field>
<value name="from"> <value name="from">
@ -120,9 +143,16 @@
<field name="NUM">1</field> <field name="NUM">1</field>
</shadow> </shadow>
</value> </value>
</block> </block> -->
<block type="ugj_controls_forEach"> <!-- <block type="ugj_controls_forEach">
<field name="item" id="~!WaafBNY_R,9DB`?.cd" variabletype="">項目</field> <field name="item" id="~!WaafBNY_R,9DB`?.cd" variabletype="">項目</field>
</block> -->
<block type="ugj_controls_foreach">
<value name="item">
<block type="variables_get">
<field name="VAR" id="}LJbKt^CxR.FJ6a3T23v">項目</field>
</block>
</value>
</block> </block>
<block type="controls_flow_statements"> <block type="controls_flow_statements">
<field name="FLOW">BREAK</field> <field name="FLOW">BREAK</field>
@ -488,7 +518,14 @@
<category name="センサー" css-icon="customIcon fas fa-microchip" categorystyle="sensor_category"> <category name="センサー" css-icon="customIcon fas fa-microchip" categorystyle="sensor_category">
<label text="温湿度気圧センサー BME280" web-line="4.0" web-line-width="200"></label> <label text="温湿度気圧センサー BME280" web-line="4.0" web-line-width="200"></label>
<block type="ugj_bme280"> <block type="ugj_bme280">
<field name="temp" id="4iysIXd|f$Jj$9hZ(R_H">気温</field> <field name="addr">0x76</field>
</block>
<block type="ugj_bme280_data">
<field name="thp">0</field>
</block>
<!-- <block type="ugj_bme280">
<field name="temp">気温</field>
<field name="hum" id="IT?JH;IRcsGP.8I%aEgw">湿度</field> <field name="hum" id="IT?JH;IRcsGP.8I%aEgw">湿度</field>
<field name="pres" id="I^GLkF^Z3#x2F0ho%J[?">気圧</field> <field name="pres" id="I^GLkF^Z3#x2F0ho%J[?">気圧</field>
<value name="address"> <value name="address">
@ -500,7 +537,7 @@
</value> </value>
</shadow> </shadow>
</value> </value>
</block> </block> -->
<label text="ジェスチャーセンサー PAJ7620" web-line="4.0" web-line-width="200"></label> <label text="ジェスチャーセンサー PAJ7620" web-line="4.0" web-line-width="200"></label>
<block type="ugj_gesture_init"> <block type="ugj_gesture_init">
<value name="i2c_addr"> <value name="i2c_addr">
@ -635,9 +672,17 @@
</block> </block>
<block type="ugj_canvas_finalize"></block> <block type="ugj_canvas_finalize"></block>
<label text="イベント" web-line="4.0" web-line-width="200"></label> <label text="イベント" web-line="4.0" web-line-width="200"></label>
<block type="ugj_event_key"> <!-- <block type="ugj_event_key">
<field name="key" id="MRLP/?IZ:[U}[AV@bf6%" variabletype="">キー</field> <field name="key" id="MRLP/?IZ:[U}[AV@bf6%" variabletype="">キー</field>
<field name="updown">keydown</field> <field name="updown">keydown</field>
</block> -->
<block type="ugj_event_key">
<field name="updown">keydown</field>
<value name="key">
<block type="variables_get">
<field name="VAR" id="Tf-2_OhUEAcOe;U}wu%I">キー</field>
</block>
</value>
</block> </block>
<label text="色" web-line="4.0" web-line-width="200"></label> <label text="色" web-line="4.0" web-line-width="200"></label>
<block type="colour_picker"> <block type="colour_picker">
@ -671,11 +716,15 @@
</block> </block>
<block type="ugj_face_init"></block> <block type="ugj_face_init"></block>
<block type="ugj_face_display"></block> <block type="ugj_face_display"></block>
<block type="ugj_face_detect"> <!-- <block type="ugj_face_detect">
<field name="x" id="TF-ziC[]OAJ9]r}YjUQg" variabletype=""></field> <field name="x" id="TF-ziC[]OAJ9]r}YjUQg" variabletype=""></field>
<field name="y" id="]G:_%S*1v4!9_+yx532d" variabletype=""></field> <field name="y" id="]G:_%S*1v4!9_+yx532d" variabletype=""></field>
<field name="w" id="wP$LdeXDCiWzrI!/9R)G" variabletype=""></field> <field name="w" id="wP$LdeXDCiWzrI!/9R)G" variabletype=""></field>
<field name="h" id="8+E.-dP-Omt}v2~DCC]M" variabletype="">高さ</field> <field name="h" id="8+E.-dP-Omt}v2~DCC]M" variabletype="">高さ</field>
</block> -->
<block type="ugj_face_detect"></block>
<block type="ugj_face_coord">
<field name="face_coord">0</field>
</block> </block>
<block type="ugj_face_drawrect"></block> <block type="ugj_face_drawrect"></block>
<label text="_" web-line="4.0" web-line-width="200"></label> <label text="_" web-line="4.0" web-line-width="200"></label>
@ -713,13 +762,25 @@
</value> </value>
</block> </block>
<label text="サーバー" web-line="4.0" web-line-width="200"></label> <label text="サーバー" web-line="4.0" web-line-width="200"></label>
<block type="ugj_network_httpserver"> <!-- <block type="ugj_network_httpserver">
<field name="URL" id="fIVY=P=^1=p?6=+h:,Dt" variabletype="">url</field> <field name="URL" id="fIVY=P=^1=p?6=+h:,Dt" variabletype="">url</field>
<value name="response"> <value name="response">
<shadow type="text"> <shadow type="text">
<field name="TEXT">オコゲ</field> <field name="TEXT">オコゲ</field>
</shadow> </shadow>
</value> </value>
</block> -->
<block type="ugj_network_httpserver">
<value name="url">
<block type="variables_get">
<field name="VAR" id="b`}7sB~6O9+IKJ!vJzA`">URL</field>
</block>
</value>
<value name="response">
<shadow type="text">
<field name="TEXT">オコゲ</field>
</shadow>
</value>
</block> </block>
<label text="ウェブチャット" web-line="4.0" web-line-width="200"></label> <label text="ウェブチャット" web-line="4.0" web-line-width="200"></label>
<block type="ugj_library_load"> <block type="ugj_library_load">
@ -730,18 +791,43 @@
<block type="ugj_webchat"></block> <block type="ugj_webchat"></block>
<block type="ugj_getusermedia"></block> <block type="ugj_getusermedia"></block>
<block type="ugj_skyway_newpeer"> <block type="ugj_skyway_newpeer">
<field name="my_id">自分のID</field> <value name="my_id">
<block type="variables_get">
<field name="VAR" id="*;kYz5q$=N`hBZ$%/Gyb">自分のID</field>
</block>
</value>
</block> </block>
<block type="ugj_skyway_called"></block> <block type="ugj_skyway_called"></block>
<block type="ugj_skyway_events"> <!-- <block type="ugj_skyway_events">
<field name="remote_id" id="0H.)5,:R#6)mx{rc2O.6" variabletype="">相手のID</field> <field name="remote_id" id="0H.)5,:R#6)mx{rc2O.6" variabletype="">相手のID</field>
</block> -->
<block type="ugj_skyway_events">
<value name="remote_id">
<block type="variables_get">
<field name="VAR" id="lN*;t*HFF;@[)a_m3#F8">相手のID</field>
</block>
</value>
</block> </block>
<block type="ugj_skyway_eventopen"></block> <block type="ugj_skyway_eventopen"></block>
<block type="ugj_skyway_eventdata"> <!-- <block type="ugj_skyway_eventdata">
<field name="data" id="q[DF.B~59aE(90^posFt" variabletype="">発言</field> <field name="data" id="q[DF.B~59aE(90^posFt" variabletype="">発言</field>
</block> </block>
<block type="ugj_skyway_eventsend"> <block type="ugj_skyway_eventsend">
<field name="data" id="vN/_]nnKA$wVHSxh2_9f" variabletype="">内容</field> <field name="data" id="vN/_]nnKA$wVHSxh2_9f" variabletype="">内容</field>
</block> -->
<block type="ugj_skyway_eventdata">
<value name="data">
<block type="variables_get">
<field name="VAR" id="l[-u+nGf?P~Zu?k(bgP)">発言</field>
</block>
</value>
</block>
<block type="ugj_skyway_eventsend">
<value name="data">
<block type="variables_get">
<field name="VAR" id="NbC3[s+Uilk#moos+bn8">内容</field>
</block>
</value>
</block> </block>
<label text="_" web-line="4.0" web-line-width="200"></label> <label text="_" web-line="4.0" web-line-width="200"></label>
</category> </category>
@ -759,13 +845,25 @@
</shadow> </shadow>
</value> </value>
</block> </block>
<block type="ugj_event_answer"> <!-- <block type="ugj_event_answer">
<field name="answer" id="_m@Uj#wHnIuGJNVwdUR+" variabletype="">答え</field> <field name="answer" id="_m@Uj#wHnIuGJNVwdUR+" variabletype="">答え</field>
<value name="question"> <value name="question">
<shadow type="text"> <shadow type="text">
<field name="TEXT">お名前は?</field> <field name="TEXT">お名前は?</field>
</shadow> </shadow>
</value> </value>
</block> -->
<block type="ugj_event_answer">
<value name="question">
<shadow type="text">
<field name="TEXT">お名前は?</field>
</shadow>
</value>
<value name="answer">
<block type="variables_get">
<field name="VAR" id=":w)sl|yxx4k^W-~-VM#,">答え</field>
</block>
</value>
</block> </block>
<block type="ugj_blackboard_show"></block> <block type="ugj_blackboard_show"></block>
<block type="ugj_blackboard_write"> <block type="ugj_blackboard_write">
@ -786,7 +884,6 @@
<block type="ugj_blackboard_content"></block> <block type="ugj_blackboard_content"></block>
<block type="ugj_clearblackboard"></block> <block type="ugj_clearblackboard"></block>
<block type="ugj_control_button"> <block type="ugj_control_button">
<field name="title" id="j{fM0uCAB9~3y=|~dd?:" variabletype="">ツールチップ</field>
<value name="label"> <value name="label">
<shadow type="text"> <shadow type="text">
<field name="TEXT">ボタン1</field> <field name="TEXT">ボタン1</field>
@ -799,12 +896,12 @@
</value> </value>
<value name="bgcolor"> <value name="bgcolor">
<shadow type="colour_picker"> <shadow type="colour_picker">
<field name="COLOUR">#00cccc</field> <field name="COLOUR">#999999</field>
</shadow> </shadow>
</value> </value>
<value name="title"> <value name="title">
<shadow type="text"> <shadow type="text">
<field name="TEXT">データの保存に使えます。</field> <field name="TEXT">ここをクリック</field>
</shadow> </shadow>
</value> </value>
</block> </block>
@ -859,10 +956,18 @@
<block type="ugj_special_clearinterval"></block> <block type="ugj_special_clearinterval"></block>
<label text="プロセス" web-line="4.0" web-line-width="200"></label> <label text="プロセス" web-line="4.0" web-line-width="200"></label>
<block type="ugj_spawnsync"> <block type="ugj_spawnsync">
<field name="data" id="^B.zQ~+BcS!dKNmb,+AX" variabletype="">実行結果</field> <value name="data">
<block type="variables_get">
<field name="VAR" id="9z28J37fMu2VaWhbd4*=">実行結果</field>
</block>
</value>
</block> </block>
<block type="ugj_spawn"> <block type="ugj_spawn">
<field name="data" id=")H{jxG09B6}[PcO%4H1d" variabletype="">データ</field> <value name="data">
<block type="variables_get">
<field name="VAR" id=";i*e;NG!%_g}7}wTeaQc">データストリーム</field>
</block>
</value>
</block> </block>
<block type="ugj_child_julius"></block> <block type="ugj_child_julius"></block>
<block type="aquestalk_pi"> <block type="aquestalk_pi">
@ -946,7 +1051,12 @@
<category name="スニペット" css-icon="customIcon fas fa-egg" categorystyle="snippets_category"> <category name="スニペット" css-icon="customIcon fas fa-egg" categorystyle="snippets_category">
<label text="入出力" web-line="4.0" web-line-width="200"></label> <label text="入出力" web-line="4.0" web-line-width="200"></label>
<block type="ugj_event_answer"> <block type="ugj_event_answer">
<field name="answer" id="_m@Uj#wHnIuGJNVwdUR+" variabletype="">答え</field> <!-- <field name="answer" id="_m@Uj#wHnIuGJNVwdUR+" variabletype="">答え</field> -->
<value name="answer">
<block type="variables_get">
<field name="VAR" id=":w)sl|yxx4k^W-~-VM#,">答え</field>
</block>
</value>
<value name="question"> <value name="question">
<shadow type="text"> <shadow type="text">
<field name="TEXT">お名前は?</field> <field name="TEXT">お名前は?</field>
@ -978,7 +1088,7 @@
<mutation items="2"></mutation> <mutation items="2"></mutation>
<value name="ADD0"> <value name="ADD0">
<block type="variables_get"> <block type="variables_get">
<field name="VAR" id="_m@Uj#wHnIuGJNVwdUR+">答え</field> <field name="VAR" id=":w)sl|yxx4k^W-~-VM#,">答え</field>
</block> </block>
</value> </value>
<value name="ADD1"> <value name="ADD1">
@ -1002,7 +1112,13 @@
</statement> </statement>
</block> </block>
<block type="testblock">
<value name="foo">
<block type="variables_get">
<field name="VAR" id="BJ[VyIz4wdz@n~=d=b+X">変数</field>
</block>
</value>
</block>
</category> </category>
</xml> </xml>
@ -1011,13 +1127,13 @@
<script src="./google-blockly/python_compressed.js"></script> <script src="./google-blockly/python_compressed.js"></script>
<script src="./google-blockly/blocks_compressed.js"></script> <script src="./google-blockly/blocks_compressed.js"></script>
<script src="./google-blockly/msg/js/ja.js"></script> <script src="./google-blockly/msg/js/ja.js"></script>
<script src="./lib/custom-dialog.js"></script> <script src="./google-blockly/custom-dialog.js"></script>
<script src="./ugj_blocks.js"></script> <script src="./ugj_blocks.js"></script>
<script src="./index_elutil.js"></script> <script src="./index_elutil.js"></script>
<script src="./index.js"></script> <script src="./index.js"></script>
<script src="./lib/beautify.min.js"></script> <script src="./lib/beautify.min.js"></script>
<script src="./lib/prettify.js"></script> <script src="./lib/prettify.js"></script>
<!-- <script src="./.shared/skyway_key.js"></script> --> <script src="./.shared/skyway_key.js"></script>
</body> </body>
</html> </html>

View File

@ -313,7 +313,7 @@ const ugj_saveWorkspaceToFile = async () => {
let xml = Blockly.Xml.workspaceToDom(workspace); let xml = Blockly.Xml.workspaceToDom(workspace);
let xml_text = Blockly.Xml.domToText(xml); let xml_text = Blockly.Xml.domToText(xml);
if (await elutil.saveWsFile(xml_text) === false) { if (await elutil.saveWsFile(xml_text) === false) {
alert('保存できませんでした。'); window.alert('保存できませんでした。');
} }
} }
const ugj_loadWorkspaceFromFile = async () => { const ugj_loadWorkspaceFromFile = async () => {
@ -410,7 +410,7 @@ const ugj_runCode = async () => {
// await eval(code).catch(e => { alert(e); }); // await eval(code).catch(e => { alert(e); });
let AsyncFunction = Object.getPrototypeOf(async function () { }).constructor let AsyncFunction = Object.getPrototypeOf(async function () { }).constructor
let ocogeFunc = new AsyncFunction(ugj_createCode({})); let ocogeFunc = new AsyncFunction(ugj_createCode({}));
await ocogeFunc().catch(e => { alert(e); }); await ocogeFunc().catch(e => { window.alert(e); });
console.log('Code Execution done.'); console.log('Code Execution done.');
} }
@ -447,7 +447,7 @@ const ugj_showCode = () => {
if (chkbox_cli.checked && ext == 'js') if (chkbox_cli.checked && ext == 'js')
code = code.replace(/const appendDiv[^#]*\/\/#/gm, 'const blackboardWrite = text => console.log(text);').replace('window.alert', 'console.log').replace(/ugj_fukidashi(.*), \d+(\);)/gm, 'console.log$1$2').replace(/(^(?=.*document.)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*ugj_)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*elutil.)[^;]*;)/gm, '/* $1 */'); code = code.replace(/const appendDiv[^#]*\/\/#/gm, 'const blackboardWrite = text => console.log(text);').replace('window.alert', 'console.log').replace(/ugj_fukidashi(.*), \d+(\);)/gm, 'console.log$1$2').replace(/(^(?=.*document.)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*ugj_)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*elutil.)[^;]*;)/gm, '/* $1 */');
if (elutil.saveFile(code, ext) === false) { if (elutil.saveFile(code, ext) === false) {
alert('保存できませんでした。'); window.alert('保存できませんでした。');
} }
close_cb(); close_cb();
} }

16
lib/skyway.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,67 +1,94 @@
/** Fix Basic Blocks ****************************************************************************************/ /** Fix Basic Blocks ****************************************************************************************/
var ugjConsrolForDefinition = { // var ugjConsrolForDefinition = {
"type": "ugj_control_for", // "type": "ugj_control_for",
"message0": "%{BKY_UGJ_CONTROL_FOR_TITLE}", // "message0": "%{BKY_UGJ_CONTROL_FOR_TITLE}",
"args0": [ // "args0": [
{ // {
"type": "field_variable", // "type": "field_variable",
"name": "index", // "name": "index",
"variable": "%{BKY_UGJ_CONTROL_FOR_INDEX}" // "variable": "%{BKY_UGJ_CONTROL_FOR_INDEX}"
}, // },
{ // {
"type": "input_dummy" // "type": "input_dummy"
}, // },
{ // {
"type": "input_value", // "type": "input_value",
"name": "from", // "name": "from",
"check": "Number" // "check": "Number"
}, // },
{ // {
"type": "input_value", // "type": "input_value",
"name": "to", // "name": "to",
"check": "Number" // "check": "Number"
}, // },
{ // {
"type": "input_value", // "type": "input_value",
"name": "by", // "name": "by",
"check": "Number" // "check": "Number"
}, // },
{ // {
"type": "field_dropdown", // "type": "field_dropdown",
"name": "crease", // "name": "crease",
"options": [ // "options": [
[ // [
"%{BKY_UGJ_CONTROL_FOR_INCREASE}", // "%{BKY_UGJ_CONTROL_FOR_INCREASE}",
"+" // "+"
], // ],
[ // [
"%{BKY_UGJ_CONTROL_FOR_DECREASE}", // "%{BKY_UGJ_CONTROL_FOR_DECREASE}",
"-" // "-"
] // ]
] // ]
}, // },
{ // {
"type": "input_dummy" // "type": "input_dummy"
}, // },
{ // {
"type": "input_statement", // "type": "input_statement",
"name": "do" // "name": "do"
} // }
], // ],
"inputsInline": true, // "inputsInline": true,
"previousStatement": null, // "previousStatement": null,
"nextStatement": null, // "nextStatement": null,
"tooltip": "%{BKY_UGJ_CONTROL_FOR_TOOLTIP}", // "tooltip": "%{BKY_UGJ_CONTROL_FOR_TOOLTIP}",
"helpUrl": "", // "helpUrl": "",
"style": "loop_blocks" // "style": "loop_blocks"
}; // };
// Blockly.Blocks['ugj_control_for'] = {
// init: function () {
// this.jsonInit(ugjConsrolForDefinition);
// }
// };
Blockly.Blocks['ugj_control_for'] = { Blockly.Blocks['ugj_control_for'] = {
init: function () { init: function () {
this.jsonInit(ugjConsrolForDefinition); this.appendValueInput("index")
.setCheck("Variable");
this.appendValueInput("from")
.setCheck("Number")
.appendField("を");
this.appendValueInput("to")
.setCheck("Number")
.appendField("から");
this.appendValueInput("by")
.setCheck("Number")
.appendField("まで");
this.appendDummyInput()
.appendField("ずつ")
.appendField(new Blockly.FieldDropdown([["増やして", "+"], ["減らして", "-"]]), "crease");
this.appendStatementInput("do")
.setCheck(null);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("インデックス番号を決められた数ずつ増やし(減らし)ながら、ステートメントを実行します。");
this.setHelpUrl("");
this.setStyle('loop_blocks');
} }
}; };
Blockly.JavaScript['ugj_control_for'] = function (block) { Blockly.JavaScript['ugj_control_for'] = function (block) {
var variable_index = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('index'), Blockly.Variables.NAME_TYPE); var value_index = Blockly.JavaScript.valueToCode(block, 'index', Blockly.JavaScript.ORDER_ATOMIC);
// var variable_index = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('index'), Blockly.Variables.NAME_TYPE);
var value_from = Blockly.JavaScript.valueToCode(block, 'from', Blockly.JavaScript.ORDER_ATOMIC); var value_from = Blockly.JavaScript.valueToCode(block, 'from', Blockly.JavaScript.ORDER_ATOMIC);
var value_to = Blockly.JavaScript.valueToCode(block, 'to', Blockly.JavaScript.ORDER_ATOMIC); var value_to = Blockly.JavaScript.valueToCode(block, 'to', Blockly.JavaScript.ORDER_ATOMIC);
var value_by = Blockly.JavaScript.valueToCode(block, 'by', Blockly.JavaScript.ORDER_ATOMIC); var value_by = Blockly.JavaScript.valueToCode(block, 'by', Blockly.JavaScript.ORDER_ATOMIC);
@ -71,7 +98,7 @@ Blockly.JavaScript['ugj_control_for'] = function (block) {
if (dropdown_crease == '+') { daishou = '<'; } if (dropdown_crease == '+') { daishou = '<'; }
else { daishou = '>'; } else { daishou = '>'; }
var code = [ var code = [
`for (${variable_index} = ${value_from}; ${variable_index} ${daishou}= ${value_to}; ${variable_index} ${dropdown_crease}= ${Math.abs(value_by)}) {`, `for (${value_index} = ${value_from}; ${value_index} ${daishou}= ${value_to}; ${value_index} ${dropdown_crease}= ${Math.abs(value_by)}) {`,
statements_do, statements_do,
`}`, `}`,
'' ''
@ -96,66 +123,99 @@ Blockly.Python['ugj_control_for'] = function (block) {
return code; return code;
}; };
var ugjForEachDefinition = { // var ugjForEachDefinition = {
"type": "ugj_controls_foreach", // "type": "ugj_controls_foreach",
"message0": "%{BKY_UGJ_FOREACH_TITLE}", // "message0": "%{BKY_UGJ_FOREACH_TITLE}",
"args0": [ // "args0": [
{ // {
"type": "input_value", // "type": "input_value",
"name": "list", // "name": "list",
"check": "Array" // "check": "Array"
}, // },
{ // {
"type": "field_variable", // "type": "field_variable",
"name": "item", // "name": "item",
"variable": "%{BKY_UGJ_FOREACH_ITEM}" // "variable": "%{BKY_UGJ_FOREACH_ITEM}"
}, // },
{ // {
"type": "input_dummy" // "type": "input_dummy"
}, // },
{ // {
"type": "input_statement", // "type": "input_statement",
"name": "do" // "name": "do"
} // }
], // ],
"inputsInline": true, // "inputsInline": true,
"previousStatement": null, // "previousStatement": null,
"nextStatement": null, // "nextStatement": null,
"style": "loop_blocks", // "style": "loop_blocks",
"tooltip": "%{BKY_UGJ_FOREACH_TOOLTIP}", // "tooltip": "%{BKY_UGJ_FOREACH_TOOLTIP}",
"helpUrl": "" // "helpUrl": ""
} // }
Blockly.Blocks['ugj_controls_forEach'] = { // Blockly.Blocks['ugj_controls_forEach'] = {
// init: function () {
// this.jsonInit(ugjForEachDefinition);
// }
// };
Blockly.Blocks['ugj_controls_foreach'] = {
init: function () { init: function () {
this.jsonInit(ugjForEachDefinition); this.appendValueInput("list")
.setCheck("Array")
.appendField("リスト");
this.appendValueInput("item")
.setCheck("Variable")
.appendField("の各");
this.appendDummyInput()
.appendField("について");
this.appendStatementInput("do")
.setCheck(null);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("リストの各項目について、その項目の内容を変数「項目」に代入してステートメントを実行します。");
this.setHelpUrl("");
this.setStyle('loop_blocks');
} }
}; };
Blockly.JavaScript['ugj_controls_forEach'] = function (block) { Blockly.JavaScript['ugj_controls_foreach'] = function (block) {
var value_list = Blockly.JavaScript.valueToCode(block, 'list', Blockly.JavaScript.ORDER_ATOMIC); var value_list = Blockly.JavaScript.valueToCode(block, 'list', Blockly.JavaScript.ORDER_ATOMIC);
var variable_item = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('item'), Blockly.Variables.NAME_TYPE); var value_item = Blockly.JavaScript.valueToCode(block, 'item', Blockly.JavaScript.ORDER_ATOMIC);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do'); var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [ var code = [
`for (let _index in ${value_list}) {`, `for (let _index in ${value_list}) {`,
`${variable_item} = ${value_list}[_index];`, `${value_item} = ${value_list}[_index];`,
statements_do, statements_do,
`}`, `}`,
'' ''
].join('\n'); ].join('\n');
return code; return code;
}; };
Blockly.Python['ugj_controls_forEach'] = function (block) { // Blockly.JavaScript['ugj_controls_forEach'] = function (block) {
var value_list = Blockly.Python.valueToCode(block, 'list', Blockly.Python.ORDER_ATOMIC); // var value_list = Blockly.JavaScript.valueToCode(block, 'list', Blockly.JavaScript.ORDER_ATOMIC);
var variable_item = Blockly.Python.nameDB_.getName(block.getFieldValue('item'), Blockly.Variables.NAME_TYPE); // var variable_item = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('item'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.Python.statementToCode(block, 'do'); // var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
if (value_list === '') value_list = '[]'; // var code = [
if (statements_do === '') statements_do = ' pass'; // `for (let _index in ${value_list}) {`,
var code = [ // `${variable_item} = ${value_list}[_index];`,
`for ${variable_item} in ${value_list}:`, // statements_do,
statements_do, // `}`,
'' // ''
].join('\n'); // ].join('\n');
return code; // return code;
}; // };
// Blockly.Python['ugj_controls_forEach'] = function (block) {
// var value_list = Blockly.Python.valueToCode(block, 'list', Blockly.Python.ORDER_ATOMIC);
// var variable_item = Blockly.Python.nameDB_.getName(block.getFieldValue('item'), Blockly.Variables.NAME_TYPE);
// var statements_do = Blockly.Python.statementToCode(block, 'do');
// if (value_list === '') value_list = '[]';
// if (statements_do === '') statements_do = ' pass';
// var code = [
// `for ${variable_item} in ${value_list}:`,
// statements_do,
// ''
// ].join('\n');
// return code;
// };
// Custom Color Picker // Custom Color Picker
Blockly.FieldColour.COLOURS = [ Blockly.FieldColour.COLOURS = [
'#ffffff', '#808000', '#ffff00', '#ff00ff', '#ff4500', '#ffffff', '#808000', '#ffff00', '#ff00ff', '#ff4500',
@ -1071,84 +1131,133 @@ Blockly.Python['ugj_i2c_write_device'] = function (block) {
/********* */ /********* */
/** BME280 */ /** BME280 */
/********* */ /********* */
var ugjBme280Definition = { // var ugjBme280Definition = {
"type": "ugj_bme280", // "type": "ugj_bme280",
"message0": "%{BKY_UGJ_BME280_TITLE}", // "message0": "%{BKY_UGJ_BME280_TITLE}",
"args0": [ // "args0": [
{ // {
"type": "input_value", // "type": "input_value",
"name": "address", // "name": "address",
"check": "Number" // "check": "Number"
}, // },
{ // {
"type": "field_variable", // "type": "field_variable",
"name": "temp", // "name": "temp",
"variable": "%{BKY_UGJ_BME280_READ_TEMP}" // "variable": "%{BKY_UGJ_BME280_READ_TEMP}"
}, // },
{ // {
"type": "field_variable", // "type": "field_variable",
"name": "hum", // "name": "hum",
"variable": "%{BKY_UGJ_BME280_READ_HUM}" // "variable": "%{BKY_UGJ_BME280_READ_HUM}"
}, // },
{ // {
"type": "field_variable", // "type": "field_variable",
"name": "pres", // "name": "pres",
"variable": "%{BKY_UGJ_BME280_READ_PRES}" // "variable": "%{BKY_UGJ_BME280_READ_PRES}"
} // }
], // ],
"inputsInline": true, // "inputsInline": true,
"previousStatement": null, // "previousStatement": null,
"nextStatement": null, // "nextStatement": null,
"tooltip": "%{BKY_UGJ_BME280_TOOLTIP}", // "tooltip": "%{BKY_UGJ_BME280_TOOLTIP}",
"helpUrl": "", // "helpUrl": "",
"style": "sensor_blocks" // "style": "sensor_blocks"
}; // };
// Blockly.Blocks['ugj_bme280'] = {
// init: function () {
// this.jsonInit(ugjBme280Definition);
// }
// };
Blockly.Blocks['ugj_bme280'] = { Blockly.Blocks['ugj_bme280'] = {
init: function () { init: function () {
this.jsonInit(ugjBme280Definition); this.appendDummyInput()
.appendField("BME280アドレス")
.appendField(new Blockly.FieldDropdown([["0x76", "0x76"], ["0x77", "0x77"]]), "addr")
.appendField(")の計測値を取得");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setStyle('sensor_blocks');
this.setTooltip("環境センサーBME280で、気温摂氏、湿度、気圧hPaを計測します。計測結果は計測値ブロックで参照します。");
this.setHelpUrl("");
} }
}; };
Blockly.JavaScript['ugj_bme280'] = function (block) { Blockly.JavaScript['ugj_bme280'] = function (block) {
var value_address = Blockly.JavaScript.valueToCode(block, 'address', Blockly.JavaScript.ORDER_ATOMIC); var dropdown_addr = block.getFieldValue('addr');
var variable_temp = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('temp'), Blockly.Variables.NAME_TYPE);
var variable_hum = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('hum'), Blockly.Variables.NAME_TYPE);
var variable_pres = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('pres'), Blockly.Variables.NAME_TYPE);
Blockly.JavaScript.provideFunction_( Blockly.JavaScript.provideFunction_(
'require_bme280', [`const _bme280 = require('@ocogeclub/bme280');`] 'require_bme280', [`const _bme280 = require('@ocogeclub/bme280');`]
); );
var code = [ var code = `const options = {
`const options = {`, i2cBusNo: ${elutil.i2c_bus},
` i2cBusNo: ${elutil.i2c_bus},`, i2cAddress: ${dropdown_addr}
` i2cAddress: ${value_address}`, };
`};`, await _bme280.init(options);
`await _bme280.init(options);`, let _thp = await _bme280.readSensorData();
`let _thp = await _bme280.readSensorData();`, let _bmedata = [];
`${variable_temp} = Math.round(_thp.temperature_C * 10) / 10;`, _bmedata[0] = Math.round(_thp.temperature_C * 10) / 10;
`${variable_hum} = Math.round(_thp.humidity * 10) / 10;`, _bmedata[1] = Math.round(_thp.humidity * 10) / 10;
`${variable_pres} = Math.round(_thp.pressure_hPa);`, _bmedata[2] = Math.round(_thp.pressure_hPa);
`await _bme280.cancel();`, await _bme280.cancel();
`` `;
].join('\n');
return code; return code;
}; };
Blockly.Python['ugj_bme280'] = function (block) { // Blockly.JavaScript['ugj_bme280'] = function (block) {
var value_address = Blockly.Python.valueToCode(block, 'address', Blockly.Python.ORDER_ATOMIC); // var value_address = Blockly.JavaScript.valueToCode(block, 'address', Blockly.JavaScript.ORDER_ATOMIC);
var variable_temp = Blockly.Python.nameDB_.getName(block.getFieldValue('temp'), Blockly.Variables.NAME_TYPE); // var variable_temp = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('temp'), Blockly.Variables.NAME_TYPE);
var variable_hum = Blockly.Python.nameDB_.getName(block.getFieldValue('hum'), Blockly.Variables.NAME_TYPE); // var variable_hum = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('hum'), Blockly.Variables.NAME_TYPE);
var variable_pres = Blockly.Python.nameDB_.getName(block.getFieldValue('pres'), Blockly.Variables.NAME_TYPE); // var variable_pres = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('pres'), Blockly.Variables.NAME_TYPE);
Blockly.Python.provideFunction_( // Blockly.JavaScript.provideFunction_(
'import_bme280', [`import BME280`] // 'require_bme280', [`const _bme280 = require('@ocogeclub/bme280');`]
); // );
var code = [ // var code = [
`bme280 = BME280.sensor()`, // `const options = {`,
`temp, pres, hum = bme280.read_data()`, // ` i2cBusNo: ${elutil.i2c_bus},`,
`${variable_temp} = round(temp, 1)`, // ` i2cAddress: ${value_address}`,
`${variable_hum} = round(hum, 1)`, // `};`,
`${variable_pres} = round(pres/100);`, // `await _bme280.init(options);`,
`bme280.cancel()`, // `let _thp = await _bme280.readSensorData();`,
`` // `${variable_temp} = Math.round(_thp.temperature_C * 10) / 10;`,
].join('\n'); // `${variable_hum} = Math.round(_thp.humidity * 10) / 10;`,
return code; // `${variable_pres} = Math.round(_thp.pressure_hPa);`,
// `await _bme280.cancel();`,
// ``
// ].join('\n');
// return code;
// };
// Blockly.Python['ugj_bme280'] = function (block) {
// var value_address = Blockly.Python.valueToCode(block, 'address', Blockly.Python.ORDER_ATOMIC);
// var variable_temp = Blockly.Python.nameDB_.getName(block.getFieldValue('temp'), Blockly.Variables.NAME_TYPE);
// var variable_hum = Blockly.Python.nameDB_.getName(block.getFieldValue('hum'), Blockly.Variables.NAME_TYPE);
// var variable_pres = Blockly.Python.nameDB_.getName(block.getFieldValue('pres'), Blockly.Variables.NAME_TYPE);
// Blockly.Python.provideFunction_(
// 'import_bme280', [`import BME280`]
// );
// var code = [
// `bme280 = BME280.sensor()`,
// `temp, pres, hum = bme280.read_data()`,
// `${variable_temp} = round(temp, 1)`,
// `${variable_hum} = round(hum, 1)`,
// `${variable_pres} = round(pres/100);`,
// `bme280.cancel()`,
// ``
// ].join('\n');
// return code;
// };
Blockly.Blocks['ugj_bme280_data'] = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([["気温", "0"], ["湿度", "1"], ["気圧", "2"]]), "thp");
this.setInputsInline(true);
this.setOutput(true, null);
this.setStyle('sensor_blocks');
this.setTooltip("BME280 の計測値を返します。");
this.setHelpUrl("");
}
};
Blockly.JavaScript['ugj_bme280_data'] = function (block) {
var dropdown_thp = block.getFieldValue('thp');
var code = `_bmedata[${dropdown_thp}]`;
return [code, Blockly.JavaScript.ORDER_ATOMIC];
}; };
/********** */ /********** */
@ -1461,26 +1570,17 @@ Blockly.JavaScript['ugj_face_display'] = function (block) {
Blockly.Blocks['ugj_face_detect'] = { Blockly.Blocks['ugj_face_detect'] = {
init: function () { init: function () {
this.appendDummyInput() this.appendDummyInput()
.appendField("顔の位置(") .appendField("顔を検出したら");
.appendField(new Blockly.FieldVariable("左"), "x")
.appendField(new Blockly.FieldVariable("上"), "y")
.appendField(new Blockly.FieldVariable("幅"), "w")
.appendField(new Blockly.FieldVariable("高さ"), "h")
.appendField(")を検出したら");
this.appendStatementInput("do") this.appendStatementInput("do")
.setCheck(null); .setCheck(null);
this.setInputsInline(true); this.setInputsInline(true);
this.setPreviousStatement(true, null); this.setPreviousStatement(true, null);
this.setStyle('multimedia_blocks') this.setTooltip("顔を発見したら動作します。位置データは「顔の座標」ブロックで参照します。");
this.setTooltip("顔を発見したら動作します。");
this.setHelpUrl(""); this.setHelpUrl("");
this.setStyle('multimedia_blocks');
} }
}; };
Blockly.JavaScript['ugj_face_detect'] = function (block) { Blockly.JavaScript['ugj_face_detect'] = function (block) {
var variable_x = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('x'), Blockly.Variables.NAME_TYPE);
var variable_y = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('y'), Blockly.Variables.NAME_TYPE);
var variable_w = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('w'), Blockly.Variables.NAME_TYPE);
var variable_h = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('h'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do'); var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code_model = `await _faceapi.nets.tinyFaceDetector.load('${ugj_const.library_path}models/');`; var code_model = `await _faceapi.nets.tinyFaceDetector.load('${ugj_const.library_path}models/');`;
if (with_landmark) { code_model += `\nawait _faceapi.nets.faceLandmark68TinyNet.load('${ugj_const.library_path}models/');`; } if (with_landmark) { code_model += `\nawait _faceapi.nets.faceLandmark68TinyNet.load('${ugj_const.library_path}models/');`; }
@ -1490,17 +1590,17 @@ Blockly.JavaScript['ugj_face_detect'] = function (block) {
var code_rect; var code_rect;
if (with_landmark) { if (with_landmark) {
code_rect = [ code_rect = [
` ${variable_x} = Math.round(_result.detection.box.x);`, ` _coord[0] = Math.round(_result.detection.box.x);`,
` ${variable_y} = Math.round(_result.detection.box.y);`, ` _coord[1] = Math.round(_result.detection.box.y);`,
` ${variable_w} = Math.round(_result.detection.box.width);`, ` _coord[2] = Math.round(_result.detection.box.width);`,
` ${variable_h} = Math.round(_result.detection.box.height);`, ` _coord[3] = Math.round(_result.detection.box.height);`,
].join('\n'); ].join('\n');
} else { } else {
code_rect = [ code_rect = [
` ${variable_x} = Math.round(_result.box.x);`, ` _coord[0] = Math.round(_result.box.x);`,
` ${variable_y} = Math.round(_result.box.y);`, ` _coord[1] = Math.round(_result.box.y);`,
` ${variable_w} = Math.round(_result.box.width);`, ` _coord[2] = Math.round(_result.box.width);`,
` ${variable_h} = Math.round(_result.box.height);`, ` _coord[3] = Math.round(_result.box.height);`,
].join('\n'); ].join('\n');
} }
var code = [ var code = [
@ -1510,6 +1610,7 @@ Blockly.JavaScript['ugj_face_detect'] = function (block) {
` const _detectInterval = setInterval(async () => {`, ` const _detectInterval = setInterval(async () => {`,
code_detect_face, code_detect_face,
" if (_result) {", " if (_result) {",
` let _coord = [];`,
code_rect, code_rect,
statements_do, statements_do,
" }", " }",
@ -1521,6 +1622,23 @@ Blockly.JavaScript['ugj_face_detect'] = function (block) {
].join('\n'); ].join('\n');
return code; return code;
}; };
Blockly.Blocks['ugj_face_coord'] = {
init: function () {
this.appendDummyInput()
.appendField("顔の座標")
.appendField(new Blockly.FieldDropdown([["左", "0"], ["上", "1"], ["幅", "2"], ["高さ", "3"]]), "face_coord");
this.setInputsInline(true);
this.setOutput(true, null);
this.setTooltip("顔の座標(位置)を参照します。");
this.setHelpUrl("");
this.setStyle('multimedia_blocks');
}
};
Blockly.JavaScript['ugj_face_coord'] = function (block) {
var dropdown_face_coord = block.getFieldValue('face_coord');
var code = `_coord[${dropdown_face_coord}]`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
// //
Blockly.Blocks['ugj_face_drawrect'] = { Blockly.Blocks['ugj_face_drawrect'] = {
init: function () { init: function () {
@ -1529,7 +1647,7 @@ Blockly.Blocks['ugj_face_drawrect'] = {
this.setInputsInline(true); this.setInputsInline(true);
this.setPreviousStatement(true, null); this.setPreviousStatement(true, null);
this.setNextStatement(true, null); this.setNextStatement(true, null);
this.setStyle('multimedia_blocks') this.setStyle('multimedia_blocks');
this.setTooltip("ビデオに検出結果を四角や点で表示します。「ビデオを表示」ブロックが必要です。"); this.setTooltip("ビデオに検出結果を四角や点で表示します。「ビデオを表示」ブロックが必要です。");
this.setHelpUrl(""); this.setHelpUrl("");
} }
@ -2123,9 +2241,10 @@ Blockly.JavaScript['ugj_tensorset_parse'] = function (block) {
/****************************** */ /****************************** */
Blockly.Blocks['ugj_event_key'] = { Blockly.Blocks['ugj_event_key'] = {
init: function () { init: function () {
this.appendValueInput("key")
.setCheck("Variable")
.appendField("キーボードの");
this.appendDummyInput() this.appendDummyInput()
.appendField("キーボードの")
.appendField(new Blockly.FieldVariable("キー"), "key")
.appendField("を") .appendField("を")
.appendField(new Blockly.FieldDropdown([["押したとき", "keydown"], ["離したとき", "keyup"]]), "updown"); .appendField(new Blockly.FieldDropdown([["押したとき", "keydown"], ["離したとき", "keyup"]]), "updown");
this.appendStatementInput("do") this.appendStatementInput("do")
@ -2133,18 +2252,18 @@ Blockly.Blocks['ugj_event_key'] = {
this.setInputsInline(true); this.setInputsInline(true);
this.setPreviousStatement(true, null); this.setPreviousStatement(true, null);
this.setNextStatement(true, null); this.setNextStatement(true, null);
this.setStyle('multimedia_blocks');
this.setTooltip("キーボードを押したり離したりした時のアクションです。"); this.setTooltip("キーボードを押したり離したりした時のアクションです。");
this.setHelpUrl("https://developer.mozilla.org/ja/docs/Web/API/KeyboardEvent/key/Key_Values"); this.setHelpUrl("https://developer.mozilla.org/ja/docs/Web/API/KeyboardEvent/key/Key_Values");
this.setStyle('multimedia_blocks');
} }
}; };
Blockly.JavaScript['ugj_event_key'] = function (block) { Blockly.JavaScript['ugj_event_key'] = function (block) {
var variable_key = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('key'), Blockly.Variables.NAME_TYPE); var value_key = Blockly.JavaScript.valueToCode(block, 'key', Blockly.JavaScript.ORDER_ATOMIC);
var dropdown_updown = block.getFieldValue('updown'); var dropdown_updown = block.getFieldValue('updown');
var statements_do = Blockly.JavaScript.statementToCode(block, 'do'); var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [ var code = [
`document.addEventListener('${dropdown_updown}', async (_e) => {`, `document.addEventListener('${dropdown_updown}', async (_e) => {`,
` ${variable_key} = _e.key;`, ` ${value_key} = _e.key;`,
statements_do, statements_do,
`}, false);`, `}, false);`,
'' ''
@ -2260,9 +2379,10 @@ Blockly.JavaScript['ugj_socket_write'] = function (block) {
/************** */ /************** */
Blockly.Blocks['ugj_network_httpserver'] = { Blockly.Blocks['ugj_network_httpserver'] = {
init: function () { init: function () {
this.appendValueInput("url")
.setCheck("Variable")
.appendField("Webサーバを起動してアクセスを待ち、");
this.appendDummyInput() this.appendDummyInput()
.appendField("Webサーバを起動してアクセスを待ち、")
.appendField(new Blockly.FieldVariable("url"), "URL")
.appendField("へアクセスがあったら"); .appendField("へアクセスがあったら");
this.appendStatementInput("do") this.appendStatementInput("do")
.setCheck(null); .setCheck(null);
@ -2273,13 +2393,14 @@ Blockly.Blocks['ugj_network_httpserver'] = {
.appendField("を表示してアクセス待ちに戻る"); .appendField("を表示してアクセス待ちに戻る");
this.setInputsInline(true); this.setInputsInline(true);
this.setPreviousStatement(true, null); this.setPreviousStatement(true, null);
this.setStyle('network_blocks')
this.setTooltip("HTTPサーバを起動します。ポートは3000固定です。"); this.setTooltip("HTTPサーバを起動します。ポートは3000固定です。");
this.setHelpUrl(""); this.setHelpUrl("");
this.setStyle('network_blocks')
} }
}; };
Blockly.JavaScript['ugj_network_httpserver'] = function (block) { Blockly.JavaScript['ugj_network_httpserver'] = function (block) {
var variable_url = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('URL'), Blockly.Variables.NAME_TYPE); var value_url = Blockly.JavaScript.valueToCode(block, 'url', Blockly.JavaScript.ORDER_ATOMIC);
// var variable_url = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('URL'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do'); var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var value_response = Blockly.JavaScript.valueToCode(block, 'response', Blockly.JavaScript.ORDER_ATOMIC); var value_response = Blockly.JavaScript.valueToCode(block, 'response', Blockly.JavaScript.ORDER_ATOMIC);
Blockly.JavaScript.provideFunction_( Blockly.JavaScript.provideFunction_(
@ -2289,7 +2410,7 @@ Blockly.JavaScript['ugj_network_httpserver'] = function (block) {
`let _req, _res;`, `let _req, _res;`,
`_http.createServer(async (_req, _res) => {`, `_http.createServer(async (_req, _res) => {`,
`_res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });`, `_res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });`,
`${variable_url} = _req.url;`, `${value_url} = _req.url;`,
statements_do, statements_do,
// `_res.write('<!DOCTYPE html><html lang="ja"><head><meta charset="UTF-8"></head><body>');`, // `_res.write('<!DOCTYPE html><html lang="ja"><head><meta charset="UTF-8"></head><body>');`,
`_res.end(${value_response});`, `_res.end(${value_response});`,
@ -2378,7 +2499,7 @@ Blockly.JavaScript['ugj_network_sendmail'] = function (block) {
`port: 25`, `port: 25`,
`});`, `});`,
`let _message = {`, `let _message = {`,
`from: 'no-reply@oc.x0.to',`, `from: 'no-reply@ocoge.club',`,
`to: ${value_to},`, `to: ${value_to},`,
`subject: ${value_subject},`, `subject: ${value_subject},`,
`text: ${value_text}`, `text: ${value_text}`,
@ -2414,7 +2535,7 @@ Blockly.Blocks['ugj_library_skyway'] = {
} }
}; };
Blockly.JavaScript['ugj_library_skyway'] = function (block) { Blockly.JavaScript['ugj_library_skyway'] = function (block) {
var code = `'${ugj_const.library_path}skyway.js'`; var code = `'${ugj_const.library_path}skyway.min.js'`;
return [code, Blockly.JavaScript.ORDER_NONE]; return [code, Blockly.JavaScript.ORDER_NONE];
}; };
@ -2479,10 +2600,10 @@ Blockly.JavaScript['ugj_getusermedia'] = function (block) {
// SkyWay New Peer // SkyWay New Peer
Blockly.Blocks['ugj_skyway_newpeer'] = { Blockly.Blocks['ugj_skyway_newpeer'] = {
init: function () { init: function () {
this.appendValueInput("my_id")
.setCheck("Variable")
.appendField("SkyWayサーバーに ID:");
this.appendDummyInput() this.appendDummyInput()
.appendField("SkyWayサーバーに ID:")
.appendField(new Blockly.FieldVariable("自分のID"), "my_id")
// .appendField(new Blockly.FieldTextInput("MyID"), "NAME")
.appendField("で接続する"); .appendField("で接続する");
this.appendStatementInput("do") this.appendStatementInput("do")
.setCheck(null) .setCheck(null)
@ -2490,23 +2611,24 @@ Blockly.Blocks['ugj_skyway_newpeer'] = {
this.setInputsInline(true); this.setInputsInline(true);
this.setPreviousStatement(true, null); this.setPreviousStatement(true, null);
this.setNextStatement(true, null); this.setNextStatement(true, null);
this.setStyle('network_blocks')
this.setTooltip("サーバーにIDを登録して、相手先呼び出しの準備をします。"); this.setTooltip("サーバーにIDを登録して、相手先呼び出しの準備をします。");
this.setHelpUrl(""); this.setHelpUrl("");
this.setStyle('network_blocks')
} }
}; };
Blockly.JavaScript['ugj_skyway_newpeer'] = function (block) { Blockly.JavaScript['ugj_skyway_newpeer'] = function (block) {
var variable_my_id = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('my_id'), Blockly.Variables.NAME_TYPE); var value_my_id = Blockly.JavaScript.valueToCode(block, 'my_id', Blockly.JavaScript.ORDER_ATOMIC);
// var variable_my_id = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('my_id'), Blockly.Variables.NAME_TYPE);
// var text_name = block.getFieldValue('NAME'); // var text_name = block.getFieldValue('NAME');
var statements_do = Blockly.JavaScript.statementToCode(block, 'do'); var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [ var code = [
`const _peer = new Peer(${variable_my_id}, {`, `const _peer = new Peer(${value_my_id}, {`,
" key: window.__SKYWAY_KEY__,", " key: window.__SKYWAY_KEY__,",
" debug: 3", " debug: 3",
"});", "});",
"_peer.on('open', () => {", "_peer.on('open', () => {",
// ' ugj_blackboardWrite(`SkyWay: "${peer.id}" OK`)', // ' ugj_blackboardWrite(`SkyWay: "${peer.id}" OK`)',
`${variable_my_id} = _peer.id;`, `${value_my_id} = _peer.id;`,
"_inputForm.addEventListener('submit', _onMakeCall);", "_inputForm.addEventListener('submit', _onMakeCall);",
statements_do, statements_do,
"});", "});",
@ -2514,9 +2636,9 @@ Blockly.JavaScript['ugj_skyway_newpeer'] = function (block) {
"const _onMakeCall = _e => {", "const _onMakeCall = _e => {",
" _e.preventDefault();", " _e.preventDefault();",
" const _call = _peer.call(_inputBox.value, _localStream);", " const _call = _peer.call(_inputBox.value, _localStream);",
" setupCallEventHandlers(_call);", " _setupCallEventHandlers(_call);",
" const _connect = peer.connect(_inputBox.value);", " const _connect = _peer.connect(_inputBox.value);",
" setupConnectEventHandlers(_connect);", " _setupConnectEventHandlers(_connect);",
" _inputBox.value = '';", " _inputBox.value = '';",
"}", "}",
'' ''
@ -2552,27 +2674,29 @@ Blockly.JavaScript['ugj_skyway_called'] = function (block) {
// EventHandlers for Call and Connect // EventHandlers for Call and Connect
Blockly.Blocks['ugj_skyway_events'] = { Blockly.Blocks['ugj_skyway_events'] = {
init: function () { init: function () {
this.appendValueInput("remote_id")
.setCheck("Variable");
this.appendDummyInput() this.appendDummyInput()
.appendField(new Blockly.FieldVariable("相手のID"), "remote_id")
.appendField("との接続後にすること"); .appendField("との接続後にすること");
this.appendStatementInput("do") this.appendStatementInput("do")
.setCheck(null); .setCheck(null);
this.setInputsInline(true); this.setInputsInline(true);
this.setPreviousStatement(true, null); this.setPreviousStatement(true, null);
this.setNextStatement(true, null); this.setNextStatement(true, null);
this.setStyle('network_blocks')
this.setTooltip("チャットの相手との接続後の動作を定義します。"); this.setTooltip("チャットの相手との接続後の動作を定義します。");
this.setHelpUrl(""); this.setHelpUrl("");
this.setStyle('network_blocks')
} }
}; };
Blockly.JavaScript['ugj_skyway_events'] = function (block) { Blockly.JavaScript['ugj_skyway_events'] = function (block) {
var variable_remote_id = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('remote_id'), Blockly.Variables.NAME_TYPE); var value_remote_id = Blockly.JavaScript.valueToCode(block, 'remote_id', Blockly.JavaScript.ORDER_ATOMIC);
// var variable_remote_id = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('remote_id'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do'); var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [ var code = [
"const _setupCallEventHandlers = _call => _call.on('stream', _stream => _remoteVideo.srcObject = _stream);", "const _setupCallEventHandlers = _call => _call.on('stream', _stream => _remoteVideo.srcObject = _stream);",
"const _setupConnectEventHandlers = _connect => {", "const _setupConnectEventHandlers = _connect => {",
" _inputForm.removeEventListener('submit', _onMakeCall);", " _inputForm.removeEventListener('submit', _onMakeCall);",
` ${variable_remote_id} = _connect.remoteId;`, ` ${value_remote_id} = _connect.remoteId;`,
statements_do, statements_do,
"}", "}",
'' ''
@ -2608,26 +2732,28 @@ Blockly.JavaScript['ugj_skyway_eventopen'] = function (block) {
// Peer Data Receive // Peer Data Receive
Blockly.Blocks['ugj_skyway_eventdata'] = { Blockly.Blocks['ugj_skyway_eventdata'] = {
init: function () { init: function () {
this.appendValueInput("data")
.setCheck("Variable")
.appendField("相手の");
this.appendDummyInput() this.appendDummyInput()
.appendField("相手の")
.appendField(new Blockly.FieldVariable("発言"), "data")
.appendField("を受けとったら"); .appendField("を受けとったら");
this.appendStatementInput("do") this.appendStatementInput("do")
.setCheck(null); .setCheck(null);
this.setInputsInline(true); this.setInputsInline(true);
this.setPreviousStatement(true, null); this.setPreviousStatement(true, null);
this.setNextStatement(true, null); this.setNextStatement(true, null);
this.setStyle('network_blocks')
this.setTooltip("チャット相手の発言を受信したときの動作です。"); this.setTooltip("チャット相手の発言を受信したときの動作です。");
this.setHelpUrl(""); this.setHelpUrl("");
this.setStyle('network_blocks')
} }
}; };
Blockly.JavaScript['ugj_skyway_eventdata'] = function (block) { Blockly.JavaScript['ugj_skyway_eventdata'] = function (block) {
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE); var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
// var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do'); var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [ var code = [
" _connect.on('data', _data => {", " _connect.on('data', _data => {",
` ${variable_data} = _data;`, ` ${value_data} = _data;`,
statements_do, statements_do,
" });", " });",
'' ''
@ -2637,27 +2763,29 @@ Blockly.JavaScript['ugj_skyway_eventdata'] = function (block) {
// Send Message // Send Message
Blockly.Blocks['ugj_skyway_eventsend'] = { Blockly.Blocks['ugj_skyway_eventsend'] = {
init: function () { init: function () {
this.appendValueInput("data")
.setCheck("Variable")
.appendField("入力フィールドの");
this.appendDummyInput() this.appendDummyInput()
.appendField("入力フィールドの")
.appendField(new Blockly.FieldVariable("内容"), "data")
.appendField("を送信するとき"); .appendField("を送信するとき");
this.appendStatementInput("do") this.appendStatementInput("do")
.setCheck(null); .setCheck(null);
this.setInputsInline(true); this.setInputsInline(true);
this.setPreviousStatement(true, null); this.setPreviousStatement(true, null);
this.setNextStatement(true, null); this.setNextStatement(true, null);
this.setStyle('network_blocks')
this.setTooltip("入力フィールドで送信が発生したときの動作を決めます。"); this.setTooltip("入力フィールドで送信が発生したときの動作を決めます。");
this.setHelpUrl(""); this.setHelpUrl("");
this.setStyle('network_blocks')
} }
}; };
Blockly.JavaScript['ugj_skyway_eventsend'] = function (block) { Blockly.JavaScript['ugj_skyway_eventsend'] = function (block) {
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE); var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
// var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do'); var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [ var code = [
" const _onSendMsg = () => {", " const _onSendMsg = () => {",
` ${variable_data} = _inputBox.value;`, ` ${value_data} = _inputBox.value;`,
` _connect.send(${variable_data});`, ` _connect.send(${value_data});`,
" _inputBox.value = '';", " _inputBox.value = '';",
statements_do, statements_do,
" }", " }",
@ -2780,21 +2908,23 @@ Blockly.Blocks['ugj_event_answer'] = {
init: function () { init: function () {
this.appendValueInput("question") this.appendValueInput("question")
.setCheck("String"); .setCheck("String");
this.appendValueInput("answer")
.setCheck("Variable")
.appendField("ときいて");
this.appendDummyInput() this.appendDummyInput()
.appendField("ときいて")
.appendField(new Blockly.FieldVariable("答え"), "answer")
.appendField("を待つ"); .appendField("を待つ");
this.appendStatementInput("do") this.appendStatementInput("do")
.setCheck(null); .setCheck(null);
this.setPreviousStatement(true, null); this.setPreviousStatement(true, null);
this.setStyle('special_blocks')
this.setTooltip("質問をして答えを待ちます。入力欄でキーボードのエンターキーが入力されるか、チェックマークボタンが押されると実行されます。"); this.setTooltip("質問をして答えを待ちます。入力欄でキーボードのエンターキーが入力されるか、チェックマークボタンが押されると実行されます。");
this.setHelpUrl(""); this.setHelpUrl("");
this.setStyle('special_blocks')
} }
}; };
Blockly.JavaScript['ugj_event_answer'] = function (block) { Blockly.JavaScript['ugj_event_answer'] = function (block) {
var value_question = Blockly.JavaScript.valueToCode(block, 'question', Blockly.JavaScript.ORDER_ATOMIC); var value_question = Blockly.JavaScript.valueToCode(block, 'question', Blockly.JavaScript.ORDER_ATOMIC);
var variable_answer = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('answer'), Blockly.Variables.NAME_TYPE); var value_answer = Blockly.JavaScript.valueToCode(block, 'answer', Blockly.JavaScript.ORDER_ATOMIC);
// var variable_answer = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('answer'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do'); var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [ var code = [
`ugj_fukidashi(${value_question}, 0);`, `ugj_fukidashi(${value_question}, 0);`,
@ -2804,7 +2934,7 @@ Blockly.JavaScript['ugj_event_answer'] = function (block) {
"_inputBox.focus();", "_inputBox.focus();",
"const _inputFunc = async () => { ", "const _inputFunc = async () => { ",
" if (_inputBox.value.length > 0) {", " if (_inputBox.value.length > 0) {",
` ${variable_answer} = _inputBox.value;`, ` ${value_answer} = _inputBox.value;`,
' _inputForm.style.display = "none"', ' _inputForm.style.display = "none"',
" _inputBox.value = '';", " _inputBox.value = '';",
" document.getElementById('canvas').getContext('2d').clearRect(ugj_fdRecentBox.x,ugj_fdRecentBox.y,ugj_fdRecentBox.w,ugj_fdRecentBox.h);", " document.getElementById('canvas').getContext('2d').clearRect(ugj_fdRecentBox.x,ugj_fdRecentBox.y,ugj_fdRecentBox.w,ugj_fdRecentBox.h);",
@ -2827,22 +2957,24 @@ Blockly.Blocks['ugj_spawnsync'] = {
this.appendValueInput("childprocess") this.appendValueInput("childprocess")
.setCheck("shcmd") .setCheck("shcmd")
.appendField("外部プログラム"); .appendField("外部プログラム");
this.appendValueInput("data")
.setCheck("Variable")
.appendField("を同期的に実行して");
this.appendDummyInput() this.appendDummyInput()
.appendField("を同期的に実行して")
.appendField(new Blockly.FieldVariable("実行結果"), "data")
.appendField("を受け取る"); .appendField("を受け取る");
this.setInputsInline(true); this.setInputsInline(true);
this.setPreviousStatement(true, null); this.setPreviousStatement(true, null);
this.setNextStatement(true, null); this.setNextStatement(true, null);
this.setStyle('special_blocks')
this.setTooltip("外部プログラムを実行して子プロセスを生成し、子プロセスが終了するまで待ちます。"); this.setTooltip("外部プログラムを実行して子プロセスを生成し、子プロセスが終了するまで待ちます。");
this.setHelpUrl(""); this.setHelpUrl("");
this.setStyle('special_blocks')
} }
}; };
Blockly.JavaScript['ugj_spawnsync'] = function (block) { Blockly.JavaScript['ugj_spawnsync'] = function (block) {
var value_childprocess = Blockly.JavaScript.valueToCode(block, 'childprocess', Blockly.JavaScript.ORDER_NONE); var value_childprocess = Blockly.JavaScript.valueToCode(block, 'childprocess', Blockly.JavaScript.ORDER_NONE);
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE); var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
var code = `${variable_data} = require('child_process').spawnSync(${value_childprocess}).stdout.toString();\n`; // var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
var code = `${value_data} = require('child_process').spawnSync(${value_childprocess}).stdout.toString();\n`;
// var code = `${variable_data} = require('child_process').execFileSync(${value_childprocess});\n`; // var code = `${variable_data} = require('child_process').execFileSync(${value_childprocess});\n`;
return code; return code;
}; };
@ -2855,30 +2987,32 @@ Blockly.Blocks['ugj_spawn'] = {
this.appendValueInput("childprocess") this.appendValueInput("childprocess")
.setCheck("shcmd") .setCheck("shcmd")
.appendField("外部プログラム"); .appendField("外部プログラム");
this.appendValueInput("data")
.setCheck(null)
.appendField("を非同期に実行して");
this.appendDummyInput() this.appendDummyInput()
.appendField("を非同期に実行して")
.appendField(new Blockly.FieldVariable("データストリーム"), "data")
.appendField("を受け取る"); .appendField("を受け取る");
this.appendStatementInput("do") this.appendStatementInput("do")
.setCheck(null); .setCheck(null);
this.setInputsInline(true); this.setInputsInline(true);
this.setPreviousStatement(true, null); this.setPreviousStatement(true, null);
this.setNextStatement(true, null); this.setNextStatement(true, null);
this.setStyle('special_blocks')
this.setTooltip("外部プログラムを実行して子プロセスを生成します。データを受け取る毎にステートメントが実行されます。"); this.setTooltip("外部プログラムを実行して子プロセスを生成します。データを受け取る毎にステートメントが実行されます。");
this.setHelpUrl(""); this.setHelpUrl("");
this.setStyle('special_blocks')
} }
}; };
Blockly.JavaScript['ugj_spawn'] = function (block) { Blockly.JavaScript['ugj_spawn'] = function (block) {
var value_childprocess = Blockly.JavaScript.valueToCode(block, 'childprocess', Blockly.JavaScript.ORDER_NONE); var value_childprocess = Blockly.JavaScript.valueToCode(block, 'childprocess', Blockly.JavaScript.ORDER_NONE);
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE); var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
// var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do'); var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [ var code = [
`let _child = require('child_process').spawn(${value_childprocess});`, `let _child = require('child_process').spawn(${value_childprocess});`,
`elutil.addChild(_child);`, `elutil.addChild(_child);`,
"_child.stderr.on('data', _data => { console.error(_data.toString()) })", "_child.stderr.on('data', _data => { console.error(_data.toString()) })",
"_child.stdout.on('data', async _data => {", "_child.stdout.on('data', async _data => {",
`${variable_data} = _data.toString();`, `${value_data} = _data.toString();`,
statements_do, statements_do,
"})", "})",
"_child.on('close', (_code, _signal) => { if (_code !== 0) { console.error(`process exited with code ${_code}, signal ${_signal}`)}", "_child.on('close', (_code, _signal) => { if (_code !== 0) { console.error(`process exited with code ${_code}, signal ${_signal}`)}",
@ -3447,16 +3581,13 @@ Blockly.Blocks['ugj_control_button'] = {
.setCheck("String") .setCheck("String")
.appendField("ツールチップ"); .appendField("ツールチップ");
this.appendStatementInput("do") this.appendStatementInput("do")
.setCheck(null) .setCheck(null);
.appendField("クリックしたら (")
.appendField(new Blockly.FieldVariable("ツールチップ"), "title")
.appendField(")");
this.setInputsInline(true); this.setInputsInline(true);
this.setPreviousStatement(true, null); this.setPreviousStatement(true, null);
this.setNextStatement(true, null); this.setNextStatement(true, null);
this.setStyle('special_blocks')
this.setTooltip("ディスプレイカラムにボタンを作成し、クリックのイベントリスナを定義します。テキストデータをひとつ、\"title\"属性値として設定・取り出しが可能です。保存したデータはマウスオーバーで確認できます。"); this.setTooltip("ディスプレイカラムにボタンを作成し、クリックのイベントリスナを定義します。テキストデータをひとつ、\"title\"属性値として設定・取り出しが可能です。保存したデータはマウスオーバーで確認できます。");
this.setHelpUrl(""); this.setHelpUrl("");
this.setStyle('special_blocks')
} }
}; };
Blockly.JavaScript['ugj_control_button'] = function (block) { Blockly.JavaScript['ugj_control_button'] = function (block) {
@ -3464,7 +3595,6 @@ Blockly.JavaScript['ugj_control_button'] = function (block) {
var value_textcolor = Blockly.JavaScript.valueToCode(block, 'textcolor', Blockly.JavaScript.ORDER_ATOMIC); var value_textcolor = Blockly.JavaScript.valueToCode(block, 'textcolor', Blockly.JavaScript.ORDER_ATOMIC);
var value_bgcolor = Blockly.JavaScript.valueToCode(block, 'bgcolor', Blockly.JavaScript.ORDER_ATOMIC); var value_bgcolor = Blockly.JavaScript.valueToCode(block, 'bgcolor', Blockly.JavaScript.ORDER_ATOMIC);
var value_title = Blockly.JavaScript.valueToCode(block, 'title', Blockly.JavaScript.ORDER_ATOMIC); var value_title = Blockly.JavaScript.valueToCode(block, 'title', Blockly.JavaScript.ORDER_ATOMIC);
var variable_title = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('title'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do'); var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [ var code = [
`( async () => {`, `( async () => {`,
@ -3476,7 +3606,6 @@ Blockly.JavaScript['ugj_control_button'] = function (block) {
`el.className = 'toolbarButton ocgButton';`, `el.className = 'toolbarButton ocgButton';`,
`document.getElementById('dispColumn').appendChild(el);`, `document.getElementById('dispColumn').appendChild(el);`,
`el.addEventListener('click', async ev => {`, `el.addEventListener('click', async ev => {`,
`${variable_title} = ev.currentTarget.title;`,
statements_do, statements_do,
`});`, `});`,
`})();`, `})();`,
@ -3526,3 +3655,23 @@ else console.log('invalid certification');
`; `;
return code; return code;
}; };
Blockly.Blocks['testblock'] = {
init: function () {
this.appendValueInput("foo")
.setCheck("Variable")
.appendField("テスト");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.JavaScript['testblock'] = function (block) {
var value_foo = Blockly.JavaScript.valueToCode(block, 'foo', Blockly.JavaScript.ORDER_ATOMIC);
// TODO: Assemble JavaScript into code variable.
var code = `${value_foo} = 42;\n`;
return code;
};