@@ -140,6 +140,42 @@ Blockly.JavaScript[GET_PROPERTY_OF_FIGHTER] = (block: Blockly.Block) => [
140140 Blockly . JavaScript . ORDER_CONDITIONAL ,
141141] ;
142142
143+ // 定数
144+
145+ export const CONSTANT = "constant" ;
146+ const constantNames = {
147+ armLength : "0" ,
148+ stageWidth : "1" ,
149+ stageHeight : "2" ,
150+ maxHp : "3" ,
151+ maxStamina : "4" ,
152+ weaponRange : "5" ,
153+ } ;
154+ const constants = [ 40 , 800 , 600 , 100 , 100 , 400 ] ;
155+ const CONSTANT_NAME = "constantName" ;
156+ Blockly . Blocks [ CONSTANT ] = {
157+ init ( this : Blockly . Block ) {
158+ this . appendDummyInput ( ) . appendField (
159+ new Blockly . FieldDropdown ( [
160+ [ "腕の長さ(40)" , constantNames . armLength ] ,
161+ [ "ステージの横の長さ(800)" , constantNames . stageWidth ] ,
162+ [ "ステージの縦の長さ(600)" , constantNames . stageHeight ] ,
163+ [ "最大HP(100)" , constantNames . maxHp ] ,
164+ [ "最大元気(100)" , constantNames . maxStamina ] ,
165+ [ "武器の射程(400)" , constantNames . weaponRange ] ,
166+ ] ) ,
167+ CONSTANT_NAME
168+ ) ;
169+ this . setOutput ( true , Number ) ;
170+ this . setColour ( 20 ) ;
171+ this . setTooltip ( "ルールで決められている定数です。" ) ;
172+ } ,
173+ } ;
174+ Blockly . JavaScript [ CONSTANT ] = ( block : Blockly . Block ) => [
175+ `${ constants [ block . getFieldValue ( CONSTANT_NAME ) ] } ` ,
176+ Blockly . JavaScript . ORDER_ATOMIC ,
177+ ] ;
178+
143179// 意思決定
144180
145181const TARGET = "target" ;
@@ -333,11 +369,58 @@ Blockly.JavaScript[CLOSEST_WEAPON] = () => [
333369] ;
334370
335371// 日本語訳がおかしい物の修正など
336- // while
372+ // if
337373
338374const STATEMENT = "statement" ;
339375const CONDITION = "condition" ;
340376
377+ export const CUSTOM_IF = "custom_if" ;
378+ Blockly . Blocks [ CUSTOM_IF ] = {
379+ init ( this : Blockly . Block ) {
380+ this . appendValueInput ( CONDITION ) . setCheck ( Boolean ) . appendField ( "もし" ) ;
381+ this . appendDummyInput ( ) . appendField ( "なら" ) ;
382+ this . appendStatementInput ( STATEMENT ) ;
383+ this . setPreviousStatement ( true ) ;
384+ this . setNextStatement ( true ) ;
385+ this . setColour ( 210 ) ;
386+ this . setTooltip ( "条件が満たされる場合、内部の文を実行します。" ) ;
387+ } ,
388+ } ;
389+ Blockly . JavaScript [ CUSTOM_IF ] = ( block : Blockly . Block ) =>
390+ `if(${ Blockly . JavaScript . valueToCode (
391+ block ,
392+ CONDITION ,
393+ Blockly . JavaScript . ORDER_NONE
394+ ) } ){${ Blockly . JavaScript . statementToCode ( block , STATEMENT ) } };`;
395+
396+ const STATEMENT2 = "statement2" ;
397+ export const CUSTOM_IFELSE = "custom_ifelse" ;
398+ Blockly . Blocks [ CUSTOM_IFELSE ] = {
399+ init ( this : Blockly . Block ) {
400+ this . appendValueInput ( CONDITION ) . setCheck ( Boolean ) . appendField ( "もし" ) ;
401+ this . appendDummyInput ( ) . appendField ( "なら" ) ;
402+ this . appendStatementInput ( STATEMENT ) ;
403+ this . appendDummyInput ( ) . appendField ( "そうでなければ" ) ;
404+ this . appendStatementInput ( STATEMENT2 ) ;
405+ this . setPreviousStatement ( true ) ;
406+ this . setNextStatement ( true ) ;
407+ this . setColour ( 210 ) ;
408+ this . setTooltip (
409+ "条件が満たされる場合は1番目の文を、満たされない場合は2番目の文を実行します。"
410+ ) ;
411+ } ,
412+ } ;
413+ Blockly . JavaScript [ CUSTOM_IFELSE ] = ( block : Blockly . Block ) =>
414+ `if(${ Blockly . JavaScript . valueToCode (
415+ block ,
416+ CONDITION ,
417+ Blockly . JavaScript . ORDER_NONE
418+ ) } ){${ Blockly . JavaScript . statementToCode ( block , STATEMENT ) } }else{
419+ ${ Blockly . JavaScript . statementToCode ( block , STATEMENT2 ) }
420+ };` ;
421+
422+ // while
423+
341424export const CUSTOM_WHILE = "custom_while" ;
342425Blockly . Blocks [ CUSTOM_WHILE ] = {
343426 init ( this : Blockly . Block ) {
0 commit comments