[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,174 +1,161 @@
/**
* Blockly Demos: Custom Dialogs
*
* Copyright 2016 Google Inc.
* 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.
*/
/**
* An example implementation of how one might replace Blockly's browser
* dialogs. This is just an example, and applications are not encouraged to use
* it verbatim.
*
* @namespace
*/
CustomDialog = {};
/** Override Blockly.alert() with custom implementation. */
Blockly.alert = function(message, callback) {
console.log('Alert: ' + message);
CustomDialog.show('Alert', message, {
onCancel: callback
});
};
/** Override Blockly.confirm() with custom implementation. */
Blockly.confirm = function(message, callback) {
console.log('Confirm: ' + message);
CustomDialog.show('Confirm', message, {
showOkay: true,
onOkay: function() {
callback(true);
},
showCancel: true,
onCancel: function() {
callback(false);
}
});
};
/** Override Blockly.prompt() with custom implementation. */
Blockly.prompt = function(message, defaultValue, callback) {
console.log('Prompt: ' + message);
CustomDialog.show('Prompt', message, {
showInput: true,
showOkay: true,
onOkay: function() {
callback(CustomDialog.inputField.value);
},
showCancel: true,
onCancel: function() {
callback(null);
}
});
CustomDialog.inputField.value = defaultValue;
};
/** Hides any currently visible dialog. */
CustomDialog.hide = function() {
if (CustomDialog.backdropDiv_) {
CustomDialog.backdropDiv_.style.display = 'none';
CustomDialog.dialogDiv_.style.display = 'none';
}
};
/**
* Shows the dialog.
* Allowed options:
* - showOkay: Whether to show the OK button.
* - showCancel: Whether to show the Cancel button.
* - showInput: Whether to show the text input field.
* - onOkay: Callback to handle the okay button.
* - onCancel: Callback to handle the cancel button and backdrop clicks.
*/
CustomDialog.show = function(title, message, options) {
var backdropDiv = CustomDialog.backdropDiv_;
var dialogDiv = CustomDialog.dialogDiv_;
if (!dialogDiv) {
// Generate HTML
backdropDiv = document.createElement('div');
backdropDiv.id = 'customDialogBackdrop';
backdropDiv.style.cssText =
'position: absolute;' +
'top: 0; left: 0; right: 0; bottom: 0;' +
'background-color: rgba(0, 0, 0, .7);' +
'z-index: 100;';
document.body.appendChild(backdropDiv);
dialogDiv = document.createElement('div');
dialogDiv.id = 'customDialog';
dialogDiv.style.cssText =
'background-color: #fff;' +
'width: 400px;' +
'margin: 20px auto 0;' +
'padding: 10px;';
backdropDiv.appendChild(dialogDiv);
dialogDiv.onclick = function(event) {
event.stopPropagation();
};
CustomDialog.backdropDiv_ = backdropDiv;
CustomDialog.dialogDiv_ = dialogDiv;
}
backdropDiv.style.display = 'block';
dialogDiv.style.display = 'block';
dialogDiv.innerHTML =
'<header class="customDialogTitle"></header>' +
'<p class="customDialogMessage"></p>' +
(options.showInput ? '<div><input id="customDialogInput"></div>' : '') +
'<div class="customDialogButtons">' +
(options.showCancel ? '<button id="customDialogCancel">Cancel</button>': '') +
(options.showOkay ? '<button id="customDialogOkay">OK</button>': '') +
'</div>';
dialogDiv.getElementsByClassName('customDialogTitle')[0]
.appendChild(document.createTextNode(title));
dialogDiv.getElementsByClassName('customDialogMessage')[0]
.appendChild(document.createTextNode(message));
var onOkay = function(event) {
CustomDialog.hide();
options.onOkay && options.onOkay();
event && event.stopPropagation();
};
var onCancel = function(event) {
CustomDialog.hide();
options.onCancel && options.onCancel();
event && event.stopPropagation();
};
var dialogInput = document.getElementById('customDialogInput');
CustomDialog.inputField = dialogInput;
if (dialogInput) {
dialogInput.focus();
dialogInput.onkeyup = function(event) {
if (event.keyCode == 13) {
// Process as OK when user hits enter.
onOkay();
return false;
} else if (event.keyCode == 27) {
// Process as cancel when user hits esc.
onCancel();
return false;
}
};
} else {
var okay = document.getElementById('customDialogOkay');
okay && okay.focus();
}
if (options.showOkay) {
document.getElementById('customDialogOkay')
.addEventListener('click', onOkay);
}
if (options.showCancel) {
document.getElementById('customDialogCancel')
.addEventListener('click', onCancel);
}
backdropDiv.onclick = onCancel;
};
/**
* @license
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* An example implementation of how one might replace Blockly's browser
* dialogs. This is just an example, and applications are not encouraged to use
* it verbatim.
*
* @namespace
*/
CustomDialog = {};
/** Override Blockly.dialog.alert() with custom implementation. */
Blockly.dialog.setAlert(function(message, callback) {
console.log('Alert: ' + message);
CustomDialog.show('Alert', message, {
onCancel: callback
});
});
/** Override Blockly.dialog.confirm() with custom implementation. */
Blockly.dialog.setConfirm(function(message, callback) {
console.log('Confirm: ' + message);
CustomDialog.show('Confirm', message, {
showOkay: true,
onOkay: function() {
callback(true);
},
showCancel: true,
onCancel: function() {
callback(false);
}
});
});
/** Override Blockly.dialog.prompt() with custom implementation. */
Blockly.dialog.setPrompt(function(message, defaultValue, callback) {
console.log('Prompt: ' + message);
CustomDialog.show('Prompt', message, {
showInput: true,
showOkay: true,
onOkay: function() {
callback(CustomDialog.inputField.value);
},
showCancel: true,
onCancel: function() {
callback(null);
}
});
CustomDialog.inputField.value = defaultValue;
});
/** Hides any currently visible dialog. */
CustomDialog.hide = function() {
if (CustomDialog.backdropDiv_) {
CustomDialog.backdropDiv_.style.display = 'none';
CustomDialog.dialogDiv_.style.display = 'none';
}
};
/**
* Shows the dialog.
* Allowed options:
* - showOkay: Whether to show the OK button.
* - showCancel: Whether to show the Cancel button.
* - showInput: Whether to show the text input field.
* - onOkay: Callback to handle the okay button.
* - onCancel: Callback to handle the cancel button and backdrop clicks.
*/
CustomDialog.show = function(title, message, options) {
var backdropDiv = CustomDialog.backdropDiv_;
var dialogDiv = CustomDialog.dialogDiv_;
if (!dialogDiv) {
// Generate HTML
backdropDiv = document.createElement('div');
backdropDiv.id = 'customDialogBackdrop';
backdropDiv.style.cssText =
'position: absolute;' +
'top: 0; left: 0; right: 0; bottom: 0;' +
'background-color: rgba(0, 0, 0, .7);' +
'z-index: 100;';
document.body.appendChild(backdropDiv);
dialogDiv = document.createElement('div');
dialogDiv.id = 'customDialog';
dialogDiv.style.cssText =
'background-color: #fff;' +
'width: 400px;' +
'margin: 20px auto 0;' +
'padding: 10px;';
backdropDiv.appendChild(dialogDiv);
dialogDiv.onclick = function(event) {
event.stopPropagation();
};
CustomDialog.backdropDiv_ = backdropDiv;
CustomDialog.dialogDiv_ = dialogDiv;
}
backdropDiv.style.display = 'block';
dialogDiv.style.display = 'block';
dialogDiv.innerHTML =
'<header class="customDialogTitle"></header>' +
'<p class="customDialogMessage"></p>' +
(options.showInput ? '<div><input id="customDialogInput"></div>' : '') +
'<div class="customDialogButtons">' +
(options.showCancel ? '<button id="customDialogCancel">Cancel</button>': '') +
(options.showOkay ? '<button id="customDialogOkay">OK</button>': '') +
'</div>';
dialogDiv.getElementsByClassName('customDialogTitle')[0]
.appendChild(document.createTextNode(title));
dialogDiv.getElementsByClassName('customDialogMessage')[0]
.appendChild(document.createTextNode(message));
var onOkay = function(event) {
CustomDialog.hide();
options.onOkay && options.onOkay();
event && event.stopPropagation();
};
var onCancel = function(event) {
CustomDialog.hide();
options.onCancel && options.onCancel();
event && event.stopPropagation();
};
var dialogInput = document.getElementById('customDialogInput');
CustomDialog.inputField = dialogInput;
if (dialogInput) {
dialogInput.focus();
dialogInput.onkeyup = function(event) {
if (event.keyCode === 13) {
// Process as OK when user hits enter.
onOkay();
return false;
} else if (event.keyCode === 27) {
// Process as cancel when user hits esc.
onCancel();
return false;
}
};
} else {
var okay = document.getElementById('customDialogOkay');
okay && okay.focus();
}
if (options.showOkay) {
document.getElementById('customDialogOkay')
.addEventListener('click', onOkay);
}
if (options.showCancel) {
document.getElementById('customDialogCancel')
.addEventListener('click', onCancel);
}
backdropDiv.onclick = onCancel;
};

View File

@ -103,6 +103,29 @@
<field name="MODE">WHILE</field>
</block>
<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="crease">+</field>
<value name="from">
@ -120,9 +143,16 @@
<field name="NUM">1</field>
</shadow>
</value>
</block>
<block type="ugj_controls_forEach">
</block> -->
<!-- <block type="ugj_controls_forEach">
<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 type="controls_flow_statements">
<field name="FLOW">BREAK</field>
@ -488,7 +518,14 @@
<category name="センサー" css-icon="customIcon fas fa-microchip" categorystyle="sensor_category">
<label text="温湿度気圧センサー BME280" web-line="4.0" web-line-width="200"></label>
<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="pres" id="I^GLkF^Z3#x2F0ho%J[?">気圧</field>
<value name="address">
@ -500,7 +537,7 @@
</value>
</shadow>
</value>
</block>
</block> -->
<label text="ジェスチャーセンサー PAJ7620" web-line="4.0" web-line-width="200"></label>
<block type="ugj_gesture_init">
<value name="i2c_addr">
@ -635,9 +672,17 @@
</block>
<block type="ugj_canvas_finalize"></block>
<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="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>
<label text="色" web-line="4.0" web-line-width="200"></label>
<block type="colour_picker">
@ -671,11 +716,15 @@
</block>
<block type="ugj_face_init"></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="y" id="]G:_%S*1v4!9_+yx532d" 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>
</block> -->
<block type="ugj_face_detect"></block>
<block type="ugj_face_coord">
<field name="face_coord">0</field>
</block>
<block type="ugj_face_drawrect"></block>
<label text="_" web-line="4.0" web-line-width="200"></label>
@ -713,13 +762,25 @@
</value>
</block>
<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>
<value name="response">
<shadow type="text">
<field name="TEXT">オコゲ</field>
</shadow>
</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>
<label text="ウェブチャット" web-line="4.0" web-line-width="200"></label>
<block type="ugj_library_load">
@ -730,18 +791,43 @@
<block type="ugj_webchat"></block>
<block type="ugj_getusermedia"></block>
<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 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>
</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 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>
</block>
<block type="ugj_skyway_eventsend">
<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>
<label text="_" web-line="4.0" web-line-width="200"></label>
</category>
@ -759,13 +845,25 @@
</shadow>
</value>
</block>
<block type="ugj_event_answer">
<!-- <block type="ugj_event_answer">
<field name="answer" id="_m@Uj#wHnIuGJNVwdUR+" variabletype="">答え</field>
<value name="question">
<shadow type="text">
<field name="TEXT">お名前は?</field>
</shadow>
</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 type="ugj_blackboard_show"></block>
<block type="ugj_blackboard_write">
@ -786,7 +884,6 @@
<block type="ugj_blackboard_content"></block>
<block type="ugj_clearblackboard"></block>
<block type="ugj_control_button">
<field name="title" id="j{fM0uCAB9~3y=|~dd?:" variabletype="">ツールチップ</field>
<value name="label">
<shadow type="text">
<field name="TEXT">ボタン1</field>
@ -799,12 +896,12 @@
</value>
<value name="bgcolor">
<shadow type="colour_picker">
<field name="COLOUR">#00cccc</field>
<field name="COLOUR">#999999</field>
</shadow>
</value>
<value name="title">
<shadow type="text">
<field name="TEXT">データの保存に使えます。</field>
<field name="TEXT">ここをクリック</field>
</shadow>
</value>
</block>
@ -859,10 +956,18 @@
<block type="ugj_special_clearinterval"></block>
<label text="プロセス" web-line="4.0" web-line-width="200"></label>
<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 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 type="ugj_child_julius"></block>
<block type="aquestalk_pi">
@ -946,7 +1051,12 @@
<category name="スニペット" css-icon="customIcon fas fa-egg" categorystyle="snippets_category">
<label text="入出力" web-line="4.0" web-line-width="200"></label>
<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">
<shadow type="text">
<field name="TEXT">お名前は?</field>
@ -978,7 +1088,7 @@
<mutation items="2"></mutation>
<value name="ADD0">
<block type="variables_get">
<field name="VAR" id="_m@Uj#wHnIuGJNVwdUR+">答え</field>
<field name="VAR" id=":w)sl|yxx4k^W-~-VM#,">答え</field>
</block>
</value>
<value name="ADD1">
@ -1002,7 +1112,13 @@
</statement>
</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>
</xml>
@ -1011,13 +1127,13 @@
<script src="./google-blockly/python_compressed.js"></script>
<script src="./google-blockly/blocks_compressed.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="./index_elutil.js"></script>
<script src="./index.js"></script>
<script src="./lib/beautify.min.js"></script>
<script src="./lib/prettify.js"></script>
<!-- <script src="./.shared/skyway_key.js"></script> -->
<script src="./.shared/skyway_key.js"></script>
</body>
</html>

View File

@ -313,7 +313,7 @@ const ugj_saveWorkspaceToFile = async () => {
let xml = Blockly.Xml.workspaceToDom(workspace);
let xml_text = Blockly.Xml.domToText(xml);
if (await elutil.saveWsFile(xml_text) === false) {
alert('保存できませんでした。');
window.alert('保存できませんでした。');
}
}
const ugj_loadWorkspaceFromFile = async () => {
@ -410,7 +410,7 @@ const ugj_runCode = async () => {
// await eval(code).catch(e => { alert(e); });
let AsyncFunction = Object.getPrototypeOf(async function () { }).constructor
let ocogeFunc = new AsyncFunction(ugj_createCode({}));
await ocogeFunc().catch(e => { alert(e); });
await ocogeFunc().catch(e => { window.alert(e); });
console.log('Code Execution done.');
}
@ -447,7 +447,7 @@ const ugj_showCode = () => {
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 */');
if (elutil.saveFile(code, ext) === false) {
alert('保存できませんでした。');
window.alert('保存できませんでした。');
}
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 ****************************************************************************************/
var ugjConsrolForDefinition = {
"type": "ugj_control_for",
"message0": "%{BKY_UGJ_CONTROL_FOR_TITLE}",
"args0": [
{
"type": "field_variable",
"name": "index",
"variable": "%{BKY_UGJ_CONTROL_FOR_INDEX}"
},
{
"type": "input_dummy"
},
{
"type": "input_value",
"name": "from",
"check": "Number"
},
{
"type": "input_value",
"name": "to",
"check": "Number"
},
{
"type": "input_value",
"name": "by",
"check": "Number"
},
{
"type": "field_dropdown",
"name": "crease",
"options": [
[
"%{BKY_UGJ_CONTROL_FOR_INCREASE}",
"+"
],
[
"%{BKY_UGJ_CONTROL_FOR_DECREASE}",
"-"
]
]
},
{
"type": "input_dummy"
},
{
"type": "input_statement",
"name": "do"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"tooltip": "%{BKY_UGJ_CONTROL_FOR_TOOLTIP}",
"helpUrl": "",
"style": "loop_blocks"
};
// var ugjConsrolForDefinition = {
// "type": "ugj_control_for",
// "message0": "%{BKY_UGJ_CONTROL_FOR_TITLE}",
// "args0": [
// {
// "type": "field_variable",
// "name": "index",
// "variable": "%{BKY_UGJ_CONTROL_FOR_INDEX}"
// },
// {
// "type": "input_dummy"
// },
// {
// "type": "input_value",
// "name": "from",
// "check": "Number"
// },
// {
// "type": "input_value",
// "name": "to",
// "check": "Number"
// },
// {
// "type": "input_value",
// "name": "by",
// "check": "Number"
// },
// {
// "type": "field_dropdown",
// "name": "crease",
// "options": [
// [
// "%{BKY_UGJ_CONTROL_FOR_INCREASE}",
// "+"
// ],
// [
// "%{BKY_UGJ_CONTROL_FOR_DECREASE}",
// "-"
// ]
// ]
// },
// {
// "type": "input_dummy"
// },
// {
// "type": "input_statement",
// "name": "do"
// }
// ],
// "inputsInline": true,
// "previousStatement": null,
// "nextStatement": null,
// "tooltip": "%{BKY_UGJ_CONTROL_FOR_TOOLTIP}",
// "helpUrl": "",
// "style": "loop_blocks"
// };
// Blockly.Blocks['ugj_control_for'] = {
// init: function () {
// this.jsonInit(ugjConsrolForDefinition);
// }
// };
Blockly.Blocks['ugj_control_for'] = {
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) {
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_to = Blockly.JavaScript.valueToCode(block, 'to', 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 = '<'; }
else { daishou = '>'; }
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,
`}`,
''
@ -96,66 +123,99 @@ Blockly.Python['ugj_control_for'] = function (block) {
return code;
};
var ugjForEachDefinition = {
"type": "ugj_controls_foreach",
"message0": "%{BKY_UGJ_FOREACH_TITLE}",
"args0": [
{
"type": "input_value",
"name": "list",
"check": "Array"
},
{
"type": "field_variable",
"name": "item",
"variable": "%{BKY_UGJ_FOREACH_ITEM}"
},
{
"type": "input_dummy"
},
{
"type": "input_statement",
"name": "do"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"style": "loop_blocks",
"tooltip": "%{BKY_UGJ_FOREACH_TOOLTIP}",
"helpUrl": ""
}
Blockly.Blocks['ugj_controls_forEach'] = {
// var ugjForEachDefinition = {
// "type": "ugj_controls_foreach",
// "message0": "%{BKY_UGJ_FOREACH_TITLE}",
// "args0": [
// {
// "type": "input_value",
// "name": "list",
// "check": "Array"
// },
// {
// "type": "field_variable",
// "name": "item",
// "variable": "%{BKY_UGJ_FOREACH_ITEM}"
// },
// {
// "type": "input_dummy"
// },
// {
// "type": "input_statement",
// "name": "do"
// }
// ],
// "inputsInline": true,
// "previousStatement": null,
// "nextStatement": null,
// "style": "loop_blocks",
// "tooltip": "%{BKY_UGJ_FOREACH_TOOLTIP}",
// "helpUrl": ""
// }
// Blockly.Blocks['ugj_controls_forEach'] = {
// init: function () {
// this.jsonInit(ugjForEachDefinition);
// }
// };
Blockly.Blocks['ugj_controls_foreach'] = {
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 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 code = [
`for (let _index in ${value_list}) {`,
`${variable_item} = ${value_list}[_index];`,
`${value_item} = ${value_list}[_index];`,
statements_do,
`}`,
''
].join('\n');
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;
};
// Blockly.JavaScript['ugj_controls_forEach'] = function (block) {
// 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 statements_do = Blockly.JavaScript.statementToCode(block, 'do');
// var code = [
// `for (let _index in ${value_list}) {`,
// `${variable_item} = ${value_list}[_index];`,
// statements_do,
// `}`,
// ''
// ].join('\n');
// 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
Blockly.FieldColour.COLOURS = [
'#ffffff', '#808000', '#ffff00', '#ff00ff', '#ff4500',
@ -1071,84 +1131,133 @@ Blockly.Python['ugj_i2c_write_device'] = function (block) {
/********* */
/** BME280 */
/********* */
var ugjBme280Definition = {
"type": "ugj_bme280",
"message0": "%{BKY_UGJ_BME280_TITLE}",
"args0": [
{
"type": "input_value",
"name": "address",
"check": "Number"
},
{
"type": "field_variable",
"name": "temp",
"variable": "%{BKY_UGJ_BME280_READ_TEMP}"
},
{
"type": "field_variable",
"name": "hum",
"variable": "%{BKY_UGJ_BME280_READ_HUM}"
},
{
"type": "field_variable",
"name": "pres",
"variable": "%{BKY_UGJ_BME280_READ_PRES}"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"tooltip": "%{BKY_UGJ_BME280_TOOLTIP}",
"helpUrl": "",
"style": "sensor_blocks"
};
// var ugjBme280Definition = {
// "type": "ugj_bme280",
// "message0": "%{BKY_UGJ_BME280_TITLE}",
// "args0": [
// {
// "type": "input_value",
// "name": "address",
// "check": "Number"
// },
// {
// "type": "field_variable",
// "name": "temp",
// "variable": "%{BKY_UGJ_BME280_READ_TEMP}"
// },
// {
// "type": "field_variable",
// "name": "hum",
// "variable": "%{BKY_UGJ_BME280_READ_HUM}"
// },
// {
// "type": "field_variable",
// "name": "pres",
// "variable": "%{BKY_UGJ_BME280_READ_PRES}"
// }
// ],
// "inputsInline": true,
// "previousStatement": null,
// "nextStatement": null,
// "tooltip": "%{BKY_UGJ_BME280_TOOLTIP}",
// "helpUrl": "",
// "style": "sensor_blocks"
// };
// Blockly.Blocks['ugj_bme280'] = {
// init: function () {
// this.jsonInit(ugjBme280Definition);
// }
// };
Blockly.Blocks['ugj_bme280'] = {
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) {
var value_address = Blockly.JavaScript.valueToCode(block, 'address', Blockly.JavaScript.ORDER_ATOMIC);
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);
var dropdown_addr = block.getFieldValue('addr');
Blockly.JavaScript.provideFunction_(
'require_bme280', [`const _bme280 = require('@ocogeclub/bme280');`]
);
var code = [
`const options = {`,
` i2cBusNo: ${elutil.i2c_bus},`,
` i2cAddress: ${value_address}`,
`};`,
`await _bme280.init(options);`,
`let _thp = await _bme280.readSensorData();`,
`${variable_temp} = Math.round(_thp.temperature_C * 10) / 10;`,
`${variable_hum} = Math.round(_thp.humidity * 10) / 10;`,
`${variable_pres} = Math.round(_thp.pressure_hPa);`,
`await _bme280.cancel();`,
``
].join('\n');
var code = `const options = {
i2cBusNo: ${elutil.i2c_bus},
i2cAddress: ${dropdown_addr}
};
await _bme280.init(options);
let _thp = await _bme280.readSensorData();
let _bmedata = [];
_bmedata[0] = Math.round(_thp.temperature_C * 10) / 10;
_bmedata[1] = Math.round(_thp.humidity * 10) / 10;
_bmedata[2] = Math.round(_thp.pressure_hPa);
await _bme280.cancel();
`;
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.JavaScript['ugj_bme280'] = function (block) {
// var value_address = Blockly.JavaScript.valueToCode(block, 'address', Blockly.JavaScript.ORDER_ATOMIC);
// 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_(
// 'require_bme280', [`const _bme280 = require('@ocogeclub/bme280');`]
// );
// var code = [
// `const options = {`,
// ` i2cBusNo: ${elutil.i2c_bus},`,
// ` i2cAddress: ${value_address}`,
// `};`,
// `await _bme280.init(options);`,
// `let _thp = await _bme280.readSensorData();`,
// `${variable_temp} = Math.round(_thp.temperature_C * 10) / 10;`,
// `${variable_hum} = Math.round(_thp.humidity * 10) / 10;`,
// `${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'] = {
init: function () {
this.appendDummyInput()
.appendField("顔の位置(")
.appendField(new Blockly.FieldVariable("左"), "x")
.appendField(new Blockly.FieldVariable("上"), "y")
.appendField(new Blockly.FieldVariable("幅"), "w")
.appendField(new Blockly.FieldVariable("高さ"), "h")
.appendField(")を検出したら");
.appendField("顔を検出したら");
this.appendStatementInput("do")
.setCheck(null);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setStyle('multimedia_blocks')
this.setTooltip("顔を発見したら動作します。");
this.setTooltip("顔を発見したら動作します。位置データは「顔の座標」ブロックで参照します。");
this.setHelpUrl("");
this.setStyle('multimedia_blocks');
}
};
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 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/');`; }
@ -1490,17 +1590,17 @@ Blockly.JavaScript['ugj_face_detect'] = function (block) {
var code_rect;
if (with_landmark) {
code_rect = [
` ${variable_x} = Math.round(_result.detection.box.x);`,
` ${variable_y} = Math.round(_result.detection.box.y);`,
` ${variable_w} = Math.round(_result.detection.box.width);`,
` ${variable_h} = Math.round(_result.detection.box.height);`,
` _coord[0] = Math.round(_result.detection.box.x);`,
` _coord[1] = Math.round(_result.detection.box.y);`,
` _coord[2] = Math.round(_result.detection.box.width);`,
` _coord[3] = Math.round(_result.detection.box.height);`,
].join('\n');
} else {
code_rect = [
` ${variable_x} = Math.round(_result.box.x);`,
` ${variable_y} = Math.round(_result.box.y);`,
` ${variable_w} = Math.round(_result.box.width);`,
` ${variable_h} = Math.round(_result.box.height);`,
` _coord[0] = Math.round(_result.box.x);`,
` _coord[1] = Math.round(_result.box.y);`,
` _coord[2] = Math.round(_result.box.width);`,
` _coord[3] = Math.round(_result.box.height);`,
].join('\n');
}
var code = [
@ -1510,6 +1610,7 @@ Blockly.JavaScript['ugj_face_detect'] = function (block) {
` const _detectInterval = setInterval(async () => {`,
code_detect_face,
" if (_result) {",
` let _coord = [];`,
code_rect,
statements_do,
" }",
@ -1521,6 +1622,23 @@ Blockly.JavaScript['ugj_face_detect'] = function (block) {
].join('\n');
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'] = {
init: function () {
@ -1529,7 +1647,7 @@ Blockly.Blocks['ugj_face_drawrect'] = {
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setStyle('multimedia_blocks')
this.setStyle('multimedia_blocks');
this.setTooltip("ビデオに検出結果を四角や点で表示します。「ビデオを表示」ブロックが必要です。");
this.setHelpUrl("");
}
@ -2123,9 +2241,10 @@ Blockly.JavaScript['ugj_tensorset_parse'] = function (block) {
/****************************** */
Blockly.Blocks['ugj_event_key'] = {
init: function () {
this.appendValueInput("key")
.setCheck("Variable")
.appendField("キーボードの");
this.appendDummyInput()
.appendField("キーボードの")
.appendField(new Blockly.FieldVariable("キー"), "key")
.appendField("を")
.appendField(new Blockly.FieldDropdown([["押したとき", "keydown"], ["離したとき", "keyup"]]), "updown");
this.appendStatementInput("do")
@ -2133,18 +2252,18 @@ Blockly.Blocks['ugj_event_key'] = {
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setStyle('multimedia_blocks');
this.setTooltip("キーボードを押したり離したりした時のアクションです。");
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) {
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 statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [
`document.addEventListener('${dropdown_updown}', async (_e) => {`,
` ${variable_key} = _e.key;`,
` ${value_key} = _e.key;`,
statements_do,
`}, false);`,
''
@ -2260,9 +2379,10 @@ Blockly.JavaScript['ugj_socket_write'] = function (block) {
/************** */
Blockly.Blocks['ugj_network_httpserver'] = {
init: function () {
this.appendValueInput("url")
.setCheck("Variable")
.appendField("Webサーバを起動してアクセスを待ち、");
this.appendDummyInput()
.appendField("Webサーバを起動してアクセスを待ち、")
.appendField(new Blockly.FieldVariable("url"), "URL")
.appendField("へアクセスがあったら");
this.appendStatementInput("do")
.setCheck(null);
@ -2273,13 +2393,14 @@ Blockly.Blocks['ugj_network_httpserver'] = {
.appendField("を表示してアクセス待ちに戻る");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setStyle('network_blocks')
this.setTooltip("HTTPサーバを起動します。ポートは3000固定です。");
this.setHelpUrl("");
this.setStyle('network_blocks')
}
};
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 value_response = Blockly.JavaScript.valueToCode(block, 'response', Blockly.JavaScript.ORDER_ATOMIC);
Blockly.JavaScript.provideFunction_(
@ -2289,7 +2410,7 @@ Blockly.JavaScript['ugj_network_httpserver'] = function (block) {
`let _req, _res;`,
`_http.createServer(async (_req, _res) => {`,
`_res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });`,
`${variable_url} = _req.url;`,
`${value_url} = _req.url;`,
statements_do,
// `_res.write('<!DOCTYPE html><html lang="ja"><head><meta charset="UTF-8"></head><body>');`,
`_res.end(${value_response});`,
@ -2378,7 +2499,7 @@ Blockly.JavaScript['ugj_network_sendmail'] = function (block) {
`port: 25`,
`});`,
`let _message = {`,
`from: 'no-reply@oc.x0.to',`,
`from: 'no-reply@ocoge.club',`,
`to: ${value_to},`,
`subject: ${value_subject},`,
`text: ${value_text}`,
@ -2414,7 +2535,7 @@ Blockly.Blocks['ugj_library_skyway'] = {
}
};
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];
};
@ -2479,10 +2600,10 @@ Blockly.JavaScript['ugj_getusermedia'] = function (block) {
// SkyWay New Peer
Blockly.Blocks['ugj_skyway_newpeer'] = {
init: function () {
this.appendValueInput("my_id")
.setCheck("Variable")
.appendField("SkyWayサーバーに ID:");
this.appendDummyInput()
.appendField("SkyWayサーバーに ID:")
.appendField(new Blockly.FieldVariable("自分のID"), "my_id")
// .appendField(new Blockly.FieldTextInput("MyID"), "NAME")
.appendField("で接続する");
this.appendStatementInput("do")
.setCheck(null)
@ -2490,23 +2611,24 @@ Blockly.Blocks['ugj_skyway_newpeer'] = {
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setStyle('network_blocks')
this.setTooltip("サーバーにIDを登録して、相手先呼び出しの準備をします。");
this.setHelpUrl("");
this.setStyle('network_blocks')
}
};
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 statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [
`const _peer = new Peer(${variable_my_id}, {`,
`const _peer = new Peer(${value_my_id}, {`,
" key: window.__SKYWAY_KEY__,",
" debug: 3",
"});",
"_peer.on('open', () => {",
// ' ugj_blackboardWrite(`SkyWay: "${peer.id}" OK`)',
`${variable_my_id} = _peer.id;`,
`${value_my_id} = _peer.id;`,
"_inputForm.addEventListener('submit', _onMakeCall);",
statements_do,
"});",
@ -2514,9 +2636,9 @@ Blockly.JavaScript['ugj_skyway_newpeer'] = function (block) {
"const _onMakeCall = _e => {",
" _e.preventDefault();",
" const _call = _peer.call(_inputBox.value, _localStream);",
" setupCallEventHandlers(_call);",
" const _connect = peer.connect(_inputBox.value);",
" setupConnectEventHandlers(_connect);",
" _setupCallEventHandlers(_call);",
" const _connect = _peer.connect(_inputBox.value);",
" _setupConnectEventHandlers(_connect);",
" _inputBox.value = '';",
"}",
''
@ -2552,27 +2674,29 @@ Blockly.JavaScript['ugj_skyway_called'] = function (block) {
// EventHandlers for Call and Connect
Blockly.Blocks['ugj_skyway_events'] = {
init: function () {
this.appendValueInput("remote_id")
.setCheck("Variable");
this.appendDummyInput()
.appendField(new Blockly.FieldVariable("相手のID"), "remote_id")
.appendField("との接続後にすること");
this.appendStatementInput("do")
.setCheck(null);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setStyle('network_blocks')
this.setTooltip("チャットの相手との接続後の動作を定義します。");
this.setHelpUrl("");
this.setStyle('network_blocks')
}
};
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 code = [
"const _setupCallEventHandlers = _call => _call.on('stream', _stream => _remoteVideo.srcObject = _stream);",
"const _setupConnectEventHandlers = _connect => {",
" _inputForm.removeEventListener('submit', _onMakeCall);",
` ${variable_remote_id} = _connect.remoteId;`,
` ${value_remote_id} = _connect.remoteId;`,
statements_do,
"}",
''
@ -2608,26 +2732,28 @@ Blockly.JavaScript['ugj_skyway_eventopen'] = function (block) {
// Peer Data Receive
Blockly.Blocks['ugj_skyway_eventdata'] = {
init: function () {
this.appendValueInput("data")
.setCheck("Variable")
.appendField("相手の");
this.appendDummyInput()
.appendField("相手の")
.appendField(new Blockly.FieldVariable("発言"), "data")
.appendField("を受けとったら");
this.appendStatementInput("do")
.setCheck(null);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setStyle('network_blocks')
this.setTooltip("チャット相手の発言を受信したときの動作です。");
this.setHelpUrl("");
this.setStyle('network_blocks')
}
};
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 code = [
" _connect.on('data', _data => {",
` ${variable_data} = _data;`,
` ${value_data} = _data;`,
statements_do,
" });",
''
@ -2637,27 +2763,29 @@ Blockly.JavaScript['ugj_skyway_eventdata'] = function (block) {
// Send Message
Blockly.Blocks['ugj_skyway_eventsend'] = {
init: function () {
this.appendValueInput("data")
.setCheck("Variable")
.appendField("入力フィールドの");
this.appendDummyInput()
.appendField("入力フィールドの")
.appendField(new Blockly.FieldVariable("内容"), "data")
.appendField("を送信するとき");
this.appendStatementInput("do")
.setCheck(null);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setStyle('network_blocks')
this.setTooltip("入力フィールドで送信が発生したときの動作を決めます。");
this.setHelpUrl("");
this.setStyle('network_blocks')
}
};
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 code = [
" const _onSendMsg = () => {",
` ${variable_data} = _inputBox.value;`,
` _connect.send(${variable_data});`,
` ${value_data} = _inputBox.value;`,
` _connect.send(${value_data});`,
" _inputBox.value = '';",
statements_do,
" }",
@ -2780,21 +2908,23 @@ Blockly.Blocks['ugj_event_answer'] = {
init: function () {
this.appendValueInput("question")
.setCheck("String");
this.appendValueInput("answer")
.setCheck("Variable")
.appendField("ときいて");
this.appendDummyInput()
.appendField("ときいて")
.appendField(new Blockly.FieldVariable("答え"), "answer")
.appendField("を待つ");
this.appendStatementInput("do")
.setCheck(null);
this.setPreviousStatement(true, null);
this.setStyle('special_blocks')
this.setTooltip("質問をして答えを待ちます。入力欄でキーボードのエンターキーが入力されるか、チェックマークボタンが押されると実行されます。");
this.setHelpUrl("");
this.setStyle('special_blocks')
}
};
Blockly.JavaScript['ugj_event_answer'] = function (block) {
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 code = [
`ugj_fukidashi(${value_question}, 0);`,
@ -2804,7 +2934,7 @@ Blockly.JavaScript['ugj_event_answer'] = function (block) {
"_inputBox.focus();",
"const _inputFunc = async () => { ",
" if (_inputBox.value.length > 0) {",
` ${variable_answer} = _inputBox.value;`,
` ${value_answer} = _inputBox.value;`,
' _inputForm.style.display = "none"',
" _inputBox.value = '';",
" 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")
.setCheck("shcmd")
.appendField("外部プログラム");
this.appendValueInput("data")
.setCheck("Variable")
.appendField("を同期的に実行して");
this.appendDummyInput()
.appendField("を同期的に実行して")
.appendField(new Blockly.FieldVariable("実行結果"), "data")
.appendField("を受け取る");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setStyle('special_blocks')
this.setTooltip("外部プログラムを実行して子プロセスを生成し、子プロセスが終了するまで待ちます。");
this.setHelpUrl("");
this.setStyle('special_blocks')
}
};
Blockly.JavaScript['ugj_spawnsync'] = function (block) {
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 code = `${variable_data} = require('child_process').spawnSync(${value_childprocess}).stdout.toString();\n`;
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 code = `${value_data} = require('child_process').spawnSync(${value_childprocess}).stdout.toString();\n`;
// var code = `${variable_data} = require('child_process').execFileSync(${value_childprocess});\n`;
return code;
};
@ -2855,30 +2987,32 @@ Blockly.Blocks['ugj_spawn'] = {
this.appendValueInput("childprocess")
.setCheck("shcmd")
.appendField("外部プログラム");
this.appendValueInput("data")
.setCheck(null)
.appendField("を非同期に実行して");
this.appendDummyInput()
.appendField("を非同期に実行して")
.appendField(new Blockly.FieldVariable("データストリーム"), "data")
.appendField("を受け取る");
this.appendStatementInput("do")
.setCheck(null);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setStyle('special_blocks')
this.setTooltip("外部プログラムを実行して子プロセスを生成します。データを受け取る毎にステートメントが実行されます。");
this.setHelpUrl("");
this.setStyle('special_blocks')
}
};
Blockly.JavaScript['ugj_spawn'] = function (block) {
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 code = [
`let _child = require('child_process').spawn(${value_childprocess});`,
`elutil.addChild(_child);`,
"_child.stderr.on('data', _data => { console.error(_data.toString()) })",
"_child.stdout.on('data', async _data => {",
`${variable_data} = _data.toString();`,
`${value_data} = _data.toString();`,
statements_do,
"})",
"_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")
.appendField("ツールチップ");
this.appendStatementInput("do")
.setCheck(null)
.appendField("クリックしたら (")
.appendField(new Blockly.FieldVariable("ツールチップ"), "title")
.appendField(")");
.setCheck(null);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setStyle('special_blocks')
this.setTooltip("ディスプレイカラムにボタンを作成し、クリックのイベントリスナを定義します。テキストデータをひとつ、\"title\"属性値として設定・取り出しが可能です。保存したデータはマウスオーバーで確認できます。");
this.setHelpUrl("");
this.setStyle('special_blocks')
}
};
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_bgcolor = Blockly.JavaScript.valueToCode(block, 'bgcolor', 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 code = [
`( async () => {`,
@ -3476,7 +3606,6 @@ Blockly.JavaScript['ugj_control_button'] = function (block) {
`el.className = 'toolbarButton ocgButton';`,
`document.getElementById('dispColumn').appendChild(el);`,
`el.addEventListener('click', async ev => {`,
`${variable_title} = ev.currentTarget.title;`,
statements_do,
`});`,
`})();`,
@ -3526,3 +3655,23 @@ else console.log('invalid certification');
`;
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;
};